example_post-receive.sh (2544B) - raw
1 #!/bin/sh 2 # generic git post-receive hook. 3 # change the config options below and call this script in your post-receive 4 # hook or symlink it. 5 # 6 # NOTE, things to do manually (once) before running this script: 7 # - modify the categories in the for loop with your own. 8 # 9 # usage: $0 [name] 10 # 11 # if name is not set the basename of the current directory is used, 12 # this is the directory of the repo when called from the post-receive script. 13 14 # NOTE: needs to be set for correct locale (expects UTF-8) otherwise the 15 # default is LC_CTYPE="POSIX". 16 export LC_CTYPE="en_US.UTF-8" 17 18 name="$1" 19 if test "${name}" = ""; then 20 name="$(basename "$(pwd)")" 21 fi 22 23 # paths must be absolute 24 reposdir="/srv/git" 25 dir="${reposdir}/${name}" 26 destdir="/srv/git/html" 27 cachefile=".stagit-build-cache" 28 29 if ! test -d "${dir}"; then 30 echo "${dir} does not exist" >&2 31 exit 1 32 fi 33 cd "${dir}" || exit 1 34 35 [ -f "${dir}/git-daemon-export-ok" ] || exit 0 36 37 # detect git push -f 38 force=0 39 while read -r old new ref; do 40 test "${old}" = "0000000000000000000000000000000000000000" && continue 41 test "${new}" = "0000000000000000000000000000000000000000" && continue 42 43 hasrevs="$(git rev-list "${old}" "^${new}" | sed 1q)" 44 if test -n "${hasrevs}"; then 45 force="1" 46 break 47 fi 48 done 49 50 # strip .git suffix 51 r="$(basename "${name}")" 52 d="$(basename "${name}" ".git")" 53 printf "[%s] stagit HTML pages... " "${d}" 54 55 # remove folder if forced update 56 [ "${force}" = "1" ] && printf "forced update... " && rm -rf "${destdir}/${d}" 57 58 mkdir -p "${destdir}/${d}" 59 cd "${destdir}/${d}" || exit 1 60 61 # make pages 62 stagit -c "${cachefile}" -u "https://git.oscarbenedito.com/$d/" "${reposdir}/${r}" 63 [ -f "about.html" ] \ 64 && ln -sf "about.html" "index.html" \ 65 || ln -sf "log.html" "index.html" 66 ln -sfT "${dir}" ".git" 67 68 # generate index arguments 69 args="" 70 for cat in "Projects" "Personal setup" "Miscellanea"; do 71 args="$args -c \"$cat\"" 72 for dir in "$reposdir/"*.git/; do 73 dir="${dir%/}" 74 [ ! -f "$dir/git-daemon-export-ok" ] && continue 75 if [ -f "$dir/category" ]; then 76 [ "$(cat "$dir/category")" = "$cat" ] && args="$args $dir" 77 else 78 stagit_uncat="1" 79 fi 80 done 81 done 82 83 if [ -n "$stagit_uncat" ]; then 84 args="$args -c Uncategorized" 85 for dir in "$reposdir/"*.git/; do 86 dir="${dir%/}" 87 [ -f "$dir/git-daemon-export-ok" ] && [ ! -f "$dir/category" ] && \ 88 args="$args $dir" 89 done 90 fi 91 92 # make index 93 echo "$args" | xargs stagit-index > "${destdir}/index.html" 94 95 echo "done"