aboutsummaryrefslogtreecommitdiffstats
path: root/roles/jails/22_forge/files/git-mirrors.sh
diff options
context:
space:
mode:
Diffstat (limited to 'roles/jails/22_forge/files/git-mirrors.sh')
-rw-r--r--roles/jails/22_forge/files/git-mirrors.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/roles/jails/22_forge/files/git-mirrors.sh b/roles/jails/22_forge/files/git-mirrors.sh
new file mode 100644
index 0000000..c96a000
--- /dev/null
+++ b/roles/jails/22_forge/files/git-mirrors.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Run hourly via cron. Mirrors all repos that have a 'mirror' remote configured.
+
+REPOS_DIR="/home/git"
+LOG="/var/log/git-mirrors.log"
+export GIT_SSH_COMMAND="ssh -i /home/git/.ssh/forge_deploy -o IdentitiesOnly=yes"
+
+echo "$(date) Starting mirror run" >> "$LOG"
+
+for repo in "$REPOS_DIR"/*.git; do
+ [ -d "$repo" ] || continue
+ name="$(basename "$repo" .git)"
+
+ remote=$(git -C "$repo" remote get-url mirror-to 2>/dev/null) || continue
+
+ echo "$(date) Mirroring $name -> $remote" >> "$LOG"
+ if git -C "$repo" push --mirror mirror-to >> "$LOG" 2>&1; then
+ echo "$(date) OK $name" >> "$LOG"
+ else
+ echo "$(date) FAILED $name" >> "$LOG"
+ fi
+done
+
+echo "$(date) Mirror run complete" >> "$LOG"