From e5703d8aaaadf562d95e66708d96a1aa5d92aa24 Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Mon, 7 Mar 2022 21:29:13 -0600 Subject: [PATCH] Cleanup --- extras/ikev2changeaddr.sh | 2 +- extras/ikev2onlymode.sh | 2 +- extras/ikev2setup.sh | 2 +- extras/vpnuninstall.sh | 2 +- extras/vpnupgrade.sh | 2 +- extras/vpnupgrade_alpine.sh | 2 +- extras/vpnupgrade_amzn.sh | 2 +- extras/vpnupgrade_centos.sh | 2 +- extras/vpnupgrade_ubuntu.sh | 2 +- vpnsetup_alpine.sh | 5 ++++- vpnsetup_amzn.sh | 5 ++++- vpnsetup_centos.sh | 5 ++++- vpnsetup_ubuntu.sh | 5 ++++- 13 files changed, 25 insertions(+), 13 deletions(-) diff --git a/extras/ikev2changeaddr.sh b/extras/ikev2changeaddr.sh index bd0e353..0f49d01 100755 --- a/extras/ikev2changeaddr.sh +++ b/extras/ikev2changeaddr.sh @@ -90,7 +90,7 @@ EOF check_libreswan() { ipsec_ver=$(ipsec --version 2>/dev/null) if ( ! grep -qs "hwdsl2 VPN script" /etc/sysctl.conf && ! grep -qs "hwdsl2" /opt/src/run.sh ) \ - || ! printf '%s' "$ipsec_ver" | grep -q "Libreswan"; then + || ! printf '%s' "$ipsec_ver" | grep -qi 'libreswan'; then cat 1>&2 <<'EOF' Error: This script can only be used with an IPsec server created using: https://github.com/hwdsl2/setup-ipsec-vpn diff --git a/extras/ikev2onlymode.sh b/extras/ikev2onlymode.sh index 532938c..e537b43 100755 --- a/extras/ikev2onlymode.sh +++ b/extras/ikev2onlymode.sh @@ -49,7 +49,7 @@ check_libreswan() { swan_ver=$(printf '%s' "$ipsec_ver" | sed -e 's/.*Libreswan U\?//' -e 's/\( (\|\/K\).*//') if ! grep -qs "hwdsl2 VPN script" /etc/sysctl.conf \ || ! grep -qs "config setup" /etc/ipsec.conf \ - || ! printf '%s' "$ipsec_ver" | grep -q "Libreswan"; then + || ! printf '%s' "$ipsec_ver" | grep -qi 'libreswan'; then cat 1>&2 <<'EOF' Error: Your must first set up the IPsec VPN server before selecting IKEv2-only mode. See: https://github.com/hwdsl2/setup-ipsec-vpn diff --git a/extras/ikev2setup.sh b/extras/ikev2setup.sh index a2ca305..2901c9b 100755 --- a/extras/ikev2setup.sh +++ b/extras/ikev2setup.sh @@ -101,7 +101,7 @@ EOF check_libreswan() { ipsec_ver=$(ipsec --version 2>/dev/null) if ( ! grep -qs "hwdsl2 VPN script" /etc/sysctl.conf && ! grep -qs "hwdsl2" /opt/src/run.sh ) \ - || ! printf '%s' "$ipsec_ver" | grep -q "Libreswan"; then + || ! printf '%s' "$ipsec_ver" | grep -qi 'libreswan'; then cat 1>&2 <<'EOF' Error: Your must first set up the IPsec VPN server before setting up IKEv2. See: https://github.com/hwdsl2/setup-ipsec-vpn diff --git a/extras/vpnuninstall.sh b/extras/vpnuninstall.sh index ebf847e..5b59f1d 100755 --- a/extras/vpnuninstall.sh +++ b/extras/vpnuninstall.sh @@ -71,7 +71,7 @@ EOF check_libreswan() { ipsec_ver=$(ipsec --version 2>/dev/null) if ! grep -qs "hwdsl2 VPN script" /etc/sysctl.conf \ - || ! printf '%s' "$ipsec_ver" | grep -q "Libreswan"; then + || ! printf '%s' "$ipsec_ver" | grep -qi 'libreswan'; then exiterr "Cannot remove IPsec VPN because it has not been set up on this server." fi } diff --git a/extras/vpnupgrade.sh b/extras/vpnupgrade.sh index 74e17fe..7c09588 100755 --- a/extras/vpnupgrade.sh +++ b/extras/vpnupgrade.sh @@ -93,7 +93,7 @@ EOF check_libreswan() { ipsec_ver=$(/usr/local/sbin/ipsec --version 2>/dev/null) - if ! printf '%s' "$ipsec_ver" | grep -q "Libreswan"; then + if ! printf '%s' "$ipsec_ver" | grep -qi 'libreswan'; then cat 1>&2 <<'EOF' Error: This script requires Libreswan already installed. See: https://github.com/hwdsl2/setup-ipsec-vpn diff --git a/extras/vpnupgrade_alpine.sh b/extras/vpnupgrade_alpine.sh index 136e1b1..71add4e 100755 --- a/extras/vpnupgrade_alpine.sh +++ b/extras/vpnupgrade_alpine.sh @@ -59,7 +59,7 @@ check_os() { check_libreswan() { ipsec_ver=$(/usr/local/sbin/ipsec --version 2>/dev/null) swan_ver_old=$(printf '%s' "$ipsec_ver" | sed -e 's/.*Libreswan U\?//' -e 's/\( (\|\/K\).*//') - if ! printf '%s' "$ipsec_ver" | grep -q "Libreswan"; then + if ! printf '%s' "$ipsec_ver" | grep -qi 'libreswan'; then cat 1>&2 <<'EOF' Error: This script requires Libreswan already installed. See: https://github.com/hwdsl2/setup-ipsec-vpn diff --git a/extras/vpnupgrade_amzn.sh b/extras/vpnupgrade_amzn.sh index 4c69995..69ee61c 100755 --- a/extras/vpnupgrade_amzn.sh +++ b/extras/vpnupgrade_amzn.sh @@ -42,7 +42,7 @@ check_os() { check_libreswan() { ipsec_ver=$(/usr/local/sbin/ipsec --version 2>/dev/null) swan_ver_old=$(printf '%s' "$ipsec_ver" | sed -e 's/.*Libreswan U\?//' -e 's/\( (\|\/K\).*//') - if ! printf '%s' "$ipsec_ver" | grep -q "Libreswan"; then + if ! printf '%s' "$ipsec_ver" | grep -qi 'libreswan'; then cat 1>&2 <<'EOF' Error: This script requires Libreswan already installed. See: https://github.com/hwdsl2/setup-ipsec-vpn diff --git a/extras/vpnupgrade_centos.sh b/extras/vpnupgrade_centos.sh index 851a48b..02e354f 100755 --- a/extras/vpnupgrade_centos.sh +++ b/extras/vpnupgrade_centos.sh @@ -60,7 +60,7 @@ check_os() { check_libreswan() { ipsec_ver=$(/usr/local/sbin/ipsec --version 2>/dev/null) swan_ver_old=$(printf '%s' "$ipsec_ver" | sed -e 's/.*Libreswan U\?//' -e 's/\( (\|\/K\).*//') - if ! printf '%s' "$ipsec_ver" | grep -q "Libreswan"; then + if ! printf '%s' "$ipsec_ver" | grep -qi 'libreswan'; then cat 1>&2 <<'EOF' Error: This script requires Libreswan already installed. See: https://github.com/hwdsl2/setup-ipsec-vpn diff --git a/extras/vpnupgrade_ubuntu.sh b/extras/vpnupgrade_ubuntu.sh index 78d2efb..f27d7a0 100755 --- a/extras/vpnupgrade_ubuntu.sh +++ b/extras/vpnupgrade_ubuntu.sh @@ -65,7 +65,7 @@ check_os() { check_libreswan() { ipsec_ver=$(/usr/local/sbin/ipsec --version 2>/dev/null) swan_ver_old=$(printf '%s' "$ipsec_ver" | sed -e 's/.*Libreswan U\?//' -e 's/\( (\|\/K\).*//') - if ! printf '%s' "$ipsec_ver" | grep -q "Libreswan"; then + if ! printf '%s' "$ipsec_ver" | grep -qi 'libreswan'; then cat 1>&2 <<'EOF' Error: This script requires Libreswan already installed. See: https://github.com/hwdsl2/setup-ipsec-vpn diff --git a/vpnsetup_alpine.sh b/vpnsetup_alpine.sh index 8b74ddf..26472d4 100755 --- a/vpnsetup_alpine.sh +++ b/vpnsetup_alpine.sh @@ -202,11 +202,14 @@ get_swan_ver() { } check_libreswan() { + ipsec_bin="/usr/local/sbin/ipsec" ipsec_ver=$(/usr/local/sbin/ipsec --version 2>/dev/null) swan_ver_old=$(printf '%s' "$ipsec_ver" | sed -e 's/.*Libreswan U\?//' -e 's/\( (\|\/K\).*//') - if [ -n "$swan_ver_old" ] && [ "$(find /usr/local/sbin/ipsec -mmin -10080)" ]; then + if [ -n "$swan_ver_old" ] && printf '%s' "$ipsec_ver" | grep -qi 'libreswan' \ + && [ "$(find "$ipsec_bin" -mmin -10080)" ]; then return 0 fi + [ -s "$ipsec_bin" ] && touch "$ipsec_bin" get_swan_ver [ "$swan_ver_old" = "$SWAN_VER" ] } diff --git a/vpnsetup_amzn.sh b/vpnsetup_amzn.sh index 102a4a4..8e5543b 100755 --- a/vpnsetup_amzn.sh +++ b/vpnsetup_amzn.sh @@ -202,11 +202,14 @@ get_swan_ver() { } check_libreswan() { + ipsec_bin="/usr/local/sbin/ipsec" ipsec_ver=$(/usr/local/sbin/ipsec --version 2>/dev/null) swan_ver_old=$(printf '%s' "$ipsec_ver" | sed -e 's/.*Libreswan U\?//' -e 's/\( (\|\/K\).*//') - if [ -n "$swan_ver_old" ] && [ "$(find /usr/local/sbin/ipsec -mmin -10080)" ]; then + if [ -n "$swan_ver_old" ] && printf '%s' "$ipsec_ver" | grep -qi 'libreswan' \ + && [ "$(find "$ipsec_bin" -mmin -10080)" ]; then return 0 fi + [ -s "$ipsec_bin" ] && touch "$ipsec_bin" get_swan_ver [ "$swan_ver_old" = "$SWAN_VER" ] } diff --git a/vpnsetup_centos.sh b/vpnsetup_centos.sh index 383d07b..4dc4ef9 100755 --- a/vpnsetup_centos.sh +++ b/vpnsetup_centos.sh @@ -259,11 +259,14 @@ get_swan_ver() { } check_libreswan() { + ipsec_bin="/usr/local/sbin/ipsec" ipsec_ver=$(/usr/local/sbin/ipsec --version 2>/dev/null) swan_ver_old=$(printf '%s' "$ipsec_ver" | sed -e 's/.*Libreswan U\?//' -e 's/\( (\|\/K\).*//') - if [ -n "$swan_ver_old" ] && [ "$(find /usr/local/sbin/ipsec -mmin -10080)" ]; then + if [ -n "$swan_ver_old" ] && printf '%s' "$ipsec_ver" | grep -qi 'libreswan' \ + && [ "$(find "$ipsec_bin" -mmin -10080)" ]; then return 0 fi + [ -s "$ipsec_bin" ] && touch "$ipsec_bin" get_swan_ver [ "$swan_ver_old" = "$SWAN_VER" ] } diff --git a/vpnsetup_ubuntu.sh b/vpnsetup_ubuntu.sh index 8fba9a7..0204572 100755 --- a/vpnsetup_ubuntu.sh +++ b/vpnsetup_ubuntu.sh @@ -242,11 +242,14 @@ get_swan_ver() { } check_libreswan() { + ipsec_bin="/usr/local/sbin/ipsec" ipsec_ver=$(/usr/local/sbin/ipsec --version 2>/dev/null) swan_ver_old=$(printf '%s' "$ipsec_ver" | sed -e 's/.*Libreswan U\?//' -e 's/\( (\|\/K\).*//') - if [ -n "$swan_ver_old" ] && [ "$(find /usr/local/sbin/ipsec -mmin -10080)" ]; then + if [ -n "$swan_ver_old" ] && printf '%s' "$ipsec_ver" | grep -qi 'libreswan' \ + && [ "$(find "$ipsec_bin" -mmin -10080)" ]; then return 0 fi + [ -s "$ipsec_bin" ] && touch "$ipsec_bin" get_swan_ver [ "$swan_ver_old" = "$SWAN_VER" ] }