MoncoForge:

stagit-scripts

scripts to aid in the management of stagit sites
git clone https://moncoforge.com/stagit-scripts
Download | Log | Files | Refs | README

post-receive-stagit (3122B)


      1 #!/bin/sh
      2 
      3 yourname="ENTER-REPO-OWNER-NAME"
      4 repo="$PWD"
      5 name="$(basename $repo .git)"
      6 baseurl="ENTER-YOUR-WEBSITE-DOMAIN"
      7 sitetitle="ENTER-YOUR-WEBSITE-NAME"
      8 indextitle="ENTER-INDEX-PAGE-TITLE"
      9 indextagline="ENTER-INDEX-PAGE-TAG-LINE"
     10 basedir="ENTER-YOUR-WEBSITE-DIRECTORY"
     11 pubrepodir="ENTER-YOUR-GIT-DIRECTORY"
     12 htdir="$basedir/$name"
     13 filesdir="ENTER-STAGIT-FILES-DIRECTORY"
     14 bindir="ENTER-STAGIT-BIN-DIRECTORY"
     15 
     16 setupinfo() {
     17 	echo "$yourname" > owner
     18 	echo "$baseurl/$name" > url
     19 	git update-server-info
     20 }
     21 
     22 genstagit() {
     23 	rm -rf "$htdir"
     24 	mkdir -p "$basedir"
     25 	cp -r "$repo" "$htdir"
     26 	cd "$htdir"
     27 	stagit -l 50 "$repo"
     28 	git archive HEAD -o "$basedir/$name.zip"
     29 	git show HEAD:README.md > file/README.md
     30 }
     31 
     32 cpindexfile() {
     33 	cp "$htdir/file/README.md.html" "$htdir/index.html"
     34 	printf '%s\n' \
     35 		'g/="\.\.\//s//="/g' \
     36 		w q \
     37 	| ed -s "$htdir/index.html" > /dev/null
     38 }
     39 # this just redirects nav readme to repo index, probably a waste of time.
     40 readmelink() {
     41 	printf '%s\n' \
     42 		"g/>README<\/a>/s|href=\"[^\"]*README\.md\.html\"|href=\"$baseurl/$name/\"|" \
     43 		w q \
     44 	| ed -s "$1" > /dev/null
     45 }
     46 
     47 cpstylefiles() {
     48 	cp $filesdir/favicon.png "$1"
     49 	cp $filesdir/logo.png    "$1"
     50 	cp $filesdir/style.css   "$1"
     51 	cp -r $filesdir/fonts    "$1"
     52 }
     53 
     54 formatreadme() {
     55 	cd "$htdir"
     56 	printf '%s\n' \
     57 		g/class=\"line\"/d \
     58 		"/<pre id=\"blob\">" d d i "$(lowdown file/README.md)" . w \
     59 	| ed -s file/README.md.html > /dev/null
     60 }
     61 
     62 adddownloadbutton() {
     63 	cd "$htdir"
     64 	printf '%s\n' \
     65 		"/log\.html\">Log<\/a>" i \
     66 		"<a href=\"$baseurl/$name.zip\">Download</a> |" . w \
     67 	| ed -s "$1" > /dev/null
     68 }
     69 
     70 addhomelink() {
     71 	cd "$htdir"
     72 	printf '%s\n' \
     73 		"/<h1>" \
     74 		"s|<h1>|<h1><a href=\"$baseurl\">$indextitle:</a><\/h1> <h1> |" . w \
     75 	| ed -s "$1" > /dev/null
     76 }
     77 
     78 addbottombar() {
     79 	printf '%s\n' \
     80 		"/<\/body>" i "$(cat $filesdir/bottom.html)" . w \
     81 	| ed -s "$1" > /dev/null
     82 }
     83 
     84 newsitetitle() {
     85 	printf '%s\n' \
     86 		",s|<title>Repositories</title>|<title>$sitetitle</title>|" w \
     87 	| ed -s "$1" > /dev/null
     88 }
     89 
     90 changeindextitlestyle() {
     91 	if [ -n "$indextagline" ]; then
     92 			tagline="<span class=\"desc\">$indextagline</span>"
     93 	fi
     94 	printf '%s\n' \
     95 		"/<td><span class=\"desc\">Repositories" c \
     96 		"<td><h1>$indextitle</h1>$tagline</td></tr><tr><td></td><td>" . w \
     97 	| ed -s "$basedir/index.html" > /dev/null
     98 }
     99 
    100 genstagitindex() {
    101 	stagit-index "$pubrepodir"/*.git | \
    102 	sed 's|/log\.html||g' > "$basedir/index.html"
    103 }
    104 
    105 mkpage() {
    106 	echo "Updating stagit page for $name"
    107 	setupinfo
    108 	genstagit
    109 	cpstylefiles "./"
    110 	[ -e $htdir/file/README.md ] && formatreadme
    111 	for f in $(find "$htdir" -name "*.html"); do
    112 		adddownloadbutton $f
    113 		addhomelink $f
    114 		readmelink $f
    115 		addbottombar $f
    116 	done
    117 	cpindexfile
    118 	mkindex
    119 }
    120 
    121 mkindex() {
    122 	echo "Updating stagit index page"
    123 	genstagitindex
    124 	newsitetitle "$basedir/index.html"
    125 	cpstylefiles "$basedir/"
    126 	addbottombar "$basedir/index.html"
    127 	changeindextitlestyle
    128 }
    129 
    130 if [ "$1" = "all" ]; then
    131 	for g in "$pubrepodir"/*.git; do
    132 		cd $g
    133 		cp $bindir/post-receive-stagit hooks/post-receive
    134 		chmod +x hooks/post-receive
    135 		$bindir/post-receive-stagit
    136 		cd $pubrepodir
    137 	done
    138 elif [ "$1" = "index" ]; then
    139 	mkindex
    140 else
    141 	mkpage
    142 fi