about summary refs log tree commit diff stats
path: root/cacophony.sh
blob: 7cf4dc338a3f30e94530aecd6f880c7cdf1e4079 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh

SCRIPTDIR=source

crlf() { # crlf < INPUT
	## Convert LF to CRLF
	sed 's/$/
/g'
}

header() { # header [STATUS]
	cat <<HEADER | crlf
HTTP/1.1 ${1:-200}
Content-Type: text/html;charset=utf-8

HEADER
}

hexec() { # hexec PROGRAM [header args]
	prog="$1"; shift
	header "$@"
	exec "$prog"
}

run() {
	if test / = "$PATH_INFO"
	then PATH_INFO=/index run
	else
		path="$PWD/$SCRIPTDIR$PATH_INFO"
		if ! test -d "$path" && test -x "$path"
		then hexec "$path" 200
		else header 404
		fi
	fi
}

run