stagit

Static git page generator
git clone https://git.sinitax.com/codemadness/stagit
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

example_post-receive.sh (1748B)


      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".
     13export LC_CTYPE="en_US.UTF-8"
     14
     15name="$1"
     16if test "${name}" = ""; then
     17	name=$(basename "$(pwd)")
     18fi
     19
     20# config
     21# paths must be absolute.
     22reposdir="/home/src/src"
     23dir="${reposdir}/${name}"
     24htmldir="/home/www/domains/git.codemadness.org/htdocs"
     25stagitdir="/"
     26destdir="${htmldir}${stagitdir}"
     27cachefile=".htmlcache"
     28# /config
     29
     30if ! test -d "${dir}"; then
     31	echo "${dir} does not exist" >&2
     32	exit 1
     33fi
     34cd "${dir}" || exit 1
     35
     36# detect git push -f
     37force=0
     38while read -r old new ref; do
     39	test "${old}" = "0000000000000000000000000000000000000000" && continue
     40	test "${new}" = "0000000000000000000000000000000000000000" && continue
     41
     42	hasrevs=$(git rev-list "${old}" "^${new}" | sed 1q)
     43	if test -n "${hasrevs}"; then
     44		force=1
     45		break
     46	fi
     47done
     48
     49# strip .git suffix.
     50r=$(basename "${name}")
     51d=$(basename "${name}" ".git")
     52printf "[%s] stagit HTML pages... " "${d}"
     53
     54mkdir -p "${destdir}/${d}"
     55cd "${destdir}/${d}" || exit 1
     56
     57# remove commits and ${cachefile} on git push -f, this recreated later on.
     58if test "${force}" = "1"; then
     59	rm -f "${cachefile}"
     60	rm -rf "commit"
     61fi
     62
     63# make index.
     64stagit-index "${reposdir}/"*/ > "${destdir}/index.html"
     65
     66# make pages.
     67stagit -c "${cachefile}" -u "https://git.codemadness.nl/$d/" "${reposdir}/${r}"
     68
     69ln -sf log.html index.html
     70ln -sf ../style.css style.css
     71ln -sf ../logo.png logo.png
     72
     73echo "done"