stagit-scripts

Static git repository setup scripts
git clone https://www.brianlane.com/git/stagit-scripts
Log | Files | Refs | README

post-receive (1873B)


      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 # 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 script.
     10 
     11 # NOTE: needs to be set for correct locale (expects UTF-8) otherwise the
     12 #       default is LC_CTYPE="POSIX".
     13 set -e
     14 export LC_CTYPE="en_US.UTF-8"
     15 
     16 name="$1"
     17 if test "${name}" = ""; then
     18 	name=$(basename "$(pwd)")
     19 fi
     20 
     21 # config
     22 # paths must be absolute.
     23 BASEURL="https://www.yourhost.com/git"
     24 RSYNC_DEST="yourhost.com:public_html/git/"
     25 reposdir="$HOME/stagit-repos"
     26 
     27 dir="${reposdir}/${name}"
     28 htmldir="${reposdir}"
     29 stagitdir="/"
     30 destdir="${htmldir}${stagitdir}"
     31 cachefile=".htmlcache"
     32 # /config
     33 
     34 if ! test -d "${dir}"; then
     35 	echo "${dir} does not exist" >&2
     36 	exit 1
     37 fi
     38 cd "${dir}" || exit 1
     39 
     40 # detect git push -f
     41 force=0
     42 while read -r old new ref; do
     43 	test "${old}" = "0000000000000000000000000000000000000000" && continue
     44 	test "${new}" = "0000000000000000000000000000000000000000" && continue
     45 
     46 	hasrevs=$(git rev-list "${old}" "^${new}" | sed 1q)
     47 	if test -n "${hasrevs}"; then
     48 		force=1
     49 		break
     50 	fi
     51 done
     52 
     53 printf "[%s] stagit HTML pages... " "${name}"
     54 
     55 mkdir -p "${destdir}/${name}"
     56 cd "${destdir}/${name}" || exit 1
     57 
     58 # remove commits and ${cachefile} on git push -f, this recreated later on.
     59 if test "${force}" = "1"; then
     60 	rm -f "${cachefile}"
     61 	rm -rf "commit"
     62 fi
     63 
     64 # make index.
     65 stagit-index "${reposdir}/"*/ > "${destdir}/index.html" || exit 1
     66 
     67 # Create the URL for clone
     68 echo "${BASEURL}/${name}" > url
     69 git update-server-info
     70 
     71 # make pages.
     72 stagit -c "${cachefile}" "${reposdir}/${name}" || exit 2
     73 
     74 ln -sf log.html index.html
     75 ln -sf ../style.css style.css
     76 ln -sf ../logo.png logo.png
     77 
     78 # Update the server
     79 rsync -a "${destdir}/" "${RSYNC_DEST}"
     80 
     81 echo "done"