← back to Allnewsdaily
scripts/push-videos.sh
36 lines
#!/usr/bin/env bash
# Sync the All News Daily channel's Shorts on THIS Mac (token lives here) then rsync data/videos.json
# to Kamatera prod so allnewsdaily.com/videos auto-updates. Mirrors push-wire.sh / push-live-status.sh.
# Reversible: unload the launchd job to stop.
set -euo pipefail
cd "$(dirname "$0")/.." # allnewsdaily repo root
PROD="${PROD_HOST:-root@45.61.58.125}"
REMOTE="/root/Projects/allnewsdaily/data/videos.json"
# Boot race (TK-12250, sibling of TK-12257): launchd RunAtLoad fires right after a
# reboot, before the network interface/route is up, so the API fetch + ssh/rsync die
# with "fetch failed" / "No route to host" -> exit 255. Wait (bounded) for network
# using the shared helper before doing any real work. Post-grace-window, a real
# outage still proceeds and FAILs normally (never masks a genuine problem).
# shellcheck source=/dev/null
source "$HOME/.claude/skills/_shared/boot-grace.sh"
boot_grace_wait network
if [ "$BOOT_GRACE_ACTION" = "boot_grace" ]; then
echo "[videos-push] $BOOT_GRACE_REASON — skipping this RunAtLoad fire, next StartCalendarInterval tick will run normally"
exit 0
fi
NODE="$(command -v node || true)"
for cand in /opt/homebrew/bin/node /usr/local/bin/node /usr/bin/node; do
[ -z "$NODE" ] && [ -x "$cand" ] && NODE="$cand"
done
[ -n "$NODE" ] || { echo "[videos-push] node not found"; exit 3; }
"$NODE" scripts/sync-videos.mjs || { echo "[videos-push] sync failed, not pushing"; exit 1; }
"$NODE" -e "const a=require('./data/videos.json'); if(!Array.isArray(a)){process.exit(2)}" \
|| { echo "[videos-push] videos.json invalid, not pushing"; exit 2; }
rsync -az -e "ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new" \
data/videos.json "$PROD:$REMOTE"
echo "[videos-push] pushed $(date -u +%FT%TZ) → $PROD:$REMOTE"