← back to Dw Staged Active Viewer
scripts/refresh-and-push.sh
28 lines
#!/usr/bin/env bash
# refresh-and-push.sh (Mac2-only)
# Regenerates the staged snapshot from Mac2-local dw_unified, then rsyncs it to the
# Kamatera-hosted viewer so https://staged.designerwallcoverings.com stays current.
# Runs hourly via launchd (com.steve.dw-staged-active-snapshot), aligned ~with the cadence.
# READ-ONLY against the DB; the only write is the static JSON + the rsync to Kamatera.
set -euo pipefail
PROJ="$HOME/Projects/dw-staged-active-viewer"
REMOTE_HOST="my-server"
REMOTE_PATH="/root/public-projects/staged-viewer/data/staged-snapshot.json"
LOG="$PROJ/tmp/refresh.log"
mkdir -p "$PROJ/tmp"
# Use a login shell PATH so node + psql resolve under launchd.
export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
{
echo "=== $(date '+%Y-%m-%d %H:%M:%S') refresh start ==="
cd "$PROJ"
node scripts/build-snapshot.js
# atomic rsync to a temp name then mv on the remote so the live reader never sees a half file
rsync -az --timeout=60 "$PROJ/data/staged-snapshot.json" \
"$REMOTE_HOST:${REMOTE_PATH}.tmp"
ssh "$REMOTE_HOST" "mv -f '${REMOTE_PATH}.tmp' '${REMOTE_PATH}'"
echo "=== $(date '+%Y-%m-%d %H:%M:%S') refresh + push OK ==="
} >> "$LOG" 2>&1