/\___/\
   /       \
  l  u   u  l
--l----*----l--      _   _ _                      _           _             
   \   w   /        | |_(_) |_ ____ __  __ _ _ _ ( )___  _ __| |__ _ __ ___ 
     ======         | / / |  _|_ / '  \/ _` | ' \|/(_-< | '_ \ / _` / _/ -_)
   /       \ __     |_\_\_|\__/__|_|_|_\__,_|_||_| /__/ | .__/_\__,_\__\___|
   l        l\ \                                        |_|                 
   l        l/ /
   l  l l   l /
   \ ml lm /_/
	
kitzman's place

Sysinfo and Vac Archives over Gemini

plan9

Introduction

I have a 9front cpu server, which I use for working remotely on my personal projects, build software, and keep backups.

One of its uses, is for keeping vac backups of documentation. As I sometimes needed to access it, and to share it as well, importing and mounting the vac filesystems was not easily accessible, especially for someone who doesn’t want to learn to use Plan9.

Gemini

Serving the archives via a protocol such as HTTP or Gemini would be the preferred way for most people to access and share files. Since Gemini is text-based and doesn’t require customization it’s a pretty neat solution. The clients are also lightweight - heck, you can even use socat to read text/gemini pages.

There exists a gemini server implementation, completely in rc(1), called rc-gemd [1].

That being said, let’s look over some examples of how you can leverage gemini for ad-hoc scripts.

Stats script

First, we can make a stats.rc script. When checking the $location in select-handler, mount #c.

#!/bin/rc

type=text/gemini
cr=

echo 20' '$type^$cr
echo '# Server stats'
echo ''

sysname=`{cat /dev/sysname}
serda=`{date}
serup=`{uptime}

echo 'Name:' $sysname
echo 'Date:' $serda
echo 'Uptime:' $serup

Ta-da! Now you can have your server stats wherever you have a gemini client.

Serving backups

My use-case, in particular, was serving my library items backed-up in Venti. So, the library server had to be mounted in the appropriate location.

#!/bin/rc

type=text/gemini
cr=

libpath=$1
if(~ $#libpath 0) {
	error 40 'library not mounted'
	exit
}

if(! test -r $library/$libpath) {
	error 51 'file does not exist'
	exit
}

# if it's a file, send it
if(test -f $library/$libpath) {
	type=`{file -m $library/$libpath}
	echo 20' '$type^$cr
	cat $library/$libpath
	exit
}

# if it ends with snap.tgz, take a snapshot of the whole directory
if((test -d $library/`{basename -d $libpath}) && (~ `{basename $libpath} 'snap.tgz')) {
	type='application/octet-stream'
	echo 20' '$type^$cr
	tar c $library/`{basename -d $libpath} | gzip
	exit
}

# otherwise, list files
echo 20' '$type^$cr
echo '# library/'^$libpath
echo ''

echo '=>' `{basename -d $libpath} '..'
for (lfile in `{ls $library/$libpath}) {
	echo '=> "'$libpath/$lfile'"' $lfile
}

echo ''
echo '=> snap.tgz snapshot'

Result

Great, in few lines of code, I can easily access and send my backups to anyone!

Appendix

[1] https://git.sr.ht/~moody/rc-gemd/