MoncoForge:

stagit-scripts

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

commit af4412559576a8dbfb3c18d5a29ba1c0cd09ec8d
Author: MoncoForge <git@moncoforge.com>
Date:   Fri, 13 Nov 2026 21:45:31 -0800

first commit

Diffstat:
AREADME.md | 18++++++++++++++++++
Acopy-hook | 9+++++++++
Anewrepo | 36++++++++++++++++++++++++++++++++++++
Apost-receive-stagit | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 179 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -0,0 +1,18 @@ +# MoncoForge Stagit Scripts! +A few helper scripts I use when sharing my git repositories here at MoncoForge. + +## Inspiration? +My scripts are a continuation of the work by [Sebastiano Tronto](https://stagit.tronto.net/git-hooks/) + -Updated "copy-hook" + -Updated "post-receive-stagit" + -Added "newrepo" + -Soon to add new css theme + -Soon to add new logo/icons + +## Required To Build Stagit And Use Scripts + -gcc + -make + -libgit2-1.9 + -libgit2-dev + -ed + -lowdown diff --git a/copy-hook b/copy-hook @@ -0,0 +1,9 @@ +#!/bin/sh + +pubrepodir="ENTER-YOUR-GIT-DIRECTORY" +bindir="ENTER-STAGIT-BIN-DIRECTORY" + +for d in "$pubrepodir"/*.git; do + cp "$bindir"/post-receive-stagit $d/hooks/ + chmod +x $d/hooks/post-receive-stagit +done diff --git a/newrepo b/newrepo @@ -0,0 +1,36 @@ +#!/bin/sh + +server="ENTER-YOUR-SSH-SERVER-INFO" +pubrepodir="ENTER-YOUR-GIT-DIRECTORY" +bindir="ENTER-STAGIT-BIN-DIRECTORY" +branch="ENTER-DEFAULT-BRANCH-NAME" + +hook="$bindir/post-receive-stagit" +[ -f "$hook" ] || { echo "Missing $hook" >&2; exit 1; } +cd "$pubrepodir" || { echo "Cannot cd to $pubrepodir" >&2; exit 1; } + +printf "Enter repository name (without .git): " +read -r reponame +reponame="${reponame%.git}" + +case "$reponame" in + ""|*[!A-Za-z0-9._-]*|.*) + echo "Use only letters, digits, . _ - (not starting with a dot)." >&2 + exit 1 ;; +esac + +repo="$pubrepodir/$reponame.git" +[ -e "$repo" ] && { echo "$reponame.git already exists." >&2; exit 1; } + +printf "Enter short description: " +read -r shrtdesc + +git init --bare -b "$branch" "$repo" || exit 1 +echo "$shrtdesc" > "$repo/description" +cp "$hook" "$repo/hooks/post-receive" +chmod +x "$repo/hooks/post-receive" + +echo +echo "Created $reponame.git. Stagit git hook installed; the website updates on first push." +echo "From your PC: git remote add origin ssh://$server$repo" +echo " git push -u origin $branch" diff --git a/post-receive-stagit b/post-receive-stagit @@ -0,0 +1,116 @@ +#!/bin/sh + +yourname="ENTER-REPO-OWNER-NAME" +repo="$PWD" +name="$(basename $repo .git)" +baseurl="ENTER-YOUR-WEBSITE-DOMAIN" +sitetitle="ENTER-YOUR-WEBSITE-NAME" +indextitle="ENTER-INDEX-PAGE-TITLE" +basedir="ENTER-YOUR-WEBSITE-DIRECTORY" +pubrepodir="ENTER-YOUR-GIT-DIRECTORY" +htdir="$basedir/$name" +filesdir="ENTER-STAGIT-FILES-DIRECTORY" +bindir="ENTER-STAGIT-BIN-DIRECTORY" + +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 50 "$repo" + git archive HEAD -o "$basedir/$name.zip" + git show HEAD:README.md > file/README.md +} + +cpindexfile() { + cp "$htdir/log.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 +} + +newsitetitle() { + printf '%s\n' \ + ",s|<title>Repositories</title>|<title>$sitetitle</title>|" w \ + | ed -s "$1" > /dev/null +} + +changeindextitlestyle() { + printf '%s\n' \ + "/<td><span class=\"desc\">Repositories" c \ + "<td><h1>$indextitle</h1></td></tr><tr><td></td><td>" . w \ + | ed -s "$basedir/index.html" > /dev/null +} + +genstagitindex() { + stagit-index "$pubrepodir"/*.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 +} + +mkindex() { + echo "Updating stagit index page" + genstagitindex + newsitetitle "$basedir/index.html" + cpstylefiles "$basedir/" + addbottombar "$basedir/index.html" + changeindextitlestyle +} + +if [ "$1" = "all" ]; then + for g in "$pubrepodir"/*.git; do + cd $g + cp $bindir/post-receive-stagit hooks/post-receive + chmod +x hooks/post-receive + $bindir/post-receive-stagit + cd $pubrepodir + done +elif [ "$1" = "index" ]; then + mkindex +else + mkpage +fi