From: paul Date: Wed, 18 Mar 2015 10:43:50 +0000 (+0000) Subject: improved debugging functions X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=d41ccbb56b8ebf2b7f317a5b35f2b04725a2005d;p=busy improved debugging functions svn path=/trunk/; revision=58 --- diff --git a/index.cgi b/index.cgi index 932a763..618fac4 100755 --- a/index.cgi +++ b/index.cgi @@ -18,18 +18,9 @@ # You should have received a copy of the GNU Affero General Public License # along with Busy. 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 -} +export LC_ALL=C LANG=C +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 @@ -40,9 +31,28 @@ 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() { + echo -E "$*" + exit 1 +} # create directories for object storage +[ -w "$_DATA" ] && [ -d "$_DATA" ] || die "storage directory must be writable" + for each in "$_DATA"/{Home,Tasks,Wiki,QRcodes}; do [ ! -e "$each" ] && mkdir "$each" [ -w "$each" ] && [ -d "$each" ] || die "storage $each must be a writable directory" 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