From 8fb4bf7897c32652608e09bd8bc461c620809ea0 Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Mon, 22 May 2017 11:46:28 -0500 Subject: [PATCH] Minor clean up --- extras/vpnupgrade.sh | 10 ++++------ extras/vpnupgrade_centos.sh | 6 +++--- vpnsetup.sh | 25 +++++++++++++------------ vpnsetup_centos.sh | 21 ++++++++++++--------- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/extras/vpnupgrade.sh b/extras/vpnupgrade.sh index 8f97409..37337b5 100644 --- a/extras/vpnupgrade.sh +++ b/extras/vpnupgrade.sh @@ -24,10 +24,8 @@ os_type="$(lsb_release -si 2>/dev/null)" if [ -z "$os_type" ]; then [ -f /etc/os-release ] && os_type="$(. /etc/os-release && echo "$ID")" [ -f /etc/lsb-release ] && os_type="$(. /etc/lsb-release && echo "$DISTRIB_ID")" - [ "$os_type" = "debian" ] && os_type=Debian - [ "$os_type" = "ubuntu" ] && os_type=Ubuntu fi -if [ "$os_type" != "Ubuntu" ] && [ "$os_type" != "Debian" ] && [ "$os_type" != "Raspbian" ]; then +if ! printf %s "$os_type" | head -n 1 | grep -qiF -e ubuntu -e debian -e raspbian; then exiterr "This script only supports Ubuntu/Debian." fi @@ -43,11 +41,11 @@ if [ -z "$swan_ver" ]; then exiterr "Libreswan version 'swan_ver' not specified." fi -if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "Libreswan"; then +if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -q "Libreswan"; then exiterr "This script requires Libreswan already installed." fi -if /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs -F "$swan_ver"; then +if /usr/local/sbin/ipsec --version 2>/dev/null | grep -qF "$swan_ver"; then echo "You already have Libreswan version $swan_ver installed! " echo "If you continue, the same version will be re-installed." echo @@ -156,7 +154,7 @@ make -s programs && make -s install # Verify the install and clean up cd /opt/src || exiterr "Cannot enter /opt/src." /bin/rm -rf "/opt/src/libreswan-$swan_ver" -if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs -F "$swan_ver"; then +if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qF "$swan_ver"; then exiterr "Libreswan $swan_ver failed to build." fi diff --git a/extras/vpnupgrade_centos.sh b/extras/vpnupgrade_centos.sh index 3986942..5f33485 100644 --- a/extras/vpnupgrade_centos.sh +++ b/extras/vpnupgrade_centos.sh @@ -36,11 +36,11 @@ if [ -z "$swan_ver" ]; then exiterr "Libreswan version 'swan_ver' not specified." fi -if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "Libreswan"; then +if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -q "Libreswan"; then exiterr "This script requires Libreswan already installed." fi -if /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs -F "$swan_ver"; then +if /usr/local/sbin/ipsec --version 2>/dev/null | grep -qF "$swan_ver"; then echo "You already have Libreswan version $swan_ver installed! " echo "If you continue, the same version will be re-installed." echo @@ -145,7 +145,7 @@ make -s programs && make -s install # Verify the install and clean up cd /opt/src || exiterr "Cannot enter /opt/src." /bin/rm -rf "/opt/src/libreswan-$swan_ver" -if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs -F "$swan_ver"; then +if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qF "$swan_ver"; then exiterr "Libreswan $swan_ver failed to build." fi diff --git a/vpnsetup.sh b/vpnsetup.sh index 51a7435..71996d6 100755 --- a/vpnsetup.sh +++ b/vpnsetup.sh @@ -50,10 +50,8 @@ os_type="$(lsb_release -si 2>/dev/null)" if [ -z "$os_type" ]; then [ -f /etc/os-release ] && os_type="$(. /etc/os-release && echo "$ID")" [ -f /etc/lsb-release ] && os_type="$(. /etc/lsb-release && echo "$DISTRIB_ID")" - [ "$os_type" = "debian" ] && os_type=Debian - [ "$os_type" = "ubuntu" ] && os_type=Ubuntu fi -if [ "$os_type" != "Ubuntu" ] && [ "$os_type" != "Debian" ] && [ "$os_type" != "Raspbian" ]; then +if ! printf %s "$os_type" | head -n 1 | grep -qiF -e ubuntu -e debian -e raspbian; then exiterr "This script only supports Ubuntu/Debian." fi @@ -72,19 +70,22 @@ DEF_IFACE="$(route | grep '^default' | grep -o '[^ ]*$')" if_state1=$(cat "/sys/class/net/$DEF_IFACE/operstate" 2>/dev/null) if [ -z "$VPN_NET_IFACE" ] && [ -n "$if_state1" ] && [ "$if_state1" != "down" ]; then - case "$DEF_IFACE" in - wlan*) - printf "Error: Default network interface '%s' detected.\n\n" "$DEF_IFACE" >&2 + if ! grep -qs raspbian /etc/os-release; then + case "$DEF_IFACE" in + wlan*) cat 1>&2 </dev/null | grep -qs -F "$swan_ver"; then +if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qF "$swan_ver"; then exiterr "Libreswan $swan_ver failed to build." fi diff --git a/vpnsetup_centos.sh b/vpnsetup_centos.sh index d5f410f..86516ad 100755 --- a/vpnsetup_centos.sh +++ b/vpnsetup_centos.sh @@ -65,19 +65,22 @@ DEF_IFACE="$(route | grep '^default' | grep -o '[^ ]*$')" if_state1=$(cat "/sys/class/net/$DEF_IFACE/operstate" 2>/dev/null) if [ -z "$VPN_NET_IFACE" ] && [ -n "$if_state1" ] && [ "$if_state1" != "down" ]; then - case "$DEF_IFACE" in - wlan*) - printf "Error: Default network interface '%s' detected.\n\n" "$DEF_IFACE" >&2 + if ! grep -qs raspbian /etc/os-release; then + case "$DEF_IFACE" in + wlan*) cat 1>&2 </dev/null | grep -qs -F "$swan_ver"; then +if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qF "$swan_ver"; then exiterr "Libreswan $swan_ver failed to build." fi