diff --git a/extras/vpnsetup-debian-7-workaround.sh b/extras/vpnsetup-debian-7-workaround.sh index 6230ce8..21fcae7 100644 --- a/extras/vpnsetup-debian-7-workaround.sh +++ b/extras/vpnsetup-debian-7-workaround.sh @@ -22,7 +22,7 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" -exiterr() { echo "Error: ${1}" >&2; exit 1; } +exiterr() { echo "Error: $1" >&2; exit 1; } if [ "$(sed 's/\..*//' /etc/debian_version 2>/dev/null)" != "7" ]; then exiterr "This script only supports Debian 7 (Wheezy)." diff --git a/extras/vpnupgrade.sh b/extras/vpnupgrade.sh index c3d37c5..d73515b 100644 --- a/extras/vpnupgrade.sh +++ b/extras/vpnupgrade.sh @@ -13,11 +13,11 @@ # Check https://libreswan.org for the latest version swan_ver=3.18 -### Do not edit below this line ### +### DO NOT edit below this line ### export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" -exiterr() { echo "Error: ${1}" >&2; exit 1; } +exiterr() { echo "Error: $1" >&2; exit 1; } exiterr2() { echo "Error: 'apt-get install' failed." >&2; exit 1; } os_type="$(lsb_release -si 2>/dev/null)" @@ -37,13 +37,11 @@ if [ -z "$swan_ver" ]; then exiterr "Libreswan version 'swan_ver' not specified." fi -/usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "Libreswan" -if [ "$?" != "0" ]; then +if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "Libreswan"; then exiterr "This script requires Libreswan already installed." fi -/usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "$swan_ver" -if [ "$?" = "0" ]; then +if /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "$swan_ver"; then echo "You already have Libreswan version $swan_ver installed! " echo "If you continue, the same version will be re-installed." echo diff --git a/extras/vpnupgrade_centos.sh b/extras/vpnupgrade_centos.sh index 8cdbafc..98eabbf 100644 --- a/extras/vpnupgrade_centos.sh +++ b/extras/vpnupgrade_centos.sh @@ -13,11 +13,11 @@ # Check https://libreswan.org for the latest version swan_ver=3.18 -### Do not edit below this line ### +### DO NOT edit below this line ### export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" -exiterr() { echo "Error: ${1}" >&2; exit 1; } +exiterr() { echo "Error: $1" >&2; exit 1; } exiterr2() { echo "Error: 'yum install' failed." >&2; exit 1; } if ! grep -qs -e "release 6" -e "release 7" /etc/redhat-release; then @@ -36,13 +36,11 @@ if [ -z "$swan_ver" ]; then exiterr "Libreswan version 'swan_ver' not specified." fi -/usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "Libreswan" -if [ "$?" != "0" ]; then +if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "Libreswan"; then exiterr "This script requires Libreswan already installed." fi -/usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "$swan_ver" -if [ "$?" = "0" ]; then +if /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "$swan_ver"; then echo "You already have Libreswan version $swan_ver installed! " echo "If you continue, the same version will be re-installed." echo diff --git a/vpnsetup.sh b/vpnsetup.sh index 7deed8e..799c5aa 100755 --- a/vpnsetup.sh +++ b/vpnsetup.sh @@ -36,12 +36,13 @@ YOUR_PASSWORD='' export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" SYS_DT="$(date +%Y-%m-%d-%H:%M:%S)"; export SYS_DT -exiterr() { echo "Error: ${1}" >&2; exit 1; } +exiterr() { echo "Error: $1" >&2; exit 1; } exiterr2() { echo "Error: 'apt-get install' failed." >&2; exit 1; } -conf_bk() { /bin/cp -f "${1}" "${1}.old-$SYS_DT" 2>/dev/null; } +conf_bk() { /bin/cp -f "$1" "$1.old-$SYS_DT" 2>/dev/null; } + check_ip() { IP_REGEX="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" - printf %s "${1}" | tr -d '\n' | grep -Eq "$IP_REGEX" + printf %s "$1" | tr -d '\n' | grep -Eq "$IP_REGEX" } os_type="$(lsb_release -si 2>/dev/null)" @@ -335,9 +336,9 @@ fi # Check if IPTables rules need updating ipt_flag=0 IPT_FILE="/etc/iptables.rules" -if ! grep -qs "hwdsl2 VPN script" "$IPT_FILE" || \ - ! iptables -t nat -C POSTROUTING -s 192.168.42.0/24 -o "$NET_IFS" -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null || \ - ! iptables -t nat -C POSTROUTING -s 192.168.43.0/24 -o "$NET_IFS" -m policy --dir out --pol none -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null; then +if ! grep -qs "hwdsl2 VPN script" "$IPT_FILE" \ + || ! iptables -t nat -C POSTROUTING -s 192.168.42.0/24 -o "$NET_IFS" -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null \ + || ! iptables -t nat -C POSTROUTING -s 192.168.43.0/24 -o "$NET_IFS" -m policy --dir out --pol none -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null; then ipt_flag=1 fi diff --git a/vpnsetup_centos.sh b/vpnsetup_centos.sh index 444af4a..59a3b55 100755 --- a/vpnsetup_centos.sh +++ b/vpnsetup_centos.sh @@ -36,12 +36,13 @@ YOUR_PASSWORD='' export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" SYS_DT="$(date +%Y-%m-%d-%H:%M:%S)"; export SYS_DT -exiterr() { echo "Error: ${1}" >&2; exit 1; } +exiterr() { echo "Error: $1" >&2; exit 1; } exiterr2() { echo "Error: 'yum install' failed." >&2; exit 1; } -conf_bk() { /bin/cp -f "${1}" "${1}.old-$SYS_DT" 2>/dev/null; } +conf_bk() { /bin/cp -f "$1" "$1.old-$SYS_DT" 2>/dev/null; } + check_ip() { IP_REGEX="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" - printf %s "${1}" | tr -d '\n' | grep -Eq "$IP_REGEX" + printf %s "$1" | tr -d '\n' | grep -Eq "$IP_REGEX" } if ! grep -qs -e "release 6" -e "release 7" /etc/redhat-release; then @@ -325,9 +326,9 @@ fi # Check if IPTables rules need updating ipt_flag=0 IPT_FILE="/etc/sysconfig/iptables" -if ! grep -qs "hwdsl2 VPN script" "$IPT_FILE" || \ - ! iptables -t nat -C POSTROUTING -s 192.168.42.0/24 -o "$NET_IFS" -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null || \ - ! iptables -t nat -C POSTROUTING -s 192.168.43.0/24 -o "$NET_IFS" -m policy --dir out --pol none -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null; then +if ! grep -qs "hwdsl2 VPN script" "$IPT_FILE" \ + || ! iptables -t nat -C POSTROUTING -s 192.168.42.0/24 -o "$NET_IFS" -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null \ + || ! iptables -t nat -C POSTROUTING -s 192.168.43.0/24 -o "$NET_IFS" -m policy --dir out --pol none -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null; then ipt_flag=1 fi