From a8d027dc7c6312969fa91165e0e99676f23eb6e4 Mon Sep 17 00:00:00 2001 From: Jan Sydänviita Date: Wed, 19 Aug 2026 16:39:03 +0300 Subject: Improve forge --- roles/jails/22_forge/files/git-mirrors.sh | 24 +++++++++++++ roles/jails/22_forge/files/git-shell-commands/help | 11 +++--- .../22_forge/files/git-shell-commands/mirror-to | 39 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 roles/jails/22_forge/files/git-mirrors.sh create mode 100644 roles/jails/22_forge/files/git-shell-commands/mirror-to (limited to 'roles/jails/22_forge/files') 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" diff --git a/roles/jails/22_forge/files/git-shell-commands/help b/roles/jails/22_forge/files/git-shell-commands/help index fd0690d..e8f2631 100644 --- a/roles/jails/22_forge/files/git-shell-commands/help +++ b/roles/jails/22_forge/files/git-shell-commands/help @@ -2,10 +2,11 @@ cat </dev/null 2>&1; then + git remote remove mirror-to + echo "Removed mirror for $REPO" + else + echo "No mirror configured for $REPO" + fi + exit 0 +fi + +if git remote get-url mirror-to >/dev/null 2>&1; then + git remote set-url mirror-to "$REMOTE" +else + git remote add mirror-to "$REMOTE" +fi + +echo "Configured $REPO to mirror to $REMOTE" +echo "Mirrors run hourly. Logs: /var/log/git-mirrors.log" -- cgit v1.3