stagit-gopher

static git page generator for gopher
git clone git://git.2f30.org/stagit-gopher.git
Log | Files | Refs | README | LICENSE

commit 8dde93c6f9887d8a69ce60d528970848c01abb3d
parent 4a1c5be06d3e0a487cc43e910093ab690dd33114
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sat, 15 Jul 2017 12:58:10 +0200

improve example, add initial post-receive example

Diffstat:
example.sh | 37-------------------------------------
example_create.sh | 38++++++++++++++++++++++++++++++++++++++
example_post-receive.sh | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 104 insertions(+), 37 deletions(-)

diff --git a/example.sh b/example.sh @@ -1,37 +0,0 @@ -#!/bin/sh -# - Makes index for repositories in a single directory. -# - Makes static pages for each repository directory. -# -# NOTE, things to do manually (once): -# - write clone url, for example "git://git.codemadness.org/dir" to the "url" -# file for each repo. -# -# Usage: -# - mkdir -p gphdir && cd gphdir -# - sh example.sh - -# path must be absolute. -reposdir="/var/scm/git" -gopherdir="/var/gopher" -stagitdir="/scm" -destdir="${gopherdir}/${stagitdir}" - -# make index. -stagit-gopher-index -b "${stagitdir}" "${reposdir}/"*/ > "${destdir}/index.gph" - -# make files per repo. -for dir in "${reposdir}/"*/; do - # strip .git suffix. - r=$(basename "${dir}") - d=$(basename "${dir}" ".git") - printf "%s... " "${d}" - - mkdir -p "${destdir}/${d}" - cd "${destdir}/${d}" - stagit-gopher -b "${stagitdir}/${d}" -c ".cache" "${reposdir}/${r}" - - # symlinks - ln -sf log.gph index.gph - - printf "done\n" -done diff --git a/example_create.sh b/example_create.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# - Makes index for repositories in a single directory. +# - Makes static pages for each repository directory. +# +# NOTE, things to do manually (once) before running this script: +# - write clone url, for example "git://git.codemadness.org/dir" to the "url" +# file for each repo. +# - write description in "description" file. +# +# Usage: +# - mkdir -p gphdir && cd gphdir +# - sh example.sh + +# path must be absolute. +reposdir="/var/scm/git" +gopherdir="/var/gopher" +stagitdir="/scm" +destdir="${gopherdir}/${stagitdir}" + +# make index. +stagit-gopher-index -b "${stagitdir}" "${reposdir}/"*/ > "${destdir}/index.gph" + +# make files per repo. +for dir in "${reposdir}/"*/; do + # strip .git suffix. + r=$(basename "${dir}") + d=$(basename "${dir}" ".git") + printf "%s... " "${d}" + + mkdir -p "${destdir}/${d}" + cd "${destdir}/${d}" + stagit-gopher -b "${stagitdir}/${d}" -c ".cache" "${reposdir}/${r}" + + # symlinks + ln -sf log.gph index.gph + + printf "done\n" +done diff --git a/example_post-receive.sh b/example_post-receive.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# generic git post-receive hook. +# change the config options below and call this script in your post-receive +# hook or symlink it. +# +# usage: $0 [name] +# +# if name is not set the basename of the current directory is used, +# this is the directory of the repo when called from the post-receive script. + +name="$1" +if test "$name" = ""; then + name="$(basename $(pwd))" +fi + +# config +# paths must be absolute. +reposdir="/home/src/src" +dir="${reposdir}/${name}" +gopherdir="/home/www/gopher" +stagitdir="/" +destdir="${gopherdir}/${stagitdir}" +cachefile=".gphcache" +# /config + +if ! test -d "$dir"; then + echo "$dir does not exist" >&2 + exit 1 +fi +cd "$dir" || exit 1 + +# detect git push -f +force=0 +while read -r old new ref; do + hasrevs=$(git rev-list "$old" "^$new" | sed 1q) + if test -n "$hasrevs"; then + force=1 + break + fi +done + +# strip .git suffix. +r=$(basename "${name}") +d=$(basename "${name}" ".git") +printf "[%s] stagit .gph pages... " "${d}" + +mkdir -p "${destdir}/${d}" +cd "${destdir}/${d}" || exit 1 + +# remove commits and $cachefile on git push -f, this recreated later on. +if test "$force" = "1"; then + rm -f "${cachefile}" + rm -rf "commit" +fi + +# make index. +stagit-gopher-index -b "${stagitdir}" "${reposdir}/"*/ > "${destdir}/index.gph" + +# remove /'s at the end. +stagitdir=$(printf '%s' "${stagitdir}" | sed 's@[/]*$@@g') +# make pages. +stagit-gopher -b "${stagitdir}/${d}" -c "${cachefile}" "${reposdir}/${r}" + +ln -sf log.gph index.gph + +printf "done\n"