diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2023-08-26 23:22:18 +0200 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2023-08-26 23:22:18 +0200 |
commit | 1887e1cca6e988786c600660f2e1090bf69cbf2e (patch) | |
tree | 679b01f4007bda29e22028e3aab1181e7fd69fb7 /roles/git/files/runner-mirror/mirror.sh | |
parent | 2cab07c316fe414f0b1061b40fd7a9ae0e0b6a9c (diff) | |
download | ansible-memzero-1887e1cca6e988786c600660f2e1090bf69cbf2e.tar.gz ansible-memzero-1887e1cca6e988786c600660f2e1090bf69cbf2e.zip |
git: add runner to mirror github projects
Diffstat (limited to 'roles/git/files/runner-mirror/mirror.sh')
-rwxr-xr-x | roles/git/files/runner-mirror/mirror.sh | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/roles/git/files/runner-mirror/mirror.sh b/roles/git/files/runner-mirror/mirror.sh new file mode 100755 index 0000000..a517b86 --- /dev/null +++ b/roles/git/files/runner-mirror/mirror.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +function mirror() { + local repo=$1 + + if [ ! -d $repo ]; then + git clone --mirror https://github.com/johannst/$repo + else + git -C $repo fetch --all --prune + fi + + git -C $repo push --mirror ssh://git.memzero.de/mirror/$repo +} + +function lock() { + # Open lock file. + exec 42<> /tmp/mirror.lock + # Get exclusive lock. + flock -x 42 + # Automatically unlock on exit. + trap "flock -u 42" EXIT +} + +# Ensure only a single script instance runs at a time. +lock + +mkdir -p mirrors +pushd mirrors + +for R in $(cat /projects.list | awk -F '/' '/mirror/ { print $2 }'); do + echo "==> REPO: $R" + mirror $R +done |