I replaced cgit on my git server with a more minimal web representation. I think that people are, if at all, either interested in the current content of master/HEAD or want to clone the repo anyway.
Dumping master/HEAD
#!/bin/sh
set -eu
DIR="/var/www/git-dump/$1"
files=`git ls-tree --full-tree -r --name-only HEAD`
rm -rf "$DIR"
echo "$files" | while IFS=$'\n' read -r f; do
subdir=`dirname $f`
fulldir="$DIR/$subdir"
mkdir -p "$fulldir"
fullpath="$DIR/$f"
git show HEAD:"$f" > "$fullpath"
if file "$fullpath" | grep -q "text"; then
:
else
echo "Binary file" > "$fullpath"
fi
done
This script is called from post-receive hooks with the repo name as argument.
Public clone
The git-daemon allows public cloning via the git protocol on port 9418. Repositories need an empty git-daemon-export-ok file. I also set –base-path to the git repo root folder, so that stuff viewed in e.g. https://git.fireandbrimst.one/simpleserver/ can be cloned with git clone git://git.fireandbrimst.one/simpleserver.
Nginx file type
The git dump has its own nginx server configuration. Inside I made sure to only serve files as text/plain:
server {
types { }
default_type text/plain;
listen 80;
...
autoindex on;
}
Posted in
programming
tech fatigue
2021-02-24 20:06 UTC