]> git.plutz.net Git - confetti/commitdiff
improved debugging functions
authorpaul <paul@plutz.net>
Wed, 18 Mar 2015 12:14:08 +0000 (12:14 +0000)
committerpaul <paul@plutz.net>
Wed, 18 Mar 2015 12:14:08 +0000 (12:14 +0000)
svn path=/trunk/; revision=54

index.cgi
local.opts [new file with mode: 0644]

index b34c95976e65e98fcdd2a836f4f54c70cdfd29c2..c908d7bde8b3e5e4f97345d76e14212118520c84 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
 
 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 (file)
index 0000000..a473b58
--- /dev/null
@@ -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