#!/usr/bin/env bash
# refresh_calendar.sh — regenerate 07-calendar/macro-book.ics
#
# Wraps scripts/calendar_sync.py with logging. Designed to be run by cron.
# Cron entry (runs daily at 06:00 Europe/Zurich):
#   0 6 * * * /home/rpi/Obsidian-Macro/scripts/refresh_calendar.sh >> /home/rpi/Obsidian-Macro/07-calendar/refresh.log 2>&1
#
# Or via systemd user timer — see 07-calendar/MAINTENANCE.md.

set -euo pipefail
VAULT="${MACRO_BOOK_VAULT:-/home/rpi/Obsidian-Macro}"
LOG_DIR="$VAULT/07-calendar"
mkdir -p "$LOG_DIR"

echo "=== refresh_calendar.sh at $(date -Iseconds) ==="
python3 "$VAULT/scripts/calendar_sync.py" \
    --yaml "$VAULT/07-calendar/events.yaml" \
    --output "$VAULT/07-calendar/macro-book.ics"
echo "=== done at $(date -Iseconds) ==="
