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