← back to Silverleafwallpaper
scripts/wire-george-creds.sh
55 lines
#!/usr/bin/env bash
# wire-george-creds.sh — ONE-SHOT: provision silverleafwallpaper.com's George
# credentials on Kamatera so its contact forms can actually send email.
#
# Silver's contact module had NO George creds on Kamatera (no .env), so the form
# fails-closed (persists the lead, sends nothing). This writes a .env with:
# GEORGE_AUTH = "Basic base64(admin:)" — the empty-pass cred
# George accepts (proven working on goldleaf)
# GEORGE_EXTERNAL_SEND_TOKEN = copied on-box from the george agent's own .env
# then restarts the process and verifies the live form returns success.
#
# The secret never leaves the Kamatera host (copied .env→.env on the box).
# On success it BOOTS OUT + DELETES its own launchd job so it truly runs once.
# Authorized by Steve 2026-07-14 ("wire silver at 4am").
set -uo pipefail
LABEL=com.steve.silver-george-wire
PLIST="$HOME/Library/LaunchAgents/$LABEL.plist"
LOG="$HOME/.claude/logs/silver-george-wire.log"
mkdir -p "$(dirname "$LOG")"
echo "===== silver George wire $(date '+%F %T') =====" | tee -a "$LOG"
RESULT=$(ssh kamatera '
S=/var/www/silverleafwallpaper.com
TOK=$(grep -m1 "^GEORGE_EXTERNAL_SEND_TOKEN=" /root/DW-Agents/gmail-agent/.env | cut -d= -f2-)
if [ -z "$TOK" ]; then echo "TOKEN_NOT_FOUND"; exit 1; fi
AUTH="Basic $(printf admin: | base64)"
touch $S/.env
grep -vE "^(GEORGE_EXTERNAL_SEND_TOKEN|GEORGE_AUTH)=" $S/.env > $S/.env.t 2>/dev/null || true
echo "GEORGE_AUTH=$AUTH" >> $S/.env.t
echo "GEORGE_EXTERNAL_SEND_TOKEN=$TOK" >> $S/.env.t
mv $S/.env.t $S/.env && chmod 600 $S/.env
pm2 restart silverleafwallpaper --update-env >/dev/null 2>&1
sleep 3
echo "WIRED tok_len=${#TOK}"
' 2>&1)
echo "$RESULT" | tee -a "$LOG"
echo "-- verify live form --" | tee -a "$LOG"
VERIFY=$(curl -s --max-time 30 -X POST https://silverleafwallpaper.com/api/send-sample \
-H 'Content-Type: application/json' \
-d '{"name":"Silver form auto-wire verify (ignore)","email":"steveabramsdesigns@gmail.com","sku":"RML-33022","title":"Silver Leaf verify","message":"ignore"}' \
-w ' HTTP %{http_code}')
echo "$VERIFY" | tee -a "$LOG"
if echo "$VERIFY" | grep -q '"success":true'; then
echo "SUCCESS — silver form sends. Self-removing one-shot job." | tee -a "$LOG"
launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true
rm -f "$PLIST"
else
echo "FAILED — leaving job in place for retry / manual look." | tee -a "$LOG"
exit 1
fi