← back to Goldleafwallpaper
scripts/rebuild-and-deploy.sh
31 lines
#!/usr/bin/env bash
# rebuild-and-deploy.sh — refresh goldleafwallpaper.com's RML- feed from the
# local dw_unified mirror and push it live. Idempotent; safe to run any time.
#
# 1. rebuild data/products.json from dw_unified (ACTIVE RML- only)
# 2. rsync it to the Kamatera static site
# 3. pm2 restart so the (static) server reloads the file
# 4. verify the live count over HTTPS
#
# Run manually, or nightly via launchd (com.steve.metalleaf-rml-refresh).
set -euo pipefail
REPO="$(cd "$(dirname "$0")/.." && pwd)"
REMOTE="/root/Projects/Designer-Wallcoverings/DW-Websites/GoldLeafWallpaper"
PM2_PROC="goldleafwallpaper-website"
HEALTH="https://goldleafwallpaper.com/data/products.json"
cd "$REPO"
echo "[$(date '+%F %T')] rebuild gold RML- feed"
node scripts/build-products.js
echo "rsync → Kamatera"
rsync -az data/products.json "kamatera:$REMOTE/data/products.json"
echo "pm2 restart + verify"
ssh kamatera "pm2 restart $PM2_PROC >/dev/null 2>&1; sleep 2"
COUNT=$(curl -s --max-time 20 "$HEALTH" | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{const a=JSON.parse(s);console.log(a.length)}catch(e){console.log("ERR")}})')
echo "[$(date '+%F %T')] live count: $COUNT"
[ "$COUNT" = "ERR" ] && { echo "VERIFY FAILED"; exit 1; }
echo "done."