summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordd <dd@wx.tnyzeq.icu>2024-07-06 08:06:41 +0200
committerdd <dd@wx.tnyzeq.icu>2024-07-06 08:06:41 +0200
commita88c6df48342a32f4193480d3d69eafbe0d13cc6 (patch)
tree31404e2efdedca33aad551fdf3c79295375d2c98
parentfb0e9995298a8cd951ceef0d9bb427be584bd697 (diff)
downloadvyos-jenkins-a88c6df48342a32f4193480d3d69eafbe0d13cc6.tar.gz
vyos-jenkins-a88c6df48342a32f4193480d3d69eafbe0d13cc6.zip
added vyos-github-mirror.sh
-rwxr-xr-xextras/mirror/vyos-github-mirror.sh51
1 files changed, 51 insertions, 0 deletions
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