#!/usr/bin/env bash set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" LAB_ROOT="${AZEROTHAI_PLAYABLE_ROOT:-$HOME/azerothai-pc-lab}" cd "$REPO_ROOT" echo "==> Rebuilding AzerothAI so server HTML and client bundles match" pnpm build echo "==> Restarting AzerothAI runtime" if [[ -f "$LAB_ROOT/azerothai.pid" ]]; then PID="$(cat "$LAB_ROOT/azerothai.pid" 2>/dev/null || true)" if [[ -n "$PID" ]]; then kill "$PID" 2>/dev/null || true; fi sleep 1 fi nohup pnpm start:lan >"$LAB_ROOT/azerothai.log" 2>&1 & echo $! > "$LAB_ROOT/azerothai.pid" echo "==> Waiting for dashboard health" for _ in {1..90}; do if curl -fsS http://127.0.0.1:8787/api/health >/dev/null 2>&1; then break fi sleep 1 done curl -fsS http://127.0.0.1:8787/api/health >/dev/null echo "==> Rebuilding remote Tailscale dashboard proxy" bash "$REPO_ROOT/deploy/pc-lab/tailscale-dashboard.sh" DNS_NAME="$(tailscale status --json 2>/dev/null | python3 -c 'import json,sys; d=json.load(sys.stdin); print((d.get("Self",{}).get("DNSName") or "").rstrip("."))' 2>/dev/null || true)" STAMP="$(date +%s)" echo echo "Remote dashboard repair complete." if [[ -n "$DNS_NAME" ]]; then echo "Open this fresh URL:" echo " https://$DNS_NAME/?v=$STAMP" fi