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.sh36
1 files changed, 36 insertions, 0 deletions
diff --git a/cacophony.sh b/cacophony.sh new file mode 100755 index 0000000..7cf4dc3 --- /dev/null +++ b/cacophony.sh
@@ -0,0 +1,36 @@
1#!/bin/sh
2
3SCRIPTDIR=source
4
5crlf() { # crlf < INPUT
6 ## Convert LF to CRLF
7 sed 's/$/ /g'
8}
9
10header() { # header [STATUS]
11 cat <<HEADER | crlf
12HTTP/1.1 ${1:-200}
13Content-Type: text/html;charset=utf-8
14
15HEADER
16}
17
18hexec() { # hexec PROGRAM [header args]
19 prog="$1"; shift
20 header "$@"
21 exec "$prog"
22}
23
24run() {
25 if test / = "$PATH_INFO"
26 then PATH_INFO=/index run
27 else
28 path="$PWD/$SCRIPTDIR$PATH_INFO"
29 if ! test -d "$path" && test -x "$path"
30 then hexec "$path" 200
31 else header 404
32 fi
33 fi
34}
35
36run