|
|
|
@ -2,32 +2,49 @@
|
|
|
|
|
# Purpose: helper functions for ngcpcfg
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
# console output including timestamps {{{
|
|
|
|
|
timestamp_replacementchars='' # unset by default
|
|
|
|
|
|
|
|
|
|
console_output() {
|
|
|
|
|
if [ -z "${TIME_FORMAT:-}" ] ; then
|
|
|
|
|
printf -- "$*"
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
local timestamp="$(date "$TIME_FORMAT")"
|
|
|
|
|
|
|
|
|
|
# indent depending on number of characters in date output
|
|
|
|
|
timestamp_replacementchars="$(printf -- "%s: " "$timestamp" | sed 's/./ /g')"
|
|
|
|
|
printf -- "$timestamp: $*"
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
## logging functions {{{
|
|
|
|
|
log_info() {
|
|
|
|
|
logger -t ngcpcfg -- "$*"
|
|
|
|
|
echo "$*"
|
|
|
|
|
console_output "$*\n"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# info without ending newline
|
|
|
|
|
log_info_n() {
|
|
|
|
|
logger -t ngcpcfg -- "$*"
|
|
|
|
|
printf -- "$*"
|
|
|
|
|
console_output "$*"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log_warn() {
|
|
|
|
|
logger -t ngcpcfg -- "Warning: $*"
|
|
|
|
|
echo "Warning: $*"
|
|
|
|
|
console_output "Warning: $*\n"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log_error() {
|
|
|
|
|
logger -t ngcpcfg -- "Error: $*"
|
|
|
|
|
echo "Error: $*" >&2
|
|
|
|
|
console_output "Error: $*\n" >&2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log_debug() {
|
|
|
|
|
if [ -n "${DEBUG:-}" ] ; then
|
|
|
|
|
logger -t ngcpcfg -- "Debug: $*"
|
|
|
|
|
echo ; echo "DEBUG: $*" ; echo # newlines to avoid messup with cmdline output
|
|
|
|
|
console_output "DEBUG: $*\n"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
## }}}
|
|
|
|
@ -38,14 +55,14 @@ if [ -r ngcpcfg-testsuite.cfg ] ; then
|
|
|
|
|
. ngcpcfg-testsuite.cfg
|
|
|
|
|
else
|
|
|
|
|
if [ -r /etc/ngcp-config/ngcpcfg.cfg ] ; then
|
|
|
|
|
log_debug "sourcing configuration file /etc/ngcp-config/ngcpcfg.cfg"
|
|
|
|
|
. /etc/ngcp-config/ngcpcfg.cfg
|
|
|
|
|
log_debug "sourced configuration file /etc/ngcp-config/ngcpcfg.cfg"
|
|
|
|
|
|
|
|
|
|
if [ -d /etc/ngcp-config/ngcpcfg.d ] ; then
|
|
|
|
|
for file in /etc/ngcp-config/ngcpcfg.d/*.cfg ; do
|
|
|
|
|
if test -r $file ; then
|
|
|
|
|
log_debug "sourcing configuration file $file"
|
|
|
|
|
. $file
|
|
|
|
|
log_debug "sourced configuration file $file"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|