← back to Free Roster Memory

push-to-both.sh

56 lines

#!/bin/bash
# push-to-both.sh — free-roster-memory is the SOURCE OF TRUTH for the Emoji Memory
# Match game. This copies index.html into both live downstream sites, commits in
# each, rsyncs to Kamatera, and verifies each URL is serving the new build.
#
#   games.aa  -> ~/Projects/games-agentabrams/games/emoji-memory/index.html  (arcade game)
#   emoji.aa  -> ~/Projects/emoji-agentabrams/index.html                     (standalone site)
#
# Usage: bash ~/Projects/free-roster-memory/push-to-both.sh
# Cost: $0 (local copy + git + rsync). Steve-gated: it deploys to two prod sites.
set -euo pipefail

SRC="$HOME/Projects/free-roster-memory/index.html"
KAM=root@45.61.58.125
[ -f "$SRC" ] || { echo "!! source missing: $SRC"; exit 1; }

# Fingerprint the source so verification checks the RIGHT thing, not just "a title".
FP=$(shasum -a 256 "$SRC" | cut -c1-12)
TITLE=$(grep -oiE '<title>[^<]*</title>' "$SRC" | head -1)
echo "source $SRC"
echo "  sha256[:12]=$FP  $TITLE"
echo

push() {
  local name="$1" repo="$2" dest="$3" remote="$4" url="$5"
  echo "=== $name ==="
  cp "$SRC" "$dest"
  ( cd "$repo"
    if git diff --quiet -- "$dest" 2>/dev/null && git diff --cached --quiet 2>/dev/null; then
      echo "  no change vs committed — re-deploying anyway"
    else
      git add -A && git commit -q -m "sync Emoji Memory game from free-roster-memory ($FP)" && echo "  committed"
    fi
    rsync -az --exclude .git --exclude tests --exclude deploy ./ "$KAM:$remote/" && echo "  rsynced -> $remote"
  )
  # verify the live copy matches the source fingerprint
  local live_fp
  live_fp=$(curl -s --max-time 20 "$url" | shasum -a 256 | cut -c1-12 || echo "FETCH-FAIL")
  if [ "$live_fp" = "$FP" ]; then echo "  ✅ LIVE matches source ($url)"; else echo "  ⚠️  LIVE fp=$live_fp != source $FP ($url)"; fi
  echo
}

push "games.aa" \
     "$HOME/Projects/games-agentabrams" \
     "$HOME/Projects/games-agentabrams/games/emoji-memory/index.html" \
     "/var/www/games.agentabrams.com" \
     "https://games.agentabrams.com/games/emoji-memory/index.html"

push "emoji.aa" \
     "$HOME/Projects/emoji-agentabrams" \
     "$HOME/Projects/emoji-agentabrams/index.html" \
     "/var/www/emoji.agentabrams.com" \
     "https://emoji.agentabrams.com/"

echo "done — cost \$0 (local copy + git + rsync)"