config

System config files for garbash.com
git clone git://git.garbash.com/alex/config
Log | Files | Refs | README | LICENSE

commit 81d7f520727b946337624d79079528e6585ec91d
parent b26f233b649b601d9467cadaf969d9c272801190
Author: alex <alex@garbash.com>
Date:   Fri, 24 Sep 2021 22:16:28 -0400

git: Replace cgit with modified stagit config

cgit with httpd was quite a pain due to the chroot(8) making it hard
to access any needed binaries (cat, etc)

This patch adds a post-receive script for our multi-user stagit setup
as well as a newrepo script that I rolled to make adding repos easier.

Notes incoming!

Diffstat:
MMakefile | 3++-
Metc/httpd.conf | 10+---------
Ausr/local/bin/newrepo | 27+++++++++++++++++++++++++++
Avar/git/stagit-post-receive | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dvar/www/conf/cgitrc | 14--------------
5 files changed, 106 insertions(+), 24 deletions(-)

diff --git a/Makefile b/Makefile @@ -2,7 +2,8 @@ FILES = /etc/httpd.conf \ /etc/acme-client.conf \ /etc/mail/smtpd.conf \ - /var/www/conf/cgitrc + /var/git/stagit-post-receive \ + /usr/local/bin/newrepo .PHONY: pull pull: diff --git a/etc/httpd.conf b/etc/httpd.conf @@ -26,6 +26,7 @@ server "garbash.com" { server "git.garbash.com" { listen on * tls port 443 + root "/git" tls { certificate "/etc/ssl/garbash.com.fullchain.pem" key "/etc/ssl/private/garbash.com.key" @@ -34,13 +35,4 @@ server "git.garbash.com" { root "/acme" request strip 2 } - - # don't serve static files from cgit CGI: cgit.css and cgit.png - location "/cgit.*" { - root "/cgit" - no fastcgi - } - - root "/cgi-bin/cgit.cgi" - fastcgi socket "/run/slowcgi.sock" } diff --git a/usr/local/bin/newrepo b/usr/local/bin/newrepo @@ -0,0 +1,27 @@ +#!/bin/sh +set -e +die() { + echo "$*" 1>&2 + exit 1 +} +[ -z "$1" ] && die "usage: newrepo NAME" + +[ ! -e "$HOME/git" ] && ln -sf "/var/git/$USER" "$HOME/git" + +NAME="$1" +REPO="$HOME/git/${NAME}.git" + +git init --bare "$REPO" +echo "$USER" > "${REPO}/owner" +echo "git://git.garbash.com/${USER}/${NAME}" > "$REPO/url" +touch "$REPO/git-daemon-export-ok" + +printf "description: " +read desc +echo "$desc" > "$REPO/description" + +cp /var/git/stagit-post-receive "$REPO/hooks/post-receive" + +echo "" +echo "Done! Clone with:" +echo " git clone ${USER}@git.garbash.com:git/${NAME}.git" diff --git a/var/git/stagit-post-receive b/var/git/stagit-post-receive @@ -0,0 +1,76 @@ +#!/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. + +# NOTE: needs to be set for correct locale (expects UTF-8) otherwise the +# default is LC_CTYPE="POSIX". +export LC_CTYPE="en_US.UTF-8" + +name="$1" +if test "${name}" = ""; then + name=$(basename "$(pwd)") +fi + +# config +# paths must be absolute. +reposdir="/var/git" +dir="${reposdir}/${USER}/${name}" +htmldir="/var/www/git" +stagitdir="/" +destdir="${htmldir}${stagitdir}" +cachefile=".htmlcache" +# /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 + test "${old}" = "0000000000000000000000000000000000000000" && continue + test "${new}" = "0000000000000000000000000000000000000000" && continue + + 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 HTML pages... " "${d}" + +mkdir -p "${destdir}/${USER}/${d}" +cd "${destdir}/${USER}/${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. +cd "${reposdir}" +stagit-index -r */*.git > "${destdir}/index.html" +cd "${destdir}/${USER}/${d}" || exit 1 + +# make pages. +stagit -c "${cachefile}" -u "https://git.garbash.com/${USER}/${d}/" \ + -r "https://git.garbash.com" "${dir}" + +ln -sf log.html index.html +ln -sf ../../style.css style.css +ln -sf ../../logo.png logo.png + +echo "done" diff --git a/var/www/conf/cgitrc b/var/www/conf/cgitrc @@ -1,14 +0,0 @@ -# NOTE: it's chrooted in /var/www! -scan-path=/git - -clone-prefix=git://git.garbash.com - -root-title=garbash.com git repositories -root-desc=create something worth rewriting - -readme=:README.md -readme=:README - -enable-index-links=1 -enable-index-owner=1 -enable-commit-graph=1