#!/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 # 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 # 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 | head -n $CHUNK); do # echo $dir; ls -l $dir/info/refs (cd $dir; git update-server-info || echo "Error while processing $dir") # ls -l $dir/info/refs; echo done