#!/usr/bin/env bash # Install / refresh the per-repo backup shim in every Gitea repo. # Idempotent: safe to run anytime, including via cron. # Usage: ./install-hooks.sh [--quiet] set -euo pipefail GITEA_REPOS="/home/ubuntu/gitea/data/gitea-repositories" SHIM_NAME="zzz-backup" QUIET=0 [[ "${1:-}" == "--quiet" ]] && QUIET=1 shim_content='#!/usr/bin/env bash exec /home/ubuntu/gitea-backups/bin/backup.sh ' installed=0 already=0 for repo in "$GITEA_REPOS"/*/*.git; do [[ -d "$repo" ]] || continue hook_dir="$repo/hooks/post-receive.d" mkdir -p "$hook_dir" shim="$hook_dir/$SHIM_NAME" if [[ -f "$shim" ]] && diff -q <(printf '%s' "$shim_content") "$shim" >/dev/null 2>&1; then already=$((already + 1)) else printf '%s' "$shim_content" > "$shim" chmod +x "$shim" installed=$((installed + 1)) [[ $QUIET -eq 0 ]] && echo "installed: $repo" fi done [[ $QUIET -eq 0 ]] && echo "done — installed/updated: $installed, already-current: $already" exit 0