#!/bin/sh # cacophony by C. Duckworth --- hereby released to the public domain SCRIPTDIR=/home/acdw/Sync/www crlf() { # crlf < INPUT ## Convert LF to CRLF sed 's/$/ /g' } log() { # log MESSAGE ... printf >&2 '%s\n' "$*" } http_header() { # http_header [STATUS] [MIMETYPE] [CHARSET] cat <
this page is a program served by cacophony. FOOTER } hcat() { # hcat [FILENAME] [STATUS] export status="${2:-200}" export file="$1" ( case "$file" in *.html) http_header "$status" text/html ;; *.css) http_header "$status" text/css ;; *.js) http_header "$status" text/js ;; *) case "$(file -)" in *HTML*) http_header "$status" ;; *) http_header "$status" text/plain ;; esac esac cat ) < "$file" } hexec() { # hexec PROGRAM [http_header args] prog="$1" shift http_header "$@" "$prog" html_footer "$prog" } run() { # run pag="$PWD$PATH_INFO" src="$SCRIPTDIR$PATH_INFO" if test / = "$PATH_INFO" then PATH_INFO=/index run elif ! test -d "$pag" && test -x "$src" then hexec "$src" 200 elif ! test -d "$pag" && test -r "$pag" then hcat "$pag" 200 elif test -d "$pag" && test -r "$pag/index.html" then hcat "$pag/index.html" 200 else case "$PATH_INFO" in /src/*) hcat "$SCRIPTDIR/${PATH_INFO#/src/}" 200 ;; *) http_header 404 ;; esac fi } run