diff options
-rwxr-xr-x | gitolite-sync | 58 | ||||
-rw-r--r-- | gitolite-sync.service | 6 | ||||
-rw-r--r-- | gitolite-sync.timer | 9 |
3 files changed, 73 insertions, 0 deletions
diff --git a/gitolite-sync b/gitolite-sync new file mode 100755 index 0000000..8bedcd2 --- /dev/null +++ b/gitolite-sync @@ -0,0 +1,58 @@ +#!/bin/bash + +home=$( + getent passwd gitolite \ + | cut -d: -f6 +) + +if [ -z "${home}" ] || [ ! -d "${home}" ]; then + >&2 echo 'cannot find user gitolite' + exit 1 +fi + +find "${home}/repositories" \ + -type d \ + -name '*.git' \ + -printf '%p\n' \ + -prune \ +| while read -r path; do + remotes=$( + git -C "${path}" remote -v \ + | grep '[@.]eckner\.net:' \ + | awk '{print $1}' \ + | sort -u + ) + if [ -z "${remotes}" ]; then + >&2 printf 'Repository "%s" has no backup remotes.\n' \ + "${path}" + continue + fi + for remote in ${remotes}; do + git -C "${path}" fetch "${remote}" -p + done + branches=$( + git -C "${path}" branch --list \ + | sed 's/^.\s//' + ) + if [ -n "$(git -C "${path}" tag -l)" ]; then + has_tags=true + else + has_tags=false + fi + if [ -z "${branches}" ] && ! ${has_tags}; then + >&2 printf 'Repository "%s" has no branches and no tags.\n' \ + "${path}" + continue + fi + for remote in ${remotes}; do + if ${has_tags}; then + git -C "${path}" push --tags + fi + if [ -z "${branches}" ]; then + continue + fi + for branch in ${branches}; do + git -C "${path}" push "${remote}" "${branch}" + done + done +done diff --git a/gitolite-sync.service b/gitolite-sync.service new file mode 100644 index 0000000..f85eb43 --- /dev/null +++ b/gitolite-sync.service @@ -0,0 +1,6 @@ +[Unit] +Description=synchronize gitolite repositories to and from backup location(s) + +[Service] +User=gitolite +ExecStart=/usr/bin/gitolite-sync diff --git a/gitolite-sync.timer b/gitolite-sync.timer new file mode 100644 index 0000000..4a4e9bc --- /dev/null +++ b/gitolite-sync.timer @@ -0,0 +1,9 @@ +[Unit] +Description=repeatedly synchronize gitolite repositories + +[Timer] +RandomizedDelaySec=10min +OnCalendar=*-*-* *:00/10:00 + +[Install] +WantedBy=timers.target |