#!/bin/sh # # This script runs "git update-server-info" on repositories which # didn't have it run in some time. This script is intended to be # run as cronjob, and serve as backup means to do "git update-server-info" # in case git/gerrit hook based update fail/misbehave. # GITROOT=/srv/repositories # Max age since git update-server-info was run in minutes, use leading "+" for "more than" MAXAGE="+60" # find experssion for dirs to exclude EXCLUDE="-path '*/lost+found' -prune -o" # Process so many repos per invocation CHUNK=500 if [ $(id -u -n) = "root" ]; then echo "This script must not be run as 'root' user" exit 1 fi # GNU find up to 4.4.2 has a bug, that if it is started with unreadable # current directory, it will fail with: # find: pred.c:1932: launch: Assertion `starting_desc >= 0' failed. # So, set dir to a safe one. cd /tmp # Resolve symlinks, as find won't work with a symlink unless it has trailing /. GITROOT=$(readlink -e $GITROOT) find_stale_info_refs () { find $GITROOT -path '*/lost+found' -prune -o \ -path '*.git/info' -type d '!' -exec test -e "{}/refs" ';' \ -print | sed 's|/info$||' # First find expression ignores lost+found dir find $GITROOT -path '*/lost+found' -prune -o \ -path '*.git/info/refs' -mmin "$MAXAGE" -print \ | sed -e 's|/info/refs||' } for dir in $(find_stale_info_refs | uniq | head -n $CHUNK); do # (echo $dir; ls -l $dir/info/refs) >>/tmp/update-server-info-fallback.log (cd $dir; git update-server-info || echo "Error while processing $dir") # Workaround for issue with git 2.2.1: http://article.gmane.org/gmane.comp.version-control.git/262026 chmod +r $dir/info/refs $dir/objects/info/packs # (ls -l $dir/info/refs $dir/objects/info/packs; echo) >>/tmp/update-server-info-fallback.log done