summaryrefslogtreecommitdiff
path: root/ansible/files
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-05-13 17:16:34 +0300
committerLars Wirzenius <liw@liw.fi>2021-05-13 17:16:34 +0300
commit9acbe58646ea92cf63070df4bd9a7aa3f0cdfb13 (patch)
treeeeda6d4f8cdcb130d743273d62266418ff2c9629 /ansible/files
parente479b2862228b2faf68896da48571307c9211779 (diff)
downloadansibleness-9acbe58646ea92cf63070df4bd9a7aa3f0cdfb13.tar.gz
move mirror-git from Hetzner to local, and automatically clone repos
Diffstat (limited to 'ansible/files')
-rw-r--r--ansible/files/mirror-git.sh67
-rw-r--r--ansible/files/mirror-list17
2 files changed, 84 insertions, 0 deletions
diff --git a/ansible/files/mirror-git.sh b/ansible/files/mirror-git.sh
new file mode 100644
index 0000000..be52661
--- /dev/null
+++ b/ansible/files/mirror-git.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+LIST=/etc/mirror-git.list
+# LIST=mirror-list
+
+set -euo pipefail
+
+die() {
+ echo "$@" 1>&2
+ exit 1
+}
+
+setup_clone() {
+ local dir="$1"
+ local fromurl="$2"
+ local tourl="$3"
+
+ if [ ! -e "$dir" ]; then
+ git clone -q "$fromurl" "$dir"
+ cd "$dir"
+ git remote rename origin gitlab
+ git remote add origin "$tourl"
+ fi
+
+}
+
+current_branch() {
+ git rev-parse --abbrev-ref HEAD
+}
+
+uncommitted() {
+ git status --short | grep '^ M ' >/dev/null
+}
+
+ssh-keyscan gitlab.com git.liw.fi >"$HOME/.ssh/known_hosts"
+
+grep '^[^#]' "$LIST" |
+ while read -r fromurl tourl; do
+ dir="$HOME/mirrors/$tourl"
+ fromurl="https://gitlab.com/$fromurl.git"
+ tourl="ssh://git@git.liw.fi/$tourl"
+
+ echo
+ echo "=============================================="
+ echo "from: $fromurl"
+ echo "via : $dir"
+ echo "to : $tourl"
+
+ setup_clone "$dir" "$fromurl" "$tourl"
+
+ cd "$dir"
+ case "$(current_branch)" in
+ master | main)
+ if uncommitted; then
+ die "there are uncommitted changes"
+ fi
+ git remote update --prune
+ git pull -q --rebase gitlab HEAD
+ git push -q origin HEAD
+ ;;
+ *)
+ die "not in main or master branch"
+ ;;
+ esac
+ done
+echo
+echo all mirror OK
diff --git a/ansible/files/mirror-list b/ansible/files/mirror-list
new file mode 100644
index 0000000..0e2ffb7
--- /dev/null
+++ b/ansible/files/mirror-list
@@ -0,0 +1,17 @@
+larswirzenius/bumper bumper-rs
+larswirzenius/clab clab
+larswirzenius/contractor2 contractor2
+larswirzenius/ewww ewww
+larswirzenius/gtdfh gtdfh.liw.fi
+larswirzenius/ideas ideas
+larswirzenius/jt jt2
+larswirzenius/obnam obnam2
+larswirzenius/obnam.org obnam.org
+larswirzenius/puomi puomi
+larswirzenius/summain summain-rs
+larswirzenius/vmadm vmadm
+larswirzenius/vmdb2 vmdb2
+larswirzenius/vmdb2-web vmdb2.liw.fi
+larswirzenius/yuck yuck
+subplot/subplot subplot
+subplot/subplot-web subplot.liw.fi