romanzolotarev.com: support and follow me on Mastodon and Twitter

Tested on OpenBSD 6.3 with stagit 187daa

Publish Git repositories with stagit(1) on OpenBSD

stagit(1) generates HTML files from your git repository. The source of this website, for example: /src/www.

Set up git and httpd.

Build stagit(1)

On OpenBSD we have to build stagit(1) from sources:

# pkg_add libgit2
quirks-2.414 signed on 2018-03-28T14:24:37Z
libgit2-0.26.3:libssh2-1.8.0: ok
libgit2-0.26.3: ok
# cd /tmp
# git clone git://git.codemadness.org/stagit
Cloning into 'stagit'...
remote: Counting objects: 946, done.
remote: Compressing objects: 100% (396/396), done.
remote: Total 946 (delta 620), reused 834 (delta 549)
Receiving objects: 100% (946/946), 164.47 KiB | 230.00 KiB/s, done.
Resolving deltas: 100% (620/620), done.
# cd /tmp/stagit
# make && make install
cc -c -O2 -std=c99 -I/usr/local/include -D_XOPEN_SOURCE=700
-D_DEFAULT_SOURCE -D_BSD_SOURCE -I/usr/local/include -o stagit.o
-c stagit.c
...

Configure httpd(8)

Edit /etc/httpd.conf to add location section to your server.

...
location "/src/*" { root { "/src", strip 1 } }
...

Make src directory in /var/www:

# mkdir -p /var/www/src
# chown git:git /var/www/src
#

Verify the new httpd configuration and restart it:

# httpd -n
configuration OK
# rcctl restart httpd
httpd(ok)
httpd(ok)
#

Add repositories

Switch to git user:

# cd /home/git
# su git
$

Repeat these steps for every of your repositories:

$ cd /home/git/REPOSITORY.git
$ echo 'git://REMOTE_SERVER/src/REPOSITORY.git' > url
$ echo 'OWNER_NAME' > owner
$ echo 'DESCRIPTION' > description
$

Edit a hook script /home/git/REPOSITORY.git/hooks/post-receive:

#!/bin/sh
set -e
dst="/var/www/htdocs/$(basename "$(pwd)" '.git')"

mkdir -p "$dst/src"
cd "$dst/src" && stagit "$src"
cp -f "$dst/src/log.html" "$dst/src/index.html"
cp -f "$dst/stagit/"* "$dst/src/"

Or download a bit more advanced post-receive hook:

$ cd /home/git/REPOSITORY.git/hooks
$ ftp -V https://www.romanzolotarev.com/post-receive
post-receive 100% |*****************************|  1032       00:00
$ chmod +x post-receive
$

Edit the script to suit your needs.

When all repos are ready, generate the index page:

$ cd /var/www/src
$ stagit-index /home/git/*.git > index.html
$

Add style.css, logo.png, and favicon.png to /var/www/src if needed.

$ ftp -V https://www.romanzolotarev.com/stagit/style.css
style.css    100% |*****************************|   959       00:00
$ ftp -V https://www.romanzolotarev.com/stagit/logo.png
logo.png     100% |*****************************|  6406       00:00
$ ftp -V https://www.romanzolotarev.com/favicon.png
favicon.png  100% |*****************************|   408       00:00
$

To test post-receive hook push from your local host to the server:

$ git push REMOTE master
...
$

Thanks to Adriano Barbosa for catching a bug in httpd.conf.