stagit-hook (1449B)
1 #!/bin/sh 2 3 set -e 4 5 err() { 6 echo "$@" 1>&2 7 exit 1 8 } 9 10 # This should be more flexible, but it works for now. 11 hooked() ( 12 cd "$repodir" 13 ls -d */"$hasfile" | awk -F/ '{print $1}' | 14 while read dir 15 do 16 git --git-dir "$dir" show -s --format="%ct $dir" || 17 err "$dir: Unable to get repo information" 18 done | sort -rn | cut -f2- | sed "i\\ 19 ${repodir%/}/" 20 ) 21 22 index() ( 23 IFS=' 24 ' 25 stagit-index $(hooked) > "$basedir"/index.html 26 ) 27 28 repo() { 29 abs="$(readlink -f "$1")" 30 nam="$(basename "$abs")" 31 dir="$basedir"/"$nam" 32 mkdir -p "$dir" 33 cd "$dir" 34 stagit -u "$baseurl" "$abs" 35 } 36 37 loadconfig() { 38 if test -f "$rc" 39 then 40 while read key val 41 do 42 case $key in 43 (basedir) basedir="$val" ;; 44 (baseurl) baseurl="$val" ;; 45 (repodir) repodir="$val" ;; 46 (hasfile) hasfile="$val" ;; 47 (*) err 'Invalid configuration' 48 esac 49 done < "$rc" 50 fi 51 } 52 53 rc=/etc/stagit-hook 54 host="$(hostname)" 55 basedir=/var/www/htdocs/"$host"/projects/ 56 baseurl=https://"$host"/projects/ 57 repodir="$HOME" 58 hasfile=refs 59 60 loadconfig 61 62 err="$(mktemp -t stagit-hook-errXXXXXX)" 63 trap 'rm -f "$err"' EXIT 64 # Can't use "${@:-"$GIT_DIR"}" because empty GIT_DIR runs 65 # with empty string instead of just indexing like it should 66 test $# -eq 0 -a -n "$GIT_DIR" && 67 set -- "$GIT_DIR" 68 unset GIT_DIR 69 for d in "$@" 70 do 71 repo "$d" || { 72 status=$? 73 echo "$d: Unable to generate" 1>&2 74 } 75 done 76 index 77 { 78 exit $status 79 } > "$err" 2>&1 || { 80 logger -st stagit-hook -p error < "$err" 81 exit 1 82 }