#!/usr/bin/env bash # Rebuild a throwaway data dir + server for the profile E2E suite. # The suite completes a profile for 21, so it is NOT idempotent: reseed every run. # # Two rules learned the hard way, do not undo them: # * NEVER name the data-dir variable TMP/TEMP/TMPDIR. On Windows those are already # set to the system temp directory, so `${TMP:-default}` silently inherits it and # the rm -rf below wipes the machine's temp folder instead of the throwaway dir. # * NEVER add pkill/taskkill. A broad pattern kills the tooling running this script. # Stop the old server through the pid file instead. # # Usage: bash qa/reseed.sh (then read $RMCQA_DIR/tokens.txt) set -e RMCQA_DIR=${RMCQA_DIR:-/d/tmp/rmc-e2e-data} PORT=${PORT:-3399} case "$RMCQA_DIR" in /d/tmp/*|/D/tmp/*) ;; *) echo "refusing: RMCQA_DIR must live under /d/tmp (got '$RMCQA_DIR')"; exit 2 ;; esac if [ -f "$RMCQA_DIR/server.pid" ]; then kill "$(cat "$RMCQA_DIR/server.pid")" 2>/dev/null || true; sleep 2; fi rm -rf "$RMCQA_DIR"; mkdir -p "$RMCQA_DIR" if [ -f /d/tmp/rmc-config-cache.json ]; then cp /d/tmp/rmc-config-cache.json "$RMCQA_DIR/config.json"; else ssh -o StrictHostKeyChecking=no root@coolify.saasy.top \ "docker exec \$(docker ps -q --filter name=kr445fqc) cat /app/data/config.json" > "$RMCQA_DIR/config.json" cp "$RMCQA_DIR/config.json" /d/tmp/rmc-config-cache.json; fi echo '[]' > "$RMCQA_DIR/sponsors.json" echo '{"49":{"email":"seeded49@example.com","ts":"x"}}' > "$RMCQA_DIR/member-alerts.json" node -e "const m=require('./messages.js'); m.init({dataDir:process.argv[1],chain:require('./chain.js'),isProd:false}); require('fs').writeFileSync(process.argv[1]+'/tokens.txt', m.mintSession(21)+'\n'+m.mintSession(49));" "$RMCQA_DIR" PORT=$PORT DATA_DIR=$RMCQA_DIR ADMIN_PASSWORD=localtest node server.js > "$RMCQA_DIR/server.log" 2>&1 & echo $! > "$RMCQA_DIR/server.pid" for i in $(seq 1 40); do if [ "$(curl -s -o /dev/null -w %{http_code} "http://127.0.0.1:$PORT/my/21" 2>/dev/null)" = "200" ]; then echo "ready on $PORT"; exit 0; fi sleep 1 done echo "server did not come up"; tail -20 "$RMCQA_DIR/server.log"; exit 1