src.hhvn.uk > hhvn.uk-scripts > commit > 961d741871e79a131a4655023fb6f713cb83c265

scripts that power hhvn.uk
Log | Files | Refs | README

commit 961d741871e79a131a4655023fb6f713cb83c265
parent 413e5ce219527fe56c9976571a1ffc35743d35fc
Author: Hayden Hamilton <hayden@hhvn.uk>
Date:   Sat,  6 Jun 2026 18:25:06 +0100

stagit, go module handling, git hooks

Diffstat:
AREADME | 44++++++++++++++++++++++++++++++++++++++++++++
Arepo/hooks/post-receive | 4++++
Arepo/mkhooks | 21+++++++++++++++++++++
Arepo/mkrepo | 30++++++++++++++++++++++++++++++
Mtls/edit | 2++
Awww/generate/src/gomod | 35+++++++++++++++++++++++++++++++++++
Awww/generate/src/stagit | 18++++++++++++++++++
7 files changed, 154 insertions(+), 0 deletions(-)

diff --git a/README b/README @@ -0,0 +1,44 @@ +These are the scripts that power the server at hhvn.uk + +Make*.rc: + These scripts automatically populate/depopulate a bin/ directory, + essentially managing the existence of any scripts from this repo in $PATH + +dkim: + These scripts are resposible for Domain Key management. + - lscert: lists existing DKIM keypais + - mkcert: generates new DKIM keypairs + - rmcert: removes a DKIM keypair + - purge: automatically removes old DKIM keypairs + - reconfig-dns: adds a DKIM keypair to a DNS zone file + - reconfig-smtpd: reconfigures the smtpd.conf filters to use a DKIM keypair + - update: automatically calls other scripts to generate, purge, and reconfig + +dns/zone: + These scripts make DNS zone editing simpler + - edit: attempts to find a zone and calls $EDITOR + - reload: attempts to find, and reload a zone, but checking it over first + +tls: + These scripts make acme-client easier to access + - edit: calls $EDITOR on acme-client.conf + - run: guesses domain and runs acme-client + +www/chroot: + These scripts manage / exist in the /var/www chroot + - mkchroot: copies binaries + libraries to /var/www + - git-wrapper: wraps around git for CGI access + +www/generate/src: + These scripts generate content in /var/www/htdocs/src.hhvn.uk + - gomod: generates go.mod glue code + - stagit: calls stagit + +repo: + These scrips manage /var/git + - mkrepo: initializes a new repository and returns `git origin` commands + - mkhooks: intalls hooks into all repos in /var/git + +repo/hooks: + These scripts are installed by repo/mkhooks + - post-receive: calls www/generate/src/* diff --git a/repo/hooks/post-receive b/repo/hooks/post-receive @@ -0,0 +1,4 @@ +#!/bin/rc + +www/generate/src/stagit +www/generate/src/gomod diff --git a/repo/mkhooks b/repo/mkhooks @@ -0,0 +1,21 @@ +#!/bin/rc + +user = _git +gitdir = /var/git + +# just assume post-receive will always exists. I know. ugly +hookdir = `{dirname `{whatis repo/hooks/post-receive}} + +fn as { + doas -u $user $* +} + +for (repo in $gitdir/*) { + for (hook in $hookdir/*) { + dest = $repo/hooks/`{basename $hook} + + if (!test -e $dest) { + ln -s $hook $dest + } + } +} diff --git a/repo/mkrepo b/repo/mkrepo @@ -0,0 +1,30 @@ +#!/bin/rc + +user = _git +domain = `hostname +gitdir = /var/git + +fn as { + doas -u $user $* +} + +estatus = 0 + +for (repo in $*) { + rdir = $gitdir/$repo + + if (!test -e $rdir) { + as mkdir $rdir + cd $rdir + as git init --bare + + echo + echo git remote add origin $domain:$rdir + echo git push --set-upstream origin master + } else { + estatus = 1 + echo error: $rdir already exists >[1=2] + } +} + +exit $estatus diff --git a/tls/edit b/tls/edit @@ -1,3 +1,5 @@ #!/bin/rc doas $EDITOR /etc/acme-client.conf + +tls/run diff --git a/www/generate/src/gomod b/www/generate/src/gomod @@ -0,0 +1,35 @@ +#!/bin/rc + +domain = $1 +gitdir = /var/git +if (~ $domain ()) { + domain = `hostname +} +wwwdir = /var/www/htdocs/go.$domain + + +tmpdir = `{mktemp -d} +if (!cd $tmpdir) { + exit 1 +} + +fn sigexit { + rm -rf $tmpdir +} + +for (repo in $gitdir/*) { + name = `{basename $repo} + dest = $wwwdir/$name + + if (test -e go.mod) { + rm go.mod + } + + if (git archive --remote=$repo HEAD go.mod >[2]/dev/null | tar -xf - >[2]/dev/null) { + echo GEN $name + mkdir -p $dest + modname = `{head -1 go.mod | sed 's/^module //'} + printf '<!DOCTYPE html><html><head><meta name="go-import" content="%s git %s"></head></html>' \ + $modname https://src.$domain/$name > $dest/index.html + } +} diff --git a/www/generate/src/stagit b/www/generate/src/stagit @@ -0,0 +1,18 @@ +#!/bin/rc + +gitdir = /var/git +wwwdir = /var/www/htdocs/src.hhvn.uk + +stagit-index $gitdir/* > $wwwdir/index.html + +for (repo in $gitdir/*) { + base = `{basename $repo} + echo GEN $base + + mkdir -p $wwwdir/$base + cd $wwwdir/$base + stagit -c .cache -u 'https://src.hhvn.uk/'$base $repo + if (!test -e index.html) { + ln -s log.html index.html + } +}