]> git.plutz.net Git - cgilite/blob - debug.sh
perform read test on file, not just permission check
[cgilite] / debug.sh
1 #!/bin/zsh
2
3 # Copyright 2014, 2015 Paul Hänsch
4 #
5 # This file is part of shcgi.
6
7 # shcgi is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # shcgi is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with shcgi.  If not, see <http://www.gnu.org/licenses/>. 
19
20 # put debug options in the local.opts file
21 DBG_ENABLED=false
22 DBG_FILE=/dev/stderr
23
24 # basic functions
25 debug() { #change to false to disable debugging
26   if [ "$DBG_ENABLED" = true -a -n "$*" ]; then
27     printf '%s\n' "$*" >>"$DBG_FILE"
28   elif [ "$DBG_ENABLED" = true -a -z "$*" ]; then
29     tee -a "$DBG_FILE"
30   elif [ -z "$*" ]; then
31     cat
32   fi
33 }
34
35 die() {
36   debug FATAL: "$*"
37   printf '%s\n' "$*" >&2
38   exit 1
39 }