g9srv/rfs

53 lines
775 B
Plaintext
Raw Permalink Normal View History

2021-01-14 19:18:16 +00:00
#! /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/ //'}
2021-01-14 19:32:05 +00:00
if(~ $url '') url=/
2021-01-14 19:18:16 +00:00
if(test -f $webroot$url){
header 20 text/gemini
cat $webroot$url
exit 0
}
2021-01-14 19:36:49 +00:00
if(test -f $webroot$url/index.gmi){
2021-01-14 19:18:16 +00:00
header 20 text/utf8
cat $webroot$url/index.gmi
exit 0
}
header 51 'file not found'