stagit

static git repository generator
Log | Files | Refs | README | LICENSE

example.sh (1687B)


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
#!/bin/sh
# - Makes index for repositories in a single directory.
# - Makes static pages for each repository directory.
#
# NOTE, things to do manually (once):
# - copy style.css, logo.png and favicon.png manually, a style.css example
#   is included.
# - write clone url, for example "git://git.codemadness.org/dir" to the "url"
#   file for each repo.
#
# Usage:
# - mkdir -p htmldir && cd htmldir
# - sh example.sh

reposdir="/var/www/domains/git.codemadness.nl/home/src"
curdir=$(pwd)

# make index.
cd "${reposdir}"
find . -maxdepth 1 -type d | grep -v "^.$" | sort | xargs stagit-index |
        sed 's@<td>Last commit</td>@<td><a href="index-time.html">Last commit</a></td>@g' | \
        sed 's@<td>Name</td>@<td><a href="index.html">Name</a></td>@g' > "${curdir}/index.html"

# make index (sort by last commit author time).
find . -maxdepth 1 -type d | grep -v "^.$" | while read -r dir; do
	d=$(basename "${dir}")
	cd "${reposdir}/${d}"
	timestamp=$(git show -s --pretty="format:%at" || true)

	printf "%d %s\n" "${timestamp}" "${d}"
done | sort -n -k 1 | cut -f 2- -d ' ' | xargs stagit-index | \
	sed 's@<td>Last commit</td>@<td><a href="index-time.html">Last commit</a></td>@g' | \
	sed 's@<td>Name</td>@<td><a href="index.html">Name</a></td>@g' > "${curdir}/index-time.html"

# make files per repo.
cd "${reposdir}"
find . -maxdepth 1 -type d | grep -v "^.$" | sort | while read -r dir; do
	d=$(basename "${dir}")
	printf "%s..." "${d}"

	mkdir -p "${curdir}/${d}"
	cd "${curdir}/${d}"
	stagit "${reposdir}/${d}"

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

	printf " done\n"
done