Commit f6b7a0c

Daniel Axtens <dja@axtens.net>
2026-09-29 00:57:10
Tue 29 Sep 2026 00:57:10 AEST
1 parent e4438d6
Changed files (3)
newsyslog/nginx.conf
@@ -0,0 +1,2 @@
+/var/log/nginx/*.log    root:wheel  640 7   *   @T00    GBJC  /var/run/nginx.pid 30
+
nginx/nginx.conf
@@ -44,6 +44,27 @@ http {
             }
         }
 
+	location = /git {
+		return 301 /git/www/;
+	}
+
+        location /git {
+            gzip_vary     on;
+            gzip_static   on;
+            zstd_static   on;
+            brotli_static on;
+            root   /usr/local/www/git;
+            index  index.html;
+
+            etag off;
+            if ($hash_etag != "") {
+                add_header ETag $hash_etag always;
+                add_header Cache-Control "public, s-maxage=31536000, stale-if-error=3600";
+                add_header Surrogate-Key "blog";
+                add_header Last-Modified "";
+            }
+        }
+
         location ^~ /cgi-bin/ {
             root /usr/local/www/;
 
build.sh
@@ -2,34 +2,69 @@
 set -e -u -o pipefail
 #set -v
 
+# run this from a directory outside the script directory
+# as it will clone the repo and create general mess
+# plus it will nuke anything called root
+
+SRCDIR=$(dirname $0)
+DESTDIR=$(pwd)
+
 # clean and create the output dirs
 rm -rf root
-mkdir -p root/usr/local/www
+mkdir -p root/usr/local/www/git
 mkdir -p root/usr/local/etc
+mkdir -p root/etc/newsyslog.conf.d
 
-# copy in the nginx and cgi-bin
-cp -r cgi-bin root/usr/local/www/
-cp -r nginx root/usr/local/etc
+# copy in the syslog and nginx conf
+cp $SRCDIR/newsyslog/* root/etc/newsyslog.conf.d/
+cp -r $SRCDIR/nginx root/usr/local/etc
 
-# generate the files
-pushd blog
+# generate the blog files
+pushd $SRCDIR/blog
 hugo --cleanDestinationDir=true --minify=true
 popd
 
+# move that in
+mv $SRCDIR/blog/public/ root/usr/local/www/blog
+
 # generate the etags
-pushd blog/public
+pushd root/usr/local/www/blog
 find . -type f | while read -r file; do
 	# trim: ./ -> /
 	WEB_PATH=$(echo $file | cut -c 2-)
 	SHA=$(shasum $file | awk '{print $1}')
 	echo "$WEB_PATH	\"$SHA\";"
-done | tee ../../root/usr/local/etc/nginx/etag.map
+done | tee $DESTDIR/root/usr/local/etc/nginx/etag.map
 INDEX_SHA=$(shasum index.html | awk '{print $1}')
-echo "/	\"$INDEX_SHA\";" | tee -a ../../root/usr/local/etc/nginx/etag.map
+echo "/	\"$INDEX_SHA\";" | tee -a $DESTDIR/root/usr/local/etc/nginx/etag.map
+popd
+
+# get a git checkout and update it for dumb transport
+git clone --no-hardlinks --bare $SRCDIR root/usr/local/www/git/www.git
+git -C root/usr/local/www/git/www.git remote remove origin
+git -C root/usr/local/www/git/www.git update-server-info
+
+# generate static site
+pushd root/usr/local/www/git/www.git
+~/go/bin/gitmal --minify .
+mv output ../www
+popd
+
+# generate the etags
+pushd root/usr/local/www/git/
+find . -type f | while read -r file; do
+	# trim: ./ then later prepend /git/
+	WEB_PATH=$(echo $file | cut -c 3-)
+	SHA=$(shasum $file | awk '{print $1}')
+	echo "/git/$WEB_PATH	\"$SHA\";"
+done | tee -a $DESTDIR/root/usr/local/etc/nginx/etag.map
+INDEX_SHA=$(shasum www/index.html | awk '{print $1}')
+echo "/git/	\"$INDEX_SHA\";" | tee -a $DESTDIR/root/usr/local/etc/nginx/etag.map
 popd
 
 # compress the files
-find blog/public -type f -exec brotli --squash --best \{\} \; -exec gzip --best --keep \{\} \; -exec zstd -9 \{\} \;
+find root/usr/local/www -type f -exec brotli --squash --best \{\} \; -exec gzip --best --keep \{\} \; -exec zstd -9 \{\} \;
+
+# copy in cgi-bin last so it doesn't get compressed
+cp -r $SRCDIR/cgi-bin root/usr/local/www/
 
-# move that in
-mv blog/public/ root/usr/local/www/blog