post-receive-stagit (2103B)
1 #!/bin/sh 2 3 yourname="Sebastiano Tronto" 4 repo="$PWD" 5 name="$(basename $repo .git)" 6 baseurl="https://git.tronto.net" 7 basedir="/var/www/htdocs/git.tronto.net" 8 htdir="$basedir/$name" 9 filesdir="/home/git/FILES" 10 bindir="/home/git/BIN" 11 12 setupinfo() { 13 echo "$yourname" > owner 14 echo "$baseurl/$name" > url 15 git update-server-info 16 } 17 18 genstagit() { 19 rm -rf "$htdir" 20 mkdir -p "$basedir" 21 cp -r "$repo" "$htdir" 22 cd "$htdir" 23 stagit -l 100 "$repo" 24 git archive HEAD -o "$basedir/$name.zip" 25 git show master:README.md > file/README.md 26 } 27 28 cpindexfile() { 29 cp "$htdir/files.html" "$htdir/index.html" 30 } 31 32 cpstylefiles() { 33 cp $filesdir/favicon.png "$1" 34 cp $filesdir/logo.png "$1" 35 cp $filesdir/style.css "$1" 36 } 37 38 formatreadme() { 39 cd "$htdir" 40 printf '%s\n' \ 41 g/class=\"line\"/d \ 42 "/<pre id=\"blob\">" d d i "$(lowdown file/README.md)" . w \ 43 | ed -s file/README.md.html > /dev/null 44 } 45 46 adddownloadbutton() { 47 cd "$htdir" 48 printf '%s\n' \ 49 "/log\.html\">Log<\/a>" i \ 50 "<a href=\"$baseurl/$name.zip\">Download</a> |" . w \ 51 | ed -s "$1" > /dev/null 52 } 53 54 addbottombar() { 55 printf '%s\n' \ 56 "/<\/body>" i "$(cat $filesdir/bottom.html)" . w \ 57 | ed -s "$1" > /dev/null 58 } 59 60 changeindextitlestyle() { 61 printf '%s\n' \ 62 "/<td><span class=\"desc\">Repositories" c \ 63 "<td><h1>Repositories</h1></td></tr><tr><td></td><td>" . w \ 64 | ed -s "$basedir/index.html" > /dev/null 65 } 66 67 genstagitindex() { 68 stagit-index /home/git/*.git | \ 69 sed 's|/log\.html||g' > "$basedir/index.html" 70 } 71 72 mkpage() { 73 echo "Updating stagit page for $name" 74 setupinfo 75 genstagit 76 cpindexfile 77 cpstylefiles "./" 78 [ -e $htdir/file/README.md ] && formatreadme 79 for f in $(find "$htdir" -name "*.html"); do 80 adddownloadbutton $f 81 addbottombar $f 82 done 83 mkindex 84 } 85 86 mkindex() { 87 echo "Updating stagit index page" 88 genstagitindex 89 cpstylefiles "$basedir/" 90 addbottombar "$basedir/index.html" 91 changeindextitlestyle 92 } 93 94 if [ "$1" = "all" ]; then 95 for g in *.git; do 96 cd $g 97 cp $bindir/post-receive-stagit hooks/post-receive 98 chmod +x hooks/post-receive 99 $bindir/post-receive-stagit 100 cd 101 done 102 elif [ "$1" = "index" ]; then 103 mkindex 104 else 105 mkpage 106 fi