| tpost-receive.sh - stagit - [fork] customized build of stagit, the static git p… | |
| git clone git://src.adamsgaard.dk/stagit | |
| Log | |
| Files | |
| Refs | |
| README | |
| LICENSE | |
| --- | |
| tpost-receive.sh (2720B) | |
| --- | |
| 1 #!/bin/sh | |
| 2 # generic git post-receive hook. | |
| 3 # change the config options below and call this script in your post-rece… | |
| 4 # hook or symlink it. | |
| 5 # | |
| 6 # usage: $0 [name] | |
| 7 # | |
| 8 # if name is not set the basename of the current directory is used, | |
| 9 # this is the directory of the repo when called from the post-receive sc… | |
| 10 | |
| 11 # NOTE: needs to be set for correct locale (expects UTF-8) otherwise the | |
| 12 # default is LC_CTYPE="POSIX". | |
| 13 export LC_CTYPE="en_US.UTF-8" | |
| 14 | |
| 15 name="$1" | |
| 16 if test "${name}" = ""; then | |
| 17 name=$(basename "$(pwd)") | |
| 18 fi | |
| 19 | |
| 20 # config | |
| 21 # paths must be absolute. | |
| 22 reposdir="/home/git" | |
| 23 dir="${reposdir}/${name}" | |
| 24 htmldir="/var/www/domains/src.adamsgaard.dk" | |
| 25 gopherdir="/var/gopher" | |
| 26 stagitdir="/" | |
| 27 destdir="${htmldir}${stagitdir}" | |
| 28 gopherstagitdir="/src" | |
| 29 gopherdestdir="${gopherdir}${gopherstagitdir}" | |
| 30 cachefile=".htmlcache" | |
| 31 # /config | |
| 32 | |
| 33 if ! test -d "${dir}"; then | |
| 34 echo "${dir} does not exist" >&2 | |
| 35 exit 1 | |
| 36 fi | |
| 37 cd "${dir}" || exit 1 | |
| 38 | |
| 39 # detect git push -f | |
| 40 force=0 | |
| 41 while read -r old new ref; do | |
| 42 test "${old}" = "0000000000000000000000000000000000000000" && co… | |
| 43 test "${new}" = "0000000000000000000000000000000000000000" && co… | |
| 44 | |
| 45 hasrevs=$(git rev-list "${old}" "^${new}" | sed 1q) | |
| 46 if test -n "${hasrevs}"; then | |
| 47 force=1 | |
| 48 break | |
| 49 fi | |
| 50 done | |
| 51 | |
| 52 # strip .git suffix. | |
| 53 r=$(basename "${name}") | |
| 54 d=$(basename "${name}" ".git") | |
| 55 | |
| 56 ## HTML | |
| 57 printf "[%s] stagit HTML pages... " "${d}" | |
| 58 | |
| 59 mkdir -p "${destdir}/${d}" | |
| 60 cd "${destdir}/${d}" || exit 1 | |
| 61 | |
| 62 # remove commits and ${cachefile} on git push -f, this recreated later o… | |
| 63 if test "${force}" = "1"; then | |
| 64 rm -f "${cachefile}" | |
| 65 rm -rf "commit" | |
| 66 fi | |
| 67 | |
| 68 # make index. | |
| 69 stagit-index "${reposdir}/"*/ > "${destdir}/index.html" | |
| 70 | |
| 71 # make pages. | |
| 72 stagit -c "${cachefile}" "${reposdir}/${r}" | |
| 73 | |
| 74 # update bare repo for static http clone through alturl | |
| 75 (cd "${htmldir}" && cd "${r}.git" && \ | |
| 76 git fetch origin +refs/heads/*:refs/heads/* --prune && git updat… | |
| 77 | |
| 78 # disallow access to file and commit contents in parent robots.txt | |
| 79 if ! grep -q "Disallow: /${r}/" "${destdir}/robots.txt"; then | |
| 80 printf "Disallow: /%s/file/\nDisallow: /%s/commit/\n" \ | |
| 81 "$r" "$r" >> "${destdir}/robots.txt" | |
| 82 fi | |
| 83 | |
| 84 ln -sf log.html index.html | |
| 85 ln -sf ../style.css style.css | |
| 86 ln -sf ../logo.png logo.png | |
| 87 | |
| 88 echo "done" | |
| 89 | |
| 90 ## GPH | |
| 91 printf "[%s] stagit gopher pages... " "${d}" | |
| 92 | |
| 93 mkdir -p "${gopherdestdir}/${d}" | |
| 94 cd "${gopherdestdir}/${d}" || exit 1 | |
| 95 | |
| 96 # remove commits and ${cachefile} on git push -f, this recreated later o… | |
| 97 if test "${force}" = "1"; then | |
| 98 rm -f "${cachefile}" | |
| 99 rm -rf "commit" | |
| 100 fi | |
| 101 | |
| 102 # make index. | |
| 103 stagit-gopher-index -b "${gopherstagitdir}" "${reposdir}/"*/ > "${gopher… | |
| 104 | |
| 105 # make pages. | |
| 106 stagit-gopher -b "${gopherstagitdir}/${d}" -c "${cachefile}" "${reposdir… | |
| 107 | |
| 108 ln -sf log.gph index.gph | |
| 109 | |
| 110 echo "done" |