8 debug() { #change to false to disable debugging
9 #true && echo "$*" >>debug
10 true && echo "$*" >>/dev/stderr
13 # this program is supposed to be symlinked into a http root directory
14 # we will use the http root as object storage (data directory) and call sub
15 # programs from the directory in which the real executable resides
16 # therefore we need to identify the code and data directories _EXEC and _DATA
19 while [ -L "$real" ]; do
20 real="$(stat -c %N "$real" |sed -r "s:..*. -> .(.*).$:\1:")"
23 _EXEC="$(dirname "$real")" #execution directory
24 _DATA="$(dirname "$call")" #storage directory
26 debug "Execution dir: $_EXEC"
27 debug "Storage dir: $_DATA"
29 [ -w "$_DATA" ] && [ -d "$_DATA" ] || die "storage directory must be writable"
31 # create directories for object storage
32 for each in "$_DATA"/{vcard,mappings,courses}; do
33 [ ! -e "$each" ] && mkdir "$each"
34 [ -w "$each" ] && [ -d "$each" ] || die "storage $each must be a writable directory"
37 # create htaccess file
38 [ -f .htaccess ] || cat >.htaccess <<EOF
40 AddHandler cgi-script .cgi
41 DirectoryIndex index.cgi
43 [ -f .htaccess ] || die "no htaccess file present and unable to create one"