💾 Archived View for tilde.club › ~kitzman › posts › 2023-04-15_vac_over_gemini › index.gmi captured on 2024-06-20 at 12:03:37. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
15 April 2023
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.
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.
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.
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'
Great, in few lines of code, I can easily access and send my backups
to anyone!