stagit

improve example, add initial post-receive example

Hiltjo Posthuma contact@arjunchoudhary.com

commit: bebce68 parent: d3218c8
2 files changed, 69 insertions(+), 1 deletions(-)
Mexample.sh+4-1
Aexample_post-receive.sh+65-0
M · example.sh +4, -1
 1@@ -2,11 +2,14 @@
 2 # - Makes index for repositories in a single directory.
 3 # - Makes static pages for each repository directory.
 4 #
 5-# NOTE, things to do manually (once):
 6+# NOTE, things to do manually (once) before running this script:
 7 # - copy style.css, logo.png and favicon.png manually, a style.css example
 8 #   is included.
 9+#
10 # - write clone url, for example "git://git.codemadness.org/dir" to the "url"
11 #   file for each repo.
12+# - write owner of repo to the "owner" file.
13+# - write description in "description" file.
14 #
15 # Usage:
16 # - mkdir -p htmldir && cd htmldir
A · example_post-receive.sh +65, -0
 1@@ -0,0 +1,65 @@
 2+#!/bin/sh
 3+# generic git post-receive hook.
 4+# change the config options below and call this script in your post-receive
 5+# hook or symlink it.
 6+#
 7+# usage: $0 [name]
 8+#
 9+# if name is not set the basename of the current directory is used,
10+# this is the directory of the repo when called from the post-receive script.
11+
12+name="$1"
13+if test "$name" = ""; then
14+	name="$(basename $(pwd))"
15+fi
16+
17+# config
18+# paths must be absolute.
19+reposdir="/home/src/src"
20+dir="${reposdir}/${name}"
21+htmldir="/home/www/domains/git.codemadness.org/htdocs"
22+stagitdir="/"
23+destdir="${htmldir}${stagitdir}"
24+cachefile=".htmlcache"
25+# /config
26+
27+if ! test -d "$dir"; then
28+	echo "$dir does not exist" >&2
29+	exit 1
30+fi
31+cd "$dir" || exit 1
32+
33+# detect git push -f
34+force=0
35+while read -r old new ref; do
36+	hasrevs=$(git rev-list "$old" "^$new" | sed 1q)
37+	if test -n "$hasrevs"; then
38+		force=1
39+		break
40+	fi
41+done
42+
43+# strip .git suffix.
44+r=$(basename "${name}")
45+d=$(basename "${name}" ".git")
46+printf "[%s] stagit HTML pages... " "${d}"
47+
48+mkdir -p "${destdir}/${d}"
49+cd "${destdir}/${d}" || exit 1
50+
51+# remove commits and $cachefile on git push -f, this recreated later on.
52+if test "$force" = "1"; then
53+	rm -f "${cachefile}"
54+	rm -rf "commit"
55+fi
56+
57+# make index.
58+stagit-index "${reposdir}/"*/ > "${destdir}/index.html"
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+printf "done\n"