#!/bin/sh repo="$PWD" name="$(basename $repo .git)" basedir="/var/www/htdocs/git.tronto.net" htdir="$basedir/$name" filesdir="/home/git/FILES" setupinfo() { echo "Sebastiano Tronto" > owner echo "https://git.tronto.net/$name" > url } genstagit() { rm -rf "$htdir" mkdir -p "$basedir" cp -r "$repo" "$htdir" cd "$htdir" && \ git update-server-info && \ git archive HEAD --prefix="$name/" -o "$basedir/$name.zip" stagit -l 100 "$repo" 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() { printf '%s\n' \ g/class=\"line\"/d \ "/
" d d i "$(lowdown file/README.md)" . w \
	| ed -s file/README.md.html > /dev/null
}

adddownloadbutton() {
	printf '%s\n' \
		"/log\.html\">Log<\/a>" i \
		"Download |" . 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' \
		"/Repositories" c \
		"

Repositories

" . 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 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 } mkpage mkindex