#!/usr/bin/env bash # Copy a local publication bundle (from deploy-token-aggregation-for-publication.sh) to the explorer host # and optionally restart systemd. Run from repo root on LAN. # # Prereq: # bash scripts/deploy-token-aggregation-for-publication.sh "$PWD/token-aggregation-build" # # Usage: # EXPLORER_SSH=root@192.168.11.140 REMOTE_DIR=/opt/token-aggregation \ # bash scripts/deployment/push-token-aggregation-bundle-to-explorer.sh /path/to/token-aggregation-build # # Env: # EXPLORER_SSH default root@192.168.11.140 # REMOTE_DIR default /opt/token-aggregation # REMOTE_SERVICE systemd unit to restart (default: token-aggregation); empty to skip restart # SYNC_REMOTE_ENV set to 1 to allow bundle .env to overwrite remote .env (default: preserve remote env) set -euo pipefail BUNDLE_ROOT="${1:?Usage: $0 /path/to/token-aggregation-build}" SERVICE_SRC="$BUNDLE_ROOT/smom-dbis-138/services/token-aggregation" CONFIG_SRC="$BUNDLE_ROOT/config" PMM_CONFIG_SRC="$BUNDLE_ROOT/cross-chain-pmm-lps/config" EXPLORER_SSH="${EXPLORER_SSH:-root@192.168.11.140}" REMOTE_DIR="${REMOTE_DIR:-/opt/token-aggregation}" REMOTE_SERVICE="${REMOTE_SERVICE:-token-aggregation}" SYNC_REMOTE_ENV="${SYNC_REMOTE_ENV:-0}" if [[ ! -d "$SERVICE_SRC" || ! -f "$SERVICE_SRC/dist/index.js" ]]; then echo "Expected built service at $SERVICE_SRC (run deploy-token-aggregation-for-publication.sh first)." >&2 exit 1 fi if [[ ! -d "$CONFIG_SRC" || ! -d "$PMM_CONFIG_SRC" ]]; then echo "Expected bundle config directories at $CONFIG_SRC and $PMM_CONFIG_SRC." >&2 exit 1 fi echo "Rsync $SERVICE_SRC/ → ${EXPLORER_SSH}:${REMOTE_DIR}/" rsync_args=( -avz --delete --exclude '.git' --exclude 'src' --exclude '*.test.ts' ) if [[ "$SYNC_REMOTE_ENV" != "1" ]]; then rsync_args+=(--exclude '.env' --exclude '.env.local') echo "Preserving remote .env files (set SYNC_REMOTE_ENV=1 to overwrite them)." fi RSYNC_RSH="ssh -o BatchMode=yes" rsync "${rsync_args[@]}" \ "$SERVICE_SRC/" "${EXPLORER_SSH}:${REMOTE_DIR}/" echo "Rsync $CONFIG_SRC/ → ${EXPLORER_SSH}:${REMOTE_DIR}/config/" RSYNC_RSH="ssh -o BatchMode=yes" rsync -avz --delete \ "$CONFIG_SRC/" "${EXPLORER_SSH}:${REMOTE_DIR}/config/" echo "Rsync $PMM_CONFIG_SRC/ → ${EXPLORER_SSH}:${REMOTE_DIR}/cross-chain-pmm-lps/config/" ssh -o BatchMode=yes "$EXPLORER_SSH" \ "mkdir -p '${REMOTE_DIR}/cross-chain-pmm-lps/config'" RSYNC_RSH="ssh -o BatchMode=yes" rsync -avz --delete \ "$PMM_CONFIG_SRC/" "${EXPLORER_SSH}:${REMOTE_DIR}/cross-chain-pmm-lps/config/" if [[ -n "$REMOTE_SERVICE" ]]; then echo "Restart ${REMOTE_SERVICE} on ${EXPLORER_SSH}..." ssh -o BatchMode=yes "$EXPLORER_SSH" "systemctl restart '${REMOTE_SERVICE}'" || { echo "systemctl restart failed (unit may differ). Start manually: cd $REMOTE_DIR && node dist/index.js" >&2 exit 1 } fi echo "Done. Verify: BASE_URL=https://explorer.d-bis.org pnpm run verify:token-aggregation-api"