2026-03-02 11:37:34 -08:00
#!/usr/bin/env bash
# Apply remaining operator fixes from DETAILED_GAPS_AND_ISSUES_LIST.md §12:
# 1) Nginx fix + deploy explorer config on VMID 5000 (via Proxmox host)
# 2) Token-aggregation: print steps (DB create, migrations, restart)
#
# Usage: ./scripts/apply-remaining-operator-fixes.sh [--nginx-only] [--dry-run]
# Requires: SSH to Proxmox host (PROXMOX_HOST_R630_02 or 192.168.11.12), or run nginx script inside VMID 5000 manually.
set -euo pipefail
SCRIPT_DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
PROJECT_ROOT = " $( cd " $SCRIPT_DIR /.. " && pwd ) "
cd " $PROJECT_ROOT "
source " ${ PROJECT_ROOT } /config/ip-addresses.conf " 2>/dev/null || true
PROXMOX_HOST = " ${ PROXMOX_HOST_R630_02 :- 192 .168.11.12 } "
DRY_RUN = false
NGINX_ONLY = false
for a in " $@ " ; do
[ [ " $a " = = "--dry-run" ] ] && DRY_RUN = true
[ [ " $a " = = "--nginx-only" ] ] && NGINX_ONLY = true
done
echo "=== Apply remaining operator fixes (§12) ==="
echo " dry-run= $DRY_RUN nginx-only= $NGINX_ONLY "
echo ""
# 1) Nginx fix on VMID 5000
NGINX_SCRIPT = " ${ PROJECT_ROOT } /explorer-monorepo/scripts/fix-nginx-conflicts-vmid5000.sh "
DEPLOY_CONFIG = " ${ PROJECT_ROOT } /explorer-monorepo/scripts/deploy-explorer-config-to-vmid5000.sh "
if [ [ -f " $NGINX_SCRIPT " ] ] ; then
echo "--- 1. Nginx fix (VMID 5000) ---"
if [ [ " $DRY_RUN " = = true ] ] ; then
echo " [DRY-RUN] Would run fix-nginx-conflicts-vmid5000.sh inside VMID 5000 via: ssh root@ ${ PROXMOX_HOST } 'pct exec 5000 -- bash -s' < $NGINX_SCRIPT "
else
if ssh -o ConnectTimeout = 10 -o BatchMode = yes " root@ ${ PROXMOX_HOST } " "pct exec 5000 -- true" 2>/dev/null; then
echo " Pushing and running nginx fix inside VMID 5000..."
ssh " root@ ${ PROXMOX_HOST } " "pct exec 5000 -- bash -s" < " $NGINX_SCRIPT " && echo " ✅ Nginx fix done" || { echo " ⚠ Nginx fix failed (check output above)" ; exit 1; }
if [ [ -f " $DEPLOY_CONFIG " ] ] ; then
echo " Deploying explorer config..."
CONFIG_SRC = " ${ PROJECT_ROOT } /explorer-monorepo/backend/api/rest/config/metamask "
if [ [ -f " $CONFIG_SRC /DUAL_CHAIN_TOKEN_LIST.tokenlist.json " && -f " $CONFIG_SRC /DUAL_CHAIN_NETWORKS.json " ] ] ; then
TMP_DEPLOY = $( mktemp -d) && trap " rm -rf $TMP_DEPLOY " EXIT
cp " $CONFIG_SRC /DUAL_CHAIN_TOKEN_LIST.tokenlist.json " " $CONFIG_SRC /DUAL_CHAIN_NETWORKS.json " " $TMP_DEPLOY / "
if scp -o ConnectTimeout = 10 " $TMP_DEPLOY /DUAL_CHAIN_TOKEN_LIST.tokenlist.json " " $TMP_DEPLOY /DUAL_CHAIN_NETWORKS.json " " root@ ${ PROXMOX_HOST } :/tmp/ " 2>/dev/null; then
ssh " root@ ${ PROXMOX_HOST } " "pct exec 5000 -- mkdir -p /var/www/html/config && pct push 5000 /tmp/DUAL_CHAIN_TOKEN_LIST.tokenlist.json /var/www/html/config/DUAL_CHAIN_TOKEN_LIST.tokenlist.json && pct push 5000 /tmp/DUAL_CHAIN_NETWORKS.json /var/www/html/config/DUAL_CHAIN_NETWORKS.json" 2>/dev/null && echo " ✅ Explorer config deployed (via Proxmox host)" || echo " ⚠ pct push failed (run deploy script from Proxmox host)"
else
EXPLORER_IP = " ${ EXPLORER_IP :- 192 .168.11.140 } " EXEC_MODE = ssh bash " $DEPLOY_CONFIG " 2>/dev/null && echo " ✅ Explorer config deployed" || echo " ⚠ Deploy failed (run manually: EXEC_MODE=ssh EXPLORER_IP=192.168.11.140 bash $DEPLOY_CONFIG ) "
fi
else
echo " ⚠ Config files not found in $CONFIG_SRC "
fi
fi
else
echo " ⚠ SSH to root@ ${ PROXMOX_HOST } failed or pct exec 5000 not available. Run inside VMID 5000 manually: "
echo " bash $NGINX_SCRIPT "
echo " Then deploy config: bash $DEPLOY_CONFIG "
fi
fi
echo ""
else
echo " ⚠ Nginx script not found: $NGINX_SCRIPT "
echo ""
fi
2026-03-02 13:22:58 -08:00
# 2) Token-aggregation
2026-03-02 11:37:34 -08:00
if [ [ " $NGINX_ONLY " != true ] ] ; then
echo "--- 2. Token-aggregation (see §2 in DETAILED_GAPS) ---"
2026-03-02 13:22:58 -08:00
if [ [ -x " $SCRIPT_DIR /apply-token-aggregation-fix.sh " ] ] ; then
echo " Run: ./scripts/apply-token-aggregation-fix.sh # create DB, migrations, restart via Proxmox"
echo " (VMID 5000 may need postgres user; if not, run createdb/migrations where PostgreSQL runs.)"
else
echo " If /health returns 'database token_aggregation does not exist':"
echo " 1) On VMID 5000 (or PostgreSQL host): createdb -U postgres token_aggregation"
echo " 2) Run migrations: cd smom-dbis-138/services/token-aggregation && DATABASE_URL=postgresql://... bash scripts/run-migrations.sh"
echo " 3) Restart: systemctl restart token-aggregation"
echo " 4) Verify: curl -s http://192.168.11.140:3001/health | jq ."
fi
2026-03-02 11:37:34 -08:00
echo ""
fi
echo "=== Done ==="