Roman's avatar

Hi, my name is Roman. I run a job board and make tutorials for BSD users. I'm fan of OpenBSD, POSIX-shell, and vi.

Twitter - RSS - Patreon - PayPal


Publish your Git repositories with stagit(1) and httpd(8)

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

Set up Git and httpd server.

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
export LC_CTYPE='en_US.UTF-8'
src="$(pwd)"
name=$(basename "$src")
dst="/var/www/src/$(basename "$name" '.git')"
mkdir -p "$dst"
cd "$dst" || exit 1

echo "[stagit] building $dst"
stagit "$src"

ln -sf log.html index.html
ln -sf ../style.css style.css
ln -sf ../logo.png logo.png

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

Done!

Tested on OpenBSD 6.3 with stagit 187daa