2022-02-02 09:22:29 -08:00
|
|
|
# Lines starting with '##' are intended for usage documentation
|
2022-02-02 10:49:23 -08:00
|
|
|
# Does nothing if not using stdout
|
2022-02-02 09:22:29 -08:00
|
|
|
function usage() {
|
2022-02-02 10:49:23 -08:00
|
|
|
if [ -t 1 ]; then
|
2022-07-07 17:14:28 -07:00
|
|
|
grep '^##' "$prog" | sed \
|
|
|
|
-e 's/^##\s\?//' \
|
|
|
|
-e "s/__PROG__/$me/" \
|
|
|
|
-e "s|__DEFAULT_WXRX_WEB_PUBDIR__|${WXRX_WEB_PUBDIR:-undefined}|" \
|
|
|
|
-e "s|__DEFAULT_WXRX_WEB_TEMPLATES__|${WXRX_WEB_TEMPLATES:-undefined}|" \
|
|
|
|
1>&2
|
2022-02-02 10:49:23 -08:00
|
|
|
fi
|
2022-02-02 09:22:29 -08:00
|
|
|
}
|
2022-01-22 15:15:37 -08:00
|
|
|
|
|
|
|
function nowstr() {
|
|
|
|
date -u +"%Y-%m-%dT%H:%M:%S%Z"
|
|
|
|
}
|
|
|
|
|
|
|
|
function log() {
|
2022-02-02 09:22:29 -08:00
|
|
|
if [ -t 1 ]; then
|
|
|
|
printf "$(tput setaf 2)[${me}]$(tput sgr0) ${1}\n" ${@:2}
|
|
|
|
else
|
|
|
|
printf "$(nowstr) [${me}] ${1}\n" ${@:2}
|
|
|
|
fi
|
2022-01-22 15:15:37 -08:00
|
|
|
}
|
|
|
|
|
2022-02-02 09:22:29 -08:00
|
|
|
function logerr() {
|
|
|
|
if [ -t 2 ]; then
|
2022-02-02 10:49:23 -08:00
|
|
|
printf "$(tput setaf 1)[${me}] ERROR:$(tput sgr0) ${1}\n" ${@:2} 1>&2
|
2022-02-02 09:22:29 -08:00
|
|
|
else
|
2022-02-02 10:49:23 -08:00
|
|
|
printf "$(nowstr) [${me}] ERROR: ${1}\n" ${@:2} 1>&2
|
2022-02-02 09:22:29 -08:00
|
|
|
fi
|
2022-01-22 15:15:37 -08:00
|
|
|
}
|
2022-02-03 06:29:26 -08:00
|
|
|
|
|
|
|
function logwarn() {
|
|
|
|
if [ -t 2 ]; then
|
|
|
|
printf "$(tput setaf 3)[${me}] WARNING:$(tput sgr0) ${1}\n" ${@:2} 1>&2
|
|
|
|
else
|
|
|
|
printf "$(nowstr) [${me}] WARNING: ${1}\n" ${@:2} 1>&2
|
|
|
|
fi
|
|
|
|
}
|
2022-07-11 10:31:23 -07:00
|
|
|
|
|
|
|
function logdebug() {
|
|
|
|
if [ -z "${DEBUG}" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -t 2 ]; then
|
|
|
|
printf "$(tput setaf 4)[${me}] DEBUG:$(tput sgr0) ${1}\n" ${@:2} 1>&2
|
|
|
|
else
|
|
|
|
printf "$(nowstr) [${me}] DEBUG: ${1}\n" ${@:2} 1>&2
|
|
|
|
fi
|
|
|
|
}
|