8 debug() { #change to false to disable debugging
9 true && echo "$*" >>debug
12 # this program is supposed to be symlinked into a http root directory
13 # we will use the http root as object storage and call sub programs
14 # from the directory in which the real executable resides
15 # therefore we need to identify the code and data directories _EXEC and _STOR
18 while [ -L "$real" ]; do
19 real="$(stat -c %N "$real" |sed -r "s:..*. -> .(.*).$:\1:")"
22 _EXEC="$(dirname "$real")" #execution directory
23 _STOR="$(dirname "$call")" #storage directory
25 debug "Execution dir: $_EXEC"
26 debug "Storage dir: $_EXEC"
28 [ -w "$_EXEC" ] && [ -d "$_EXEC" ] || die "storage directory must be writable"
30 # create directories for object storage
31 for each in "$_STOR"/{vcard,mappings}; do
32 [ ! -e "$each" ] && mkdir "$each"
33 [ -w "$each" ] && [ -d "$each" ] || die "storage $each must be a writable directory"
36 # create htaccess file
37 [ -f .htaccess ] || cat >.htaccess <<EOF
39 AddHandler cgi-script .cgi
40 DirectoryIndex index.cgi
42 [ -f .htaccess ] || die "no htaccess file present and unable to create one"
44 # parse HTTP GET string
46 echo "$QUERY_STRING" |tr '&' '\n' |while read query; do
47 key="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
48 val="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
49 _GET["$key"]="$(echo -e "$(echo "$val" |sed 's:+: :g;s:%:\\x:g')")"