git_infra

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

update_mirrors.sh (1616B)


      1 #!/bin/sh
      2 # Updates git mirror repositories from upstream. This script is typically
      3 # installed as a cron job for for user `git` via `crontab -e`:
      4 #
      5 # minute hour    mday    month   wday    command
      6 # 0       *       *       *       *       ~/_git_infra/update_mirrors.sh ~/etc/mirrors_hourly.conf
      7 # *       0       *       *       *       ~/_git_infra/update_mirrors.sh ~/etc/mirrors_daily.conf
      8 # *       *       *       *       0       ~/_git_infra/update_mirrors.sh ~/etc/mirrors_weekly.conf
      9 #
     10 # The config files are formatted as one repo per line. The repos must be
     11 # specified as absolute paths.
     12 
     13 # Echos arguments to stderr.
     14 printerr() {
     15   >&2 echo "$@"
     16 }
     17 
     18 # Prints the usage string.
     19 usage() {
     20   printerr "usage: $0 CONFIG"
     21 }
     22 
     23 # Exits with failure if $1 is not an absolute path.
     24 verify_absolute() {
     25   case "$1" in
     26     /*)
     27       ;;
     28     *)
     29       printerr "[git mirror] ERROR: must use absolute paths: $1"
     30       exit 1
     31       ;;
     32   esac
     33 }
     34 
     35 # Fetches the mirrors specified in the arguments list.
     36 fetch_mirrors() {
     37   mirrors="$*"
     38   for mirror in $mirrors; do
     39     verify_absolute "$mirror"
     40     if [ -d "$mirror" ]; then
     41       cd "$mirror"
     42       printerr "[git mirror] ... $mirror"
     43       git fetch
     44 
     45       # Regenerate stagit pages for public, unlisted repos.
     46       if [ -e git-daemon-export-ok ]; then
     47         grm rc `basename "$mirror" '.git'`
     48       fi
     49     else
     50       printerr "[git mirror] ... $mirror NOT FOUND"
     51     fi
     52   done
     53 }
     54 
     55 CONFIG="$1"
     56 if [ -z "${CONFIG}" ]; then
     57   usage
     58   exit 1
     59 fi
     60 
     61 printerr "[git mirror] Updating mirror repos from $CONFIG"
     62 if [ -f "$CONFIG" ]; then
     63   fetch_mirrors "$(sort -u "$CONFIG")"
     64 fi