transceiver-db/scripts/run-atgbics-mac.sh
Rene Fichtmueller d9c37af642 fix(security): remove hardcoded DB password from run-atgbics-mac.sh
The script hardcoded the pre-rotation POSTGRES_PASSWORD (retired 2026-06-04,
already invalid). Source the current password from ~/.tip/.env (git-ignored,
exported) instead — same pattern as the FS.com residential runner.
2026-07-06 10:16:27 +02:00

57 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# run-atgbics-mac.sh — Run ATGBICS scraper from Mac (bypasses Erik datacenter IP block)
#
# Uses Shopify JSON API (no Playwright needed).
# Connects to Erik's PostgreSQL via SSH tunnel.
#
# Usage: ./scripts/run-atgbics-mac.sh
# Requirements: SSH access to Erik (root@82.165.222.127)
set -euo pipefail
REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
TUNNEL_PORT=5434
TUNNEL_PID=""
LOG="/tmp/atgbics-mac-run.log"
cleanup() {
if [[ -n "$TUNNEL_PID" ]]; then
echo "Closing SSH tunnel (PID $TUNNEL_PID)..."
kill "$TUNNEL_PID" 2>/dev/null || true
fi
}
trap cleanup EXIT
echo "=== ATGBICS Mac Runner ==="
echo "Repo: $REPO_DIR"
# Open SSH tunnel to Erik's PostgreSQL
echo "Opening SSH tunnel to Erik DB (port 5433 → local 5434)..."
ssh -fNL "${TUNNEL_PORT}:127.0.0.1:5433" root@82.165.222.127
TUNNEL_PID=$(lsof -ti "TCP:${TUNNEL_PORT}" -sTCP:LISTEN 2>/dev/null | head -1)
echo "Tunnel open (listener PID: ${TUNNEL_PID:-unknown})"
# Wait briefly for tunnel to stabilize
sleep 1
# Build scraper if needed
if [[ ! -f "$REPO_DIR/packages/scraper/dist/scrapers/atgbics.js" ]]; then
echo "Building scraper package..."
cd "$REPO_DIR/packages/scraper" && npm run build
fi
# Load current DB password (not hardcoded — post-rotation secret lives in ~/.tip/.env)
[ -f "$HOME/.tip/.env" ] && set -a && source "$HOME/.tip/.env" && set +a
# Run scraper
echo "Running ATGBICS scraper..."
cd "$REPO_DIR"
POSTGRES_HOST=127.0.0.1 \
POSTGRES_PORT="${TUNNEL_PORT}" \
POSTGRES_USER=tip \
POSTGRES_DB=transceiver_db \
node packages/scraper/dist/scrapers/atgbics.js 2>&1 | tee "$LOG"
echo ""
echo "Log saved to: $LOG"
echo "=== Done ==="