aboutsummaryrefslogtreecommitdiff
path: root/post-receive-stagit
blob: 586a533e9c7293b730e3b07b05959429a085563b (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/sh

yourname="Sebastiano Tronto"
repo="$PWD"
name="$(basename $repo .git)"
baseurl="https://git.tronto.net"
basedir="/var/www/htdocs/git.tronto.net"
htdir="$basedir/$name"
filesdir="/home/git/FILES"
bindir="/home/git/BIN"

setupinfo() {
	echo "$yourname" > owner
	echo "$baseurl/$name" > url
	git update-server-info
}

genstagit() {
	rm -rf "$htdir"
	mkdir -p "$basedir"
	cp -r "$repo" "$htdir"
	cd "$htdir"
	stagit -l 100 "$repo"
	git archive HEAD -o "$basedir/$name.zip"
	git show master:README.md > file/README.md
}

cpindexfile() {
	cp "$htdir/files.html" "$htdir/index.html"
}

cpstylefiles() {
	cp $filesdir/favicon.png "$1"
	cp $filesdir/logo.png    "$1"
	cp $filesdir/style.css   "$1"
}

formatreadme() {
	cd "$htdir"
	printf '%s\n' \
		g/class=\"line\"/d \
		"/<pre id=\"blob\">" d d i "$(lowdown file/README.md)" . w \
	| ed -s file/README.md.html > /dev/null
}

adddownloadbutton() {
	cd "$htdir"
	printf '%s\n' \
		"/log\.html\">Log<\/a>" i \
		"<a href=\"$baseurl/$name.zip\">Download</a> |" . w \
	| ed -s "$1" > /dev/null
}

addbottombar() {
	printf '%s\n' \
		"/<\/body>" i "$(cat $filesdir/bottom.html)" . w \
	| ed -s "$1" > /dev/null
}

changeindextitlestyle() {
	printf '%s\n' \
		"/<td><span class=\"desc\">Repositories" c \
		"<td><h1>Repositories</h1></td></tr><tr><td></td><td>" . w \
	| ed -s "$basedir/index.html" > /dev/null
}

genstagitindex() {
	stagit-index /home/git/*.git | \
	sed 's|/log\.html||g' > "$basedir/index.html"
}

mkpage() {
	echo "Updating stagit page for $name"
	setupinfo
	genstagit
	cpindexfile
	cpstylefiles "./"
	[ -e $htdir/file/README.md ] && formatreadme
	for f in $(find "$htdir" -name "*.html"); do
		adddownloadbutton $f
		addbottombar $f
	done
}

mkindex() {
	echo "Updating stagit index page"
	genstagitindex
	cpstylefiles "$basedir/"
	addbottombar "$basedir/index.html"
	changeindextitlestyle
}

if [ "$1" = "all" ]; then
	for g in *.git; do
		cd $g
		cp $bindir/post-receive-stagit hooks/post-receive
		chmod +x hooks/post-receive
		$bindir/post-receive-stagit
		cd
	done
elif [ "$1" != "index" ]; then
	mkpage
fi
mkindex

Generated with cgit - Back to sebastiano.tronto.net