From: paul Date: Wed, 18 Mar 2015 12:14:08 +0000 (+0000) Subject: improved debugging functions X-Git-Url: https://git.plutz.net/?p=confetti;a=commitdiff_plain;h=0cf57dc53c38e306a7303f1b299f38b636fea266 improved debugging functions svn path=/trunk/; revision=54 --- diff --git a/index.cgi b/index.cgi index b34c959..c908d7b 100755 --- a/index.cgi +++ b/index.cgi @@ -18,17 +18,8 @@ # along with Confetti. If not, see . export LC_ALL=de_DE.UTF-8 - -# basic functions -die() { - echo "$*" >/dev/stderr - exit 1 -} -debug() { #change to false to disable debugging - #true && echo "$*" >>debug - true && [ -n "$*" ] && echo -E "$*" >>/dev/stderr - true && [ -z "$*" ] && tee /dev/stderr -} +DBG_ENABLED=false +DBG_FILE=/dev/stderr # this program is supposed to be symlinked into a http root directory # we will use the http root as object storage (data directory) and call sub @@ -39,9 +30,29 @@ real="$(readlink -f $call)" _EXEC="$(dirname "$real")" #execution directory _DATA="$(dirname "$call")" #storage directory -[ -w "$_DATA" ] && [ -d "$_DATA" ] || die "storage directory must be writable" +# put debug options in the local.opts file +[ -r "$_DATA/local.opts" ] && . "$_DATA/local.opts" + +# basic functions +debug() { #change to false to disable debugging + if [ "$DBG_ENABLED" = true -a -n "$*" ]; then + echo -E "$*" >>"$DBG_FILE" + elif [ "$DBG_ENABLED" = true -a -z "$*" ]; then + tee -a "$DBG_FILE" + elif [ -z "$*" ]; then + cat + fi +} + +die() { + debug "$*" + echo -E "$*" >>/dev/stderr + exit 1 +} # create directories for object storage +[ -w "$_DATA" ] && [ -d "$_DATA" ] || die "storage directory must be writable" + for each in "$_DATA"/{vcard,ical,cache,temp,mappings}; do [ ! -e "$each" ] && mkdir "$each" [ -w "$each" ] && [ -d "$each" ] || die "storage $each must be a writable directory" @@ -57,7 +68,6 @@ EOF [ -f .htaccess ] || die "no htaccess file present and unable to create one" . "$_EXEC/cgi.sh" - cgi_get . "$_EXEC/constants.sh" diff --git a/local.opts b/local.opts new file mode 100644 index 0000000..a473b58 --- /dev/null +++ b/local.opts @@ -0,0 +1,8 @@ +# This file is meaningless in the exec directory +# You can copy it to your data directory (usually +# your HTTP root) to set per instance debug +# options and the like +# beware that the file is sourced as a shell script + +DBG_ENABLED=false +DBG_FILE=/dev/stderr