]> git.plutz.net Git - busy/blobdiff - index.cgi
improved debugging functions
[busy] / index.cgi
index 932a763a26acfc453e53172adad4cc7101bef56d..618fac41982ebbe15e90c5bb4caa5ecb38589abb 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
 # You should have received a copy of the GNU Affero General Public License
 # along with Busy.  If not, see <http://www.gnu.org/licenses/>. 
 
 # You should have received a copy of the GNU Affero General Public License
 # along with Busy.  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
-}
+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
 
 # 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
 
 _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
 
 # 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"
 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"