2017-07-15 11:50:24 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# generic git post-receive hook.
|
|
|
|
# change the config options below and call this script in your post-receive
|
|
|
|
# hook or symlink it.
|
|
|
|
#
|
|
|
|
# usage: $0 [name]
|
|
|
|
#
|
|
|
|
# if name is not set the basename of the current directory is used,
|
|
|
|
# this is the directory of the repo when called from the post-receive script.
|
|
|
|
|
2017-10-31 22:20:18 +00:00
|
|
|
# NOTE: needs to be set for correct locale (expects UTF-8) otherwise the
|
|
|
|
# default is LC_CTYPE="POSIX".
|
|
|
|
export LC_CTYPE="en_US.UTF-8"
|
|
|
|
|
2017-07-15 11:50:24 +00:00
|
|
|
name="$1"
|
2017-07-30 15:21:42 +00:00
|
|
|
if test "${name}" = ""; then
|
|
|
|
name=$(basename $(pwd))
|
2017-07-15 11:50:24 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# config
|
|
|
|
# paths must be absolute.
|
|
|
|
reposdir="/home/src/src"
|
|
|
|
dir="${reposdir}/${name}"
|
|
|
|
htmldir="/home/www/domains/git.codemadness.org/htdocs"
|
|
|
|
stagitdir="/"
|
|
|
|
destdir="${htmldir}${stagitdir}"
|
|
|
|
cachefile=".htmlcache"
|
|
|
|
# /config
|
|
|
|
|
2017-07-30 15:21:42 +00:00
|
|
|
if ! test -d "${dir}"; then
|
|
|
|
echo "${dir} does not exist" >&2
|
2017-07-15 11:50:24 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2017-07-30 15:21:42 +00:00
|
|
|
cd "${dir}" || exit 1
|
2017-07-15 11:50:24 +00:00
|
|
|
|
|
|
|
# detect git push -f
|
|
|
|
force=0
|
|
|
|
while read -r old new ref; do
|
2017-08-09 16:52:53 +00:00
|
|
|
test "${old}" = "0000000000000000000000000000000000000000" && continue
|
2017-11-25 15:02:24 +00:00
|
|
|
test "${new}" = "0000000000000000000000000000000000000000" && continue
|
2017-08-09 16:52:53 +00:00
|
|
|
|
2017-07-30 15:21:42 +00:00
|
|
|
hasrevs=$(git rev-list "${old}" "^${new}" | sed 1q)
|
|
|
|
if test -n "${hasrevs}"; then
|
2017-07-15 11:50:24 +00:00
|
|
|
force=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# strip .git suffix.
|
|
|
|
r=$(basename "${name}")
|
|
|
|
d=$(basename "${name}" ".git")
|
|
|
|
printf "[%s] stagit HTML pages... " "${d}"
|
|
|
|
|
|
|
|
mkdir -p "${destdir}/${d}"
|
|
|
|
cd "${destdir}/${d}" || exit 1
|
|
|
|
|
2017-07-30 15:21:42 +00:00
|
|
|
# remove commits and ${cachefile} on git push -f, this recreated later on.
|
|
|
|
if test "${force}" = "1"; then
|
2017-07-15 11:50:24 +00:00
|
|
|
rm -f "${cachefile}"
|
|
|
|
rm -rf "commit"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# make index.
|
|
|
|
stagit-index "${reposdir}/"*/ > "${destdir}/index.html"
|
2017-07-30 15:21:42 +00:00
|
|
|
|
2017-07-15 11:50:24 +00:00
|
|
|
# make pages.
|
|
|
|
stagit -c "${cachefile}" "${reposdir}/${r}"
|
|
|
|
|
|
|
|
ln -sf log.html index.html
|
|
|
|
ln -sf ../style.css style.css
|
|
|
|
ln -sf ../logo.png logo.png
|
|
|
|
|
2017-07-30 15:21:42 +00:00
|
|
|
echo "done"
|