From b15a82d2a97a6041fd7a4ada672d56bb982860be Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Sat, 29 Aug 2009 19:47:13 -0400 Subject: move checkyesno to globals, make NETCFG_DEBUG a yes/no setting (default=no) Signed-off-by: Jim Pryor --- contrib/logging.hook | 6 +++--- src/globals | 34 +++++++++++++++++++++++++++++++++- src/network | 28 ---------------------------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/contrib/logging.hook b/contrib/logging.hook index 8a9f75f..bf6b787 100755 --- a/contrib/logging.hook +++ b/contrib/logging.hook @@ -36,7 +36,7 @@ function report_err { function report_warn { report_log warning "$*" # printhl "$*" - [[ -n "$NETCFG_DEBUG" ]] && echo "DEBUG: $*" >&2 + checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2 } @@ -44,11 +44,11 @@ function report_warn { function report_notify { report_log notice "$*" # print "$*" >&2 - [[ -n "$NETCFG_DEBUG" ]] && echo "DEBUG: $*" >&2 + checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2 } function report_debug { - if [[ -n "$NETCFG_DEBUG" ]]; then + if checkyesno "$NETCFG_DEBUG"; then echo "DEBUG: $*" >&2 else report_log debug "$*" diff --git a/src/globals b/src/globals index c55d038..ca7030e 100644 --- a/src/globals +++ b/src/globals @@ -43,7 +43,7 @@ function report_notify { } function report_debug { - [[ -n "$NETCFG_DEBUG" ]] && echo "DEBUG: $*" + checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" } function report_try { @@ -83,6 +83,37 @@ function exit_err { report_err "$*"; exit 1; } function exit_fail { report_fail "$*"; exit 1; } +### From FreeBSD's /etc/rc.subr +## +# checkyesno var +# Test $1 variable, and warn if not set to YES or NO. +# Return 0 if it's "yes" (et al), nonzero otherwise. +# to make default yes, do "checkyesno ${VAR:-yes}" +# +checkyesno() +{ + local _value="$1" + #debug "checkyesno: $1 is set to $_value." + case "$_value" in + + # "yes", "true", "on", or "1" + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + return 0 + ;; + + # "no", "false", "off", or "0" + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + return 1 + ;; + *) + #warn "\$${1} is not set properly - see ${rcvar_manpage}." + return 1 + ;; + esac +} + + + function load_hooks() { ### Load any +x files in $HOOKS_DIR and $USERHOOKS_DIR local hook @@ -98,3 +129,4 @@ function load_hooks() { load_hooks + diff --git a/src/network b/src/network index e2cdef6..ead501c 100644 --- a/src/network +++ b/src/network @@ -370,31 +370,3 @@ set_interface() esac } - -### From FreeBSD's /etc/rc.subr -## -# checkyesno var -# Test $1 variable, and warn if not set to YES or NO. -# Return 0 if it's "yes" (et al), nonzero otherwise. -# -checkyesno() -{ - local _value="$1" - #debug "checkyesno: $1 is set to $_value." - case "$_value" in - - # "yes", "true", "on", or "1" - [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) - return 0 - ;; - - # "no", "false", "off", or "0" - [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) - return 1 - ;; - *) - #warn "\$${1} is not set properly - see ${rcvar_manpage}." - return 1 - ;; - esac -} -- cgit v1.2.3-24-g4f1b