From 36517cdb1eee2a866b381b52518b192013cd13bd Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sun, 20 Nov 2016 08:48:18 -0800 Subject: [PATCH] Rename setup_environment to setup_product_environment - Default to first detected product - Verify that specified product is installed Signed-off-by: Tom Eastep --- Shorewall-core/lib.base | 38 ++++++++++++++++++++++++-------------- Shorewall-core/lib.cli | 2 +- Shorewall-lite/shorecap | 2 +- Shorewall/Perl/getparams | 2 +- Shorewall6-lite/shorecap | 2 +- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Shorewall-core/lib.base b/Shorewall-core/lib.base index 29ec318ae..cf7a4d966 100644 --- a/Shorewall-core/lib.base +++ b/Shorewall-core/lib.base @@ -26,7 +26,16 @@ SHOREWALL_LIBVERSION=40509 -setup_environment() { +# +# Fatal Error +# +fatal_error() # $@ = Message +{ + echo " ERROR: $@" >&2 + exit 2 +} + +setup_product_environment() { g_basedir=${SHAREDIR}/shorewall g_sharedir="$SHAREDIR"/$PRODUCT @@ -60,11 +69,12 @@ setup_environment() { g_lite=Yes ;; *) - echo " ERROR: Unknown PRODUCT ($PRODUCT)" >&2 - exit 1 + fatal_error "Unknown PRODUCT ($PRODUCT)" ;; esac + [ -f ${SHAREDIR}/${PRODUCT}/version ] || fatal_error "$g_product does not appear to be installed on this system" + if [ -z "${VARLIB}" ]; then VARLIB=${VARDIR} VARDIR=${VARLIB}/$g_program @@ -74,7 +84,6 @@ setup_environment() { } if [ -z "$PRODUCT" ]; then - PRODUCT=shorewall # # This is modified by the installer when ${SHAREDIR} != /usr/share # @@ -82,17 +91,18 @@ if [ -z "$PRODUCT" ]; then g_basedir=${SHAREDIR}/shorewall - setup_environment -fi + if [ -f ${g_basedir}/version ]; then + PRODUCT=shorewall + elif [ -f ${SHAREDIR}/shorewall-lite/version ]; then + PRODUCT=shorewall-lite + elif [ -f ${SHAREDIR}/shorewall6-lite/version ]; then + PRODUCT=shorewall6-lite + else + fatal_error "No Shorewall firewall product is installed" + fi -# -# Fatal Error -# -fatal_error() # $@ = Message -{ - echo " ERROR: $@" >&2 - exit 2 -} + setup_product_environment +fi # # Not configured Error diff --git a/Shorewall-core/lib.cli b/Shorewall-core/lib.cli index 0baa7f8e0..f6da9b048 100644 --- a/Shorewall-core/lib.cli +++ b/Shorewall-core/lib.cli @@ -4495,7 +4495,7 @@ shorewall_cli() { usage 1 fi - setup_environment + setup_product_environment [ -n "$g_lite" ] || . ${SHAREDIR}/shorewall/lib.cli-std diff --git a/Shorewall-lite/shorecap b/Shorewall-lite/shorecap index d64ec2086..c1cbe3649 100755 --- a/Shorewall-lite/shorecap +++ b/Shorewall-lite/shorecap @@ -56,7 +56,7 @@ g_basedir=${SHAREDIR}/shorewall . ${SHAREDIR}/shorewall/lib.cli -setup_environment +setup_product_environment . ${SHAREDIR}/shorewall-lite/configpath diff --git a/Shorewall/Perl/getparams b/Shorewall/Perl/getparams index 672a697d2..d4a4536e0 100755 --- a/Shorewall/Perl/getparams +++ b/Shorewall/Perl/getparams @@ -42,7 +42,7 @@ g_basedir=${SHAREDIR}/shorewall . $g_basedir/lib.cli -setup_environment +setup_product_environment CONFIG_PATH="$2" diff --git a/Shorewall6-lite/shorecap b/Shorewall6-lite/shorecap index 64e89a534..7ddf9e720 100755 --- a/Shorewall6-lite/shorecap +++ b/Shorewall6-lite/shorecap @@ -55,7 +55,7 @@ g_basedir=${SHAREDIR}/shorewall . ${SHAREDIR}/shorewall/lib.cli -setup_environment +setup_product_environment . ${SHAREDIR}/shorewall-lite/configpath