Initial commit: homelab maintenance and automation scripts

This commit is contained in:
ray
2026-07-12 10:15:25 -04:00
commit af29737887
5 changed files with 157 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
#!/bin/bash
# Auto-save any repos with uncommitted changes to Gitea
# Runs daily via cron — stdout is delivered to Telegram
set -euo pipefail
DATE=$(date '+%Y-%m-%d')
LOGFILE="$HOME/.hermes/logs/git-autosave.log"
mkdir -p "$HOME/.hermes/logs"
REPOS=(
"/mnt/seagate8tb/Websites/ShopProQuote.backup-20260626-2058/spq-v2:main:"
"/mnt/seagate8tb/docker:main:"
"/etc/nginx:main:sudo"
"/home/ray/.hermes:main:"
"/home/ray/homelab-scripts:main:"
)
SAVED=()
CLEAN=()
ERRORS=()
for entry in "${REPOS[@]}"; do
DIR="${entry%%:*}"
BRANCH="${entry##*:}"
NAME=$(basename "$DIR")
if [ ! -d "$DIR/.git" ]; then
echo "[$DATE] SKIP $DIR — no .git" >> "$LOGFILE"
continue
fi
cd "$DIR"
if [ -z "$(git status --porcelain 2>/dev/null)" ]; then
echo "[$DATE] CLEAN $NAME" >> "$LOGFILE"
CLEAN+=("$NAME")
continue
fi
git pull --rebase origin "$BRANCH" 2>/dev/null || true
git add -A
if git commit -m "auto-save $DATE"; then
if git push origin "$BRANCH" 2>/dev/null; then
echo "[$DATE] SAVED $NAME" >> "$LOGFILE"
SAVED+=("$NAME")
else
echo "[$DATE] PUSH FAILED $NAME" >> "$LOGFILE"
ERRORS+=("$NAME (push failed)")
fi
else
echo "[$DATE] COMMIT FAILED $NAME" >> "$LOGFILE"
ERRORS+=("$NAME (commit failed)")
fi
done
# Build stdout message for delivery
MSG=""
if [ ${#SAVED[@]} -gt 0 ]; then
MSG="${MSG}✓ Saved: ${SAVED[*]}\n"
fi
if [ ${#CLEAN[@]} -gt 0 ]; then
MSG="${MSG}— Clean: ${CLEAN[*]}\n"
fi
if [ ${#ERRORS[@]} -gt 0 ]; then
MSG="${MSG}✗ Errors: ${ERRORS[*]}\n"
fi
if [ -n "$MSG" ]; then
echo -e "Gitea auto-save $DATE\n${MSG}"
fi