summaryrefslogtreecommitdiff
path: root/example_post-receive.sh
blob: 02c6f71a1616acea0b852274e38c743768e914c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
# Git post-rreceive hook to update stagit when there is a git commit.
# This will work on all of your git repos.
#
# Add this file to your git repo
# /srv/git/<repo name>.git/hooks/post-receive
#
# Make sure the Git user has access to your website files so the hook will work!
#
# 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.

# 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"

name="$1"
if test "${name}" = ""; then
    name=$(basename "$(pwd)")
fi

# config
# paths must be absolute.

# Reposdir is the directory your git repos are located
reposdir="/srv/git"
dir="${reposdir}/${name}"
# htmldir is where your stagit static site is located
htmldir="/var/www/git/htmldir"
stagitdir="/"
destdir="${htmldir}${stagitdir}"
cachefile=".htmlcache"
# /config

if ! test -d "${dir}"; then
    echo "${dir} does not exist" >&2
    exit 1
fi
cd "${dir}" || exit 1

# detect git push -f
force=0
while read -r old new ref; do
    test "${old}" = "0000000000000000000000000000000000000000" && continue
    test "${new}" = "0000000000000000000000000000000000000000" && continue

    hasrevs=$(git rev-list "${old}" "^${new}" | sed 1q)
    if test -n "${hasrevs}"; then
        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

# remove commits and ${cachefile} on git push -f, this recreated later on.
if test "${force}" = "1"; then
    rm -f "${cachefile}"
    rm -rf "commit"
fi

# make index.
stagit-index "${reposdir}/"*/ > "${destdir}/index.html"

# make pages.
# Replace with your domain name please
stagit -c "${cachefile}" -u "https://yourwebsite.com/$d/" "${reposdir}/${r}"

ln -sf log.html index.html
ln -sf ../style.css style.css
ln -sf ../logo.png logo.png

echo "done"