#!/bin/bash # Sync dyno.yml from Hetzner host "im" # Runs via cron every 5 minutes # Auto-commits and pushes if changes detected SCRIPTS_DIR=~/scripts DEST_FILE="$SCRIPTS_DIR/configs/dyno.yml" LOG_FILE="$SCRIPTS_DIR/logs/sync-dyno.log" # Ensure dirs exist mkdir -p "$SCRIPTS_DIR/configs" mkdir -p "$SCRIPTS_DIR/logs" # Logging function log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE" } # Rotate log if > 1MB if [ -f "$LOG_FILE" ] && [ $(stat -c%s "$LOG_FILE" 2>/dev/null || echo 0) -gt 1048576 ]; then mv "$LOG_FILE" "$LOG_FILE.old" fi # Sync file - use explicit SSH options for cron compatibility if ! rsync -az -e "ssh -o StrictHostKeyChecking=no" maddox@192.168.12.3:/matrix/traefik/config/dyno.yml "$DEST_FILE" 2>> "$LOG_FILE"; then log "ERROR: rsync failed" exit 1 fi log "Synced dyno.yml" # Check for changes and auto-commit/push cd "$SCRIPTS_DIR" if [ -d .git ]; then if ! git diff --quiet configs/dyno.yml 2>/dev/null; then log "Changes detected in dyno.yml" # Auto-commit git add configs/dyno.yml git commit -m "Auto-sync dyno.yml $(date '+%Y-%m-%d %H:%M')" >> "$LOG_FILE" 2>&1 log "Committed changes" # Auto-push (if remote configured) if git remote | grep -q origin; then if git push origin main >> "$LOG_FILE" 2>&1; then log "Pushed to origin" else log "ERROR: Push failed" fi else log "No remote configured, skipping push" fi fi fi