#!/usr/bin/env bash set -euo pipefail REMOTE_HOST="${REMOTE_HOST:-root@192.168.10.150}" REMOTE_PATH="${REMOTE_PATH:-/mnt/user/appdata/geointel}" REMOTE_BRANCH="${REMOTE_BRANCH:-main}" REMOTE_REPO="${REMOTE_REPO:-gitea-widefrog:NuklearRabbit/geointel.git}" SSH_KEY="${SSH_KEY:-$HOME/.ssh/widefrog_unraid_deploy}" FRONTEND_URL="${FRONTEND_URL:-http://192.168.10.150:1202}" BOOTSTRAP="${DEPLOY_BOOTSTRAP:-0}" DEPLOY_GEOINTEL_INSTALL_AI="${GEOINTEL_INSTALL_AI:-}" ssh_opts=(-o BatchMode=yes -o StrictHostKeyChecking=accept-new) if [[ -f "$SSH_KEY" ]]; then ssh_opts+=(-i "$SSH_KEY") fi ssh "${ssh_opts[@]}" "$REMOTE_HOST" \ "REMOTE_PATH='$REMOTE_PATH' REMOTE_BRANCH='$REMOTE_BRANCH' REMOTE_REPO='$REMOTE_REPO' FRONTEND_URL='$FRONTEND_URL' DEPLOY_BOOTSTRAP='$BOOTSTRAP' DEPLOY_GEOINTEL_INSTALL_AI='$DEPLOY_GEOINTEL_INSTALL_AI' bash -s" <<'REMOTE_SCRIPT' set -euo pipefail cd "$REMOTE_PATH" if [[ ! -d .git ]]; then if [[ "$DEPLOY_BOOTSTRAP" != "1" ]]; then echo "No git checkout found in $REMOTE_PATH." echo "Re-run with DEPLOY_BOOTSTRAP=1 for the first deployment bootstrap." exit 2 fi git init git remote add origin "$REMOTE_REPO" fi git fetch origin "$REMOTE_BRANCH" git checkout -B "$REMOTE_BRANCH" "origin/$REMOTE_BRANCH" chmod +x scripts/*.sh backend/docker_start.sh deploy/unraid/*.sh || true if [ -f .env ]; then set -a # shellcheck disable=SC1091 . ./.env set +a fi if [ -n "${DEPLOY_GEOINTEL_INSTALL_AI:-}" ]; then GEOINTEL_INSTALL_AI="$DEPLOY_GEOINTEL_INSTALL_AI" fi GEOINTEL_INSTALL_AI="${GEOINTEL_INSTALL_AI:-false}" docker compose -f docker-compose.unraid.yml config >/dev/null docker build --build-arg GEOINTEL_INSTALL_AI="$GEOINTEL_INSTALL_AI" -f deploy/unraid/Dockerfile.all-in-one -t geointel-all-in-one:latest . bash deploy/unraid/run-dockerman-container.sh wait_for_geointel_health() { local status='' for attempt in $(seq 1 90); do status="$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' geointel 2>/dev/null || true)" if [[ "$status" == 'healthy' ]]; then echo "GeoIntel container is healthy after attempt $attempt." return 0 fi if [[ "$status" == 'unhealthy' || "$status" == 'exited' || "$status" == 'dead' ]]; then echo "GeoIntel container entered terminal state: $status" >&2 docker logs --tail 120 geointel >&2 || true return 1 fi sleep 2 done echo "GeoIntel container did not become healthy (last state: ${status:-missing})." >&2 docker logs --tail 120 geointel >&2 || true return 1 } # Container startup owns the migration. Waiting here prevents the validation # smoke from racing a concurrent `alembic upgrade head` against the same DB. wait_for_geointel_health if [[ -x scripts/live_migration_smoke.sh ]]; then LIVE_SMOKE_CONTAINER=geointel bash scripts/live_migration_smoke.sh fi if [[ -x scripts/verify_browser_runtime.sh ]]; then bash scripts/verify_browser_runtime.sh "$FRONTEND_URL" fi REMOTE_SCRIPT