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="/var/www/git/"
23dir="${reposdir}/${name}"
24destdir="/var/www/git/"
25cachefile=".cache"
26# /config
27
28if ! test -d "${dir}"; then
29 echo "${dir} does not exist" >&2
30 exit 1
31fi
32cd "${dir}" || exit 1
33
34# detect git push -f
35force=0
36while read -r old new ref; do
37 test "${old}" = "0000000000000000000000000000000000000000" && continue
38 test "${new}" = "0000000000000000000000000000000000000000" && continue
39
40 hasrevs=$(git rev-list "${old}" "^${new}" | sed 1q)
41 if test -n "${hasrevs}"; then
42 force=1
43 break
44 fi
45done
46
47# strip .git suffix.
48r=$(basename "${name}")
49d=$(basename "${name}" ".git")
50printf "[%s] stagit HTML pages... " "${d}"
51
52mkdir -p "${destdir}/${d}"
53cd "${destdir}/${d}" || exit 1
54
55# remove commits and ${cachefile} on git push -f, this recreated later on.
56if test "${force}" = "1"; then
57 rm -f "${cachefile}"
58 rm -rf "commit"
59fi
60
61# make index.
62stagit-index "${reposdir}/"*/ > "${reposdir}/index.html"
63
64# make pages.
65stagit -c "${cachefile}" -u "https://git.arjun.lol/$d/" "${reposdir}/${r}"
66
67# symlinks
68ln -sf log.html index.html
69ln -sf ../style.css style.css
70ln -sf ../me.webp me.webp
71ln -sf ../favicon.png favicon.png
72
73echo "done"
74