Files
gitea-ops/gitea-backups/bin/install-hooks.sh
T
prajwal a181625c89 Initial commit: backup + mirror automation for self-hosted Gitea
Includes:
- gitea-backups/bin/backup.sh (per-push bundle + DB snapshot to local + S3)
- gitea-backups/bin/install-hooks.sh (idempotent post-receive shim installer)
- gitea-backups/bin/retention.sh (count-based retention: keep newest 7 dates)
- gitea-mirror/bin/auto-mirror.sh (Gitea -> GitHub push mirror automation,
  hardened against Gitea outages)
- crontab.txt (reference for the 3 cron entries)
- README.md (architecture, layout, bootstrap)
2026-05-09 06:02:09 +00:00

36 lines
1018 B
Bash
Executable File

#!/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