diff options
| author | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-05-07 23:18:27 +0100 |
|---|---|---|
| committer | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-05-07 23:18:27 +0100 |
| commit | 2cb9c5a451be25e3d31fa68914323e1f2ade1444 (patch) | |
| tree | e0b179179c20774d132dd941bac2b6a9e08dfaab /scripts/push-repo-mirrors.bash | |
| parent | a59c578b4d65a7e2f92fbd9568b0011cf54285c4 (diff) | |
| download | git.zue.dev-2cb9c5a451be25e3d31fa68914323e1f2ade1444.tar git.zue.dev-2cb9c5a451be25e3d31fa68914323e1f2ade1444.tar.gz git.zue.dev-2cb9c5a451be25e3d31fa68914323e1f2ade1444.tar.bz2 git.zue.dev-2cb9c5a451be25e3d31fa68914323e1f2ade1444.tar.xz git.zue.dev-2cb9c5a451be25e3d31fa68914323e1f2ade1444.zip | |
add mirroring functionality
Diffstat (limited to 'scripts/push-repo-mirrors.bash')
| -rw-r--r-- | scripts/push-repo-mirrors.bash | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/scripts/push-repo-mirrors.bash b/scripts/push-repo-mirrors.bash new file mode 100644 index 0000000..e25d39f --- /dev/null +++ b/scripts/push-repo-mirrors.bash @@ -0,0 +1,49 @@ +#!/bin/bash + +# This script pushes the repository mirrors to their respective remote URLs if they are defined in the .gitinfo file. + +for repository in /repositories/*; do + echo "Processing repository: $(basename "$repository")" + + cd /repositories/$(basename "$repository") + + gitinfoExists=$(git ls-tree HEAD -- .gitinfo 2>/dev/null) + + echo "gitinfoExists: $gitinfoExists" + + # does gitinfo exist? + if [ -z "$gitinfoExists" ]; then + echo "No .gitinfo found for $(basename "$repository"). Skipping." + continue + fi + + gitinfoContents=$(git cat-file -p @:.gitinfo) + + echo "gitinfoContents: $gitinfoContents" + + # extract mirrors from gitinfo (json format) + mirrors=$(echo "$gitinfoContents" | grep -oP '"mirrors":\s*\[\K[^\]]+') + + echo "Extracted mirrors: $mirrors" + + # push to each mirror + for mirror in $(echo "$mirrors" | tr ',' '\n'); do + case "$mirror" in + *github.com*) + # do we have a /run/secrets/github_token defined? + if [ ! -f /run/secrets/github_token ]; then + echo "/run/secrets/github_token not found. Skipping push to $mirror." + continue + fi + + GITHUB_TOKEN=$(cat /run/secrets/github_token) + + echo "Pushing to GitHub mirror: $mirror" + git push --mirror "https://x-access-token:$GITHUB_TOKEN@$mirror" || echo "Failed to push to $mirror" + ;; + *) + echo "Unknown mirror type: $mirror. Skipping." + ;; + esac + done +done
\ No newline at end of file |
