From a496edef545e012caa3564977af65cf80402335b Mon Sep 17 00:00:00 2001
From: Matt Darfeuille <matdarf@gmail.com>
Date: Mon, 20 Feb 2017 18:52:03 +0100
Subject: [PATCH] Use a function to fail on fatal error

Signed-off-by: Matt Darfeuille <matdarf@gmail.com>
Signed-off-by: Tom Eastep <teastep@shorewall.net>
---
 Shorewall-core/install.sh |  3 +--
 Shorewall-init/install.sh |  6 ++----
 Shorewall-lite/install.sh |  3 +--
 Shorewall/install.sh      | 12 ++++--------
 4 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/Shorewall-core/install.sh b/Shorewall-core/install.sh
index 0fe9bf31c..97509792f 100755
--- a/Shorewall-core/install.sh
+++ b/Shorewall-core/install.sh
@@ -241,8 +241,7 @@ case "$HOST" in
     debian|gentoo|redhat|slackware|archlinux|linux|suse|openwrt)
 	;;
     *)
-	echo "ERROR: Unknown HOST \"$HOST\"" >&2
-	exit 1;
+	fatal_error "Unknown HOST \"$HOST\""
 	;;
 esac
 
diff --git a/Shorewall-init/install.sh b/Shorewall-init/install.sh
index 57a495bd6..d89dbc3b6 100755
--- a/Shorewall-init/install.sh
+++ b/Shorewall-init/install.sh
@@ -254,12 +254,10 @@ case "$HOST" in
 	echo "Installing Openwrt-specific configuration..."
 	;;
     linux)
-	echo "ERROR: Shorewall-init is not supported on this system" >&2
-	exit 1
+	fatal_error "Shorewall-init is not supported on this system"
 	;;
     *)
-	echo "ERROR: Unsupported HOST distribution: \"$HOST\"" >&2
-	exit 1;
+	fatal_error "Unsupported HOST distribution: \"$HOST\""
 	;;
 esac
 
diff --git a/Shorewall-lite/install.sh b/Shorewall-lite/install.sh
index df3edf32c..a485c5304 100755
--- a/Shorewall-lite/install.sh
+++ b/Shorewall-lite/install.sh
@@ -269,8 +269,7 @@ case "$HOST" in
     linux)
 	;;
     *)
-	echo "ERROR: Unknown HOST \"$HOST\"" >&2
-	exit 1;
+	fatal_error "ERROR: Unknown HOST \"$HOST\""
 	;;
 esac
 
diff --git a/Shorewall/install.sh b/Shorewall/install.sh
index f06764c0d..139d32586 100755
--- a/Shorewall/install.sh
+++ b/Shorewall/install.sh
@@ -266,8 +266,7 @@ case "$HOST" in
     linux)
 	;;
     *)
-	echo "ERROR: Unknown HOST \"$HOST\"" >&2
-	exit 1;
+	fatal_error "Unknown HOST \"$HOST\""
 	;;
 esac
 
@@ -278,8 +277,7 @@ if [ $PRODUCT = shorewall ]; then
 	#
 	if [ "$DIGEST" != SHA ]; then
 	    if [ "$BUILD" = "$HOST" ] && ! eval perl -e \'use Digest::$DIGEST\;\' 2> /dev/null ; then
-		echo "ERROR: Perl compilation with Digest::$DIGEST failed" >&2
-		exit 1;
+		fatal_error "Perl compilation with Digest::$DIGEST failed"
 	    fi
 
 	    cp -af Perl/Shorewall/Chains.pm Perl/Shorewall/Chains.pm.bak
@@ -302,8 +300,7 @@ if [ $PRODUCT = shorewall ]; then
 		sed -i 's/Digest::SHA/Digest::SHA1/' Perl/Shorewall/Config.pm
 		DIGEST=SHA1
 	    else
-		echo "ERROR: Shorewall $VERSION requires either Digest::SHA or Digest::SHA1" >&2
-		exit 1
+		fatal_error "Shorewall $VERSION requires either Digest::SHA or Digest::SHA1"
 	    fi
 	fi
     fi
@@ -334,8 +331,7 @@ fi
 run_install -d $OWNERSHIP -m 0755 ${DESTDIR}${SBINDIR}
 [ -n "${INITFILE}" ] && run_install -d $OWNERSHIP -m 0755 ${DESTDIR}${INITDIR}
 if [ -z "$DESTDIR" -a $PRODUCT != shorewall ]; then
-    [ -x ${LIBEXECDIR}/shorewall/compiler.pl ] || \
-	{ echo "   ERROR: Shorewall >= 4.5.0 is not installed" >&2; exit 1; }
+    [ -x ${LIBEXECDIR}/shorewall/compiler.pl ] || fatal_error "Shorewall >= 4.5.0 is not installed"
 fi
 
 echo "Installing $Product Version $VERSION"