diff options
Diffstat (limited to 'cacophony.sh')
-rwxr-xr-x | cacophony.sh | 36 |
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 | |||
3 | SCRIPTDIR=source | ||
4 | |||
5 | crlf() { # crlf < INPUT | ||
6 | ## Convert LF to CRLF | ||
7 | sed 's/$/ /g' | ||
8 | } | ||
9 | |||
10 | header() { # header [STATUS] | ||
11 | cat <<HEADER | crlf | ||
12 | HTTP/1.1 ${1:-200} | ||
13 | Content-Type: text/html;charset=utf-8 | ||
14 | |||
15 | HEADER | ||
16 | } | ||
17 | |||
18 | hexec() { # hexec PROGRAM [header args] | ||
19 | prog="$1"; shift | ||
20 | header "$@" | ||
21 | exec "$prog" | ||
22 | } | ||
23 | |||
24 | run() { | ||
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 | |||
36 | run | ||