git_infra

Git infra scripts for git.bracken.jp
git clone https://git.bracken.jp/git_infra.git
Log | Files | Refs | LICENSE

commit 2811f173d0d4b8ea0a37fff4ff5db262590849c0
parent 6d1542fc17442b99f1d3a74e25863804e0fc5ae7
Author: Chris Bracken <chris@bracken.jp>
Date:   Thu, 12 Aug 2021 16:41:18 -0700

Add update_mirrors.sh

update_mirrors.sh updates all mirror repos listed in the specified
configuration file on each invocation. Configuration files take the form
of a list of repository absolute paths, one per line.

This can be installed as a cron job to keep mirrors up to date at
various frequencies. Users should avoid polling smaller git servers
frequently.

Diffstat:
Aupdate_mirrors.sh | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+), 0 deletions(-)

diff --git a/update_mirrors.sh b/update_mirrors.sh @@ -0,0 +1,59 @@ +#!/bin/sh +# Updates git mirror repositories from upstream. This script is typically +# installed as a cron job for for user `git` via `crontab -e`: +# +# minute hour mday month wday command +# 0 * * * * ~/_git_infra/update_mirrors.sh ~/etc/mirrors_hourly.conf +# * 0 * * * ~/_git_infra/update_mirrors.sh ~/etc/mirrors_daily.conf +# * * * * 0 ~/_git_infra/update_mirrors.sh ~/etc/mirrors_weekly.conf +# +# The config files are formatted as one repo per line. The repos must be +# specified as absolute paths. + +# Echos arguments to stderr. +printerr() { + >&2 echo "$@" +} + +# Prints the usage string. +usage() { + printerr "usage: $0 CONFIG" +} + +# Exits with failure if $1 is not an absolute path. +verify_absolute() { + case "$1" in + /*) + ;; + *) + printerr "[git mirror] ERROR: must use absolute paths: $1" + exit 1 + ;; + esac +} + +# Fetches the mirrors specified in the arguments list. +fetch_mirrors() { + mirrors="$*" + for mirror in $mirrors; do + verify_absolute "$mirror" + if [ -d "$mirror" ]; then + cd "$mirror" + printerr "[git mirror] ... $mirror" + git fetch + else + printerr "[git mirror] ... $mirror NOT FOUND" + fi + done +} + +CONFIG="$1" +if [ -z "${CONFIG}" ]; then + usage + exit 1 +fi + +printerr "[git mirror] Updating mirror repos from $CONFIG" +if [ -f "$CONFIG" ]; then + fetch_mirrors "$(sort -u "$CONFIG")" +fi