]> git.plutz.net Git - confetti/blob - index.cgi
display main navigation menu
[confetti] / index.cgi
1 #!/bin/zsh
2
3 # basic functions
4 die() {
5   echo "$*" >/dev/stderr
6   exit 1
7 }
8 debug() { #change to false to disable debugging
9   #true && echo "$*" >>debug
10   true && echo "$*" >>/dev/stderr
11 }
12
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 _STOR
17 call=$0
18 real=$call
19 while [ -L "$real" ]; do
20   real="$(stat -c %N "$real" |sed -r "s:..*. -> .(.*).$:\1:")"
21 done
22
23 _EXEC="$(dirname "$real")"  #execution directory
24 _STOR="$(dirname "$call")"  #storage directory
25
26 debug "Execution dir: $_EXEC"
27 debug "Storage dir: $_STOR"
28
29 [ -w "$_EXEC" ] && [ -d "$_EXEC" ] || die "storage directory must be writable"
30
31 # create directories for object storage
32 for each in "$_STOR"/{vcard,mappings,courses}; do
33   [ ! -e "$each" ] && mkdir "$each"
34   [ -w "$each" ] && [ -d "$each" ] || die "storage $each must be a writable directory"
35 done
36
37 # create htaccess file
38 [ -f .htaccess ] || cat >.htaccess <<EOF
39 Options         +ExecCGI
40 AddHandler      cgi-script .cgi
41 DirectoryIndex  index.cgi
42 EOF
43 [ -f .htaccess ] || die "no htaccess file present and unable to create one"
44
45 . "$_EXEC/cgi.sh"
46
47 cgi_get
48 debug "$_GET"
49
50 . "$_EXEC/page.sh"