From a88c6df48342a32f4193480d3d69eafbe0d13cc6 Mon Sep 17 00:00:00 2001 From: dd Date: Sat, 6 Jul 2024 08:06:41 +0200 Subject: added vyos-github-mirror.sh --- extras/mirror/vyos-github-mirror.sh | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 extras/mirror/vyos-github-mirror.sh (limited to 'extras/mirror') diff --git a/extras/mirror/vyos-github-mirror.sh b/extras/mirror/vyos-github-mirror.sh new file mode 100755 index 0000000..1950e30 --- /dev/null +++ b/extras/mirror/vyos-github-mirror.sh @@ -0,0 +1,51 @@ +#!/bin/bash +set -e + +# +# You can use this script to mirror VyOS repositories for safekeeping purposes. +# It's good idea to use some kind of backup with versioning ability, like the duplicity/duply. +# To make sure you can go back in time, if something you want from the repositories gets deleted. +# + +rootDir="/opt/vyos-git" +dataDir="$rootDir/data" +reposDir="$rootDir/repos" + +mkdir -p "$dataDir" +mkdir -p "$reposDir" + +page=1 +while [ $page -le 1000 ] +do + echo "Processing page $page" + + path="$datadir/repos-$page.json" + curl -sS --fail-with-body "https://api.github.com/orgs/vyos/repos?per_page=50&page=$page" -o "$path" + + emptyPage=true + while read gitUrl + do + directory=$(echo "$gitUrl" | grep -oP '([^/]+).git') + fullPath="$reposDir/$directory" + if [ -d "$fullPath" ]; then + echo "Updating $gitUrl in $fullPath" + git -C "$fullPath" remote update 2>&1 + if [ $? -ne 0 ]; then + >&2 echo "ERROR: failed to 'git remote update' for $fullPath" + fi + else + echo "Cloning $gitUrl as $fullPath" + mkdir -p "$fullPath" + git -C "$fullPath" clone --mirror "$gitUrl" . + fi + + emptyPage=false + done < <(cat "$path" | jq -c -r '.[].clone_url') + + if [ $emptyPage = true ]; then + echo "All done" + break + fi + + page=$((page+1)) +done -- cgit v1.2.3