diff --git a/install.sh b/install.sh index abe1f27..dce201d 100755 --- a/install.sh +++ b/install.sh @@ -296,6 +296,25 @@ for cam in "${CAMERAS[@]}"; do fi done +# ── Timezone drift check ───────────────────────────────────────────────────── +# Daily + shortly after boot: notify if TIMEZONE no longer matches the +# machine's timezone (systemd timers follow the machine, scripts follow TIMEZONE). +write_service "sky-cam-tzcheck" "timezone drift check" "tz-drift-check.sh" +cat > "$UNIT_DIR/sky-cam-tzcheck.timer" </dev/null || true + +# Machine's zone — read WITHOUT any TZ override so we see the real system value. +sys_tz="$(env -u TZ timedatectl show -p Timezone --value 2>/dev/null)" +[ -z "$sys_tz" ] && sys_tz="$(cat /etc/timezone 2>/dev/null)" +[ -z "$sys_tz" ] && sys_tz="$(readlink /etc/localtime 2>/dev/null | sed 's|.*/zoneinfo/||')" +if [ -z "$sys_tz" ]; then + echo "tz-drift-check: could not determine the machine's timezone — skipping" + exit 0 +fi + +# Compare by real UTC offsets across the year so aliases (US/Eastern vs +# America/New_York) and identical-rule zones are not reported as drift. +same=true +if [ "$sys_tz" != "$TIMEZONE" ]; then + for m in 01 04 07 10; do + a="$(TZ="$sys_tz" date -d "2026-$m-15 12:00 UTC" +%z)" + b="$(TZ="$TIMEZONE" date -d "2026-$m-15 12:00 UTC" +%z)" + [ "$a" = "$b" ] || { same=false; break; } + done +fi + +if $same; then + echo "Timezone OK: sky-cam TIMEZONE=$TIMEZONE, machine=$sys_tz" + exit 0 +fi + +msg="sky-cam TIMEZONE is $TIMEZONE but this machine's timezone is $sys_tz. Scheduled jobs run on the machine clock, so sunrise/seasons/moon jobs will fire at the wrong local time. Fix: set TIMEZONE=$sys_tz in $SCRIPT_DIR/.env and re-run ./install.sh, or run: sudo timedatectl set-timezone $TIMEZONE" +echo "WARNING: $msg" +"$SCRIPT_DIR/notify.sh" "WARNING: sky-cam timezone mismatch" "$msg" || true +exit 0