about summary refs log tree commit diff stats
path: root/cacophony.sh
diff options
context:
space:
mode:
Diffstat (limited to 'cacophony.sh')
-rwxr-xr-xcacophony.sh23
1 files changed, 18 insertions, 5 deletions
diff --git a/cacophony.sh b/cacophony.sh index 7cf4dc3..f893a60 100755 --- a/cacophony.sh +++ b/cacophony.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# cacophony by C. Duckworth --- public domain
2 3
3SCRIPTDIR=source 4SCRIPTDIR=source
4 5
@@ -7,7 +8,7 @@ crlf() { # crlf < INPUT
7 sed 's/$/ /g' 8 sed 's/$/ /g'
8} 9}
9 10
10header() { # header [STATUS] 11http_header() { # header [STATUS]
11 cat <<HEADER | crlf 12 cat <<HEADER | crlf
12HTTP/1.1 ${1:-200} 13HTTP/1.1 ${1:-200}
13Content-Type: text/html;charset=utf-8 14Content-Type: text/html;charset=utf-8
@@ -15,20 +16,32 @@ Content-Type: text/html;charset=utf-8
15HEADER 16HEADER
16} 17}
17 18
19html_footer() { # footer PROGRAM
20 cat <<EOF
21<footer>
22copyright (C) $(stat -c %y "$1" | cut -d- -f1) Case Duckworth.
23this page is a <a href="$SCRIPTDIR/${1##*/}">program</a>
24served by <a href="https://git.acdw.net/cacophony">cacophony</a>.
25</footer>
26</body></html>
27EOF
28}
29
18hexec() { # hexec PROGRAM [header args] 30hexec() { # hexec PROGRAM [header args]
19 prog="$1"; shift 31 prog="$1"; shift
20 header "$@" 32 http_header "$@"
21 exec "$prog" 33 "$prog"
34 html_footer "$prog"
22} 35}
23 36
24run() { 37run() { # run
25 if test / = "$PATH_INFO" 38 if test / = "$PATH_INFO"
26 then PATH_INFO=/index run 39 then PATH_INFO=/index run
27 else 40 else
28 path="$PWD/$SCRIPTDIR$PATH_INFO" 41 path="$PWD/$SCRIPTDIR$PATH_INFO"
29 if ! test -d "$path" && test -x "$path" 42 if ! test -d "$path" && test -x "$path"
30 then hexec "$path" 200 43 then hexec "$path" 200
31 else header 404 44 else http_header 404
32 fi 45 fi
33 fi 46 fi
34} 47}