From aacb3e890b1e719c15564b1272472a3c091da130 Mon Sep 17 00:00:00 2001 From: glenda Date: Thu, 14 Jan 2021 19:18:16 +0000 Subject: init commit --- rfs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 rfs (limited to 'rfs') diff --git a/rfs b/rfs new file mode 100755 index 0000000..7476e91 --- /dev/null +++ b/rfs @@ -0,0 +1,52 @@ +#! /bin/rc +#TODO add content type parser +cr= +fn header{ + echo $1 $2$cr +} + +fn filetype{ + filetype=`{file -m $1} + type=text/gemini + #TODO: expand + switch ($filetype){ + case image*: + type=$filetype + } + echo $type +} +webroot=./ +while(! ~ $#* 0) { + switch ($1) { + case -w + webroot=$2 + shift + case -m + mflag='yes' + case * + echo Usage: g9srv/fsr [-w webroot] [-m] + exit usage + } + shift +} +fullurl=`{read} +if(~ $mflag yes) + url=`{echo $fullurl | sed 's/gemini:\/\/// + s/ //'} +if not + url=`{echo $fullurl | sed 's/gemini:\/\/[0-9 a-z .]*// + s/ //'} +if(test -f $webroot$url){ + header 20 text/gemini + cat $webroot$url + exit 0 +} + +if(test -f $webroot$url/index.gmi) + header 20 text/utf8 + cat $webroot$url/index.gmi + exit 0 +} +header 51 'file not found' + + -- cgit 1.4.1-2-gfad0