FinancePlanner/git-cron-setup.sh
2026-05-29 12:00:49 +01:00

48 lines
1.7 KiB
Bash
Executable file
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ─────────────────────────────────────────────
# git-cron-setup.sh · Optional: auto-sync
# on a schedule using cron.
#
# Adds a cron job that runs git-sync.sh
# every night at 2am.
# ─────────────────────────────────────────────
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SYNC_SCRIPT="$SCRIPT_DIR/git-sync.sh"
LOG_FILE="$SCRIPT_DIR/git-sync.log"
CRON_SCHEDULE="0 2 * * *" # 2:00am daily — change if you like
echo ""
echo "╔══════════════════════════════════════════╗"
echo "║ Auto-Sync Cron Setup ║"
echo "╚══════════════════════════════════════════╝"
echo ""
# Check the sync script exists
if [ ! -f "$SYNC_SCRIPT" ]; then
echo "$SYNC_SCRIPT not found. Please upload git-sync.sh first."
exit 1
fi
chmod +x "$SYNC_SCRIPT"
CRON_LINE="$CRON_SCHEDULE $SYNC_SCRIPT >> $LOG_FILE 2>&1"
# Don't add duplicate
if crontab -l 2>/dev/null | grep -qF "$SYNC_SCRIPT"; then
echo " Cron job already exists — no changes made."
else
(crontab -l 2>/dev/null; echo "$CRON_LINE") | crontab -
echo "✅ Cron job added:"
echo " $CRON_LINE"
fi
echo ""
echo "Current cron jobs:"
crontab -l
echo ""
echo "Logs will be written to: $LOG_FILE"
echo ""
echo "To remove the cron job: crontab -e (then delete the line)"
echo "To run a sync right now: $SYNC_SCRIPT"
echo ""