#!/usr/bin/env bash # load-v3.sh — one-time migration: import the v2 base into v3, push it, and deploy # v3 IN PLACE of v2 (same host port, same container name, same live-state volume). # # Run on hal-blackpearl: bash load-v3.sh # If the push step needs credentials: GITEA_TOKEN= bash load-v3.sh # # Rollback at any time: cd ~/newbury-exhibit && docker compose up -d --build set -e GITEA_HOST="gitea.hideawaygaming.com.au" V2_URL="https://${GITEA_HOST}/jessikitty/newbury-exhibit-v2.git" V3_URL="https://${GITEA_HOST}/jessikitty/newbury-exhibit-v3.git" DIR="$HOME/newbury-exhibit-v3" OLD="$HOME/newbury-exhibit" # 1) clone or update v3 if [ ! -d "$DIR/.git" ]; then git clone "$V3_URL" "$DIR"; fi cd "$DIR" git fetch origin && git reset --hard origin/main # 2) import unchanged v2 base files (only ones v3 doesn't already define), # then PUSH — required, so future `deploy.sh` hard-resets keep the base. if [ ! -f server/server.js ]; then echo "== importing v2 base files ==" TMP="$(mktemp -d)" git clone --depth 1 "$V2_URL" "$TMP/v2" rm -rf "$TMP/v2/.git" rm -f "$TMP"/v2/*.bat # v2-era upload helpers target the old repo if command -v rsync >/dev/null 2>&1; then rsync -a --ignore-existing "$TMP/v2/" "$DIR/" else cp -rn "$TMP/v2/." "$DIR/" fi rm -rf "$TMP" git add -A git -c user.name="load-v3" -c user.email="load-v3@local" commit -m "Import v2 base (unchanged files)" if [ -n "$GITEA_TOKEN" ]; then git push "https://jessikitty:${GITEA_TOKEN}@${GITEA_HOST}/jessikitty/newbury-exhibit-v3.git" main:main else if ! git push origin main; then echo "" echo "!! Push failed (no credentials on this machine)." echo "!! Re-run as: GITEA_TOKEN=your-api-token bash load-v3.sh" echo "!! Not deploying yet — deploy.sh hard-resets to origin/main, so the" echo "!! base import must be on the remote first." exit 1 fi fi fi # 3) carry deployment config + locally-dropped OBJ models over from v2 if [ -f "$OLD/.env" ]; then cp -n "$OLD/.env" .env 2>/dev/null || true elif [ ! -f .env ]; then cp .env.example .env; fi if [ -d "$OLD/public/models" ]; then mkdir -p public/models cp -an "$OLD/public/models/." public/models/ 2>/dev/null || true fi # 4) swap containers in place. Same compose project name => same container, # ports, and exhibit-live volume; live state carries over automatically. if [ -d "$OLD" ]; then (cd "$OLD" && docker compose down) || true; fi docker compose up -d --build docker image prune -f >/dev/null echo "" echo "v3 is live at the same address (host port unchanged)." echo "Future deploys: cd $DIR && bash deploy.sh" echo "Rollback: cd $OLD && docker compose up -d --build"