From 6e16712bc521d445c9015a89ce44530ca30d7ad9 Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Mon, 31 Oct 2016 01:13:20 -0500 Subject: [PATCH] Minor clean up --- extras/vpnupgrade_centos.sh | 4 ---- vpnsetup.sh | 27 ++++++++++++--------------- vpnsetup_centos.sh | 17 ++++++----------- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/extras/vpnupgrade_centos.sh b/extras/vpnupgrade_centos.sh index fd1e097..8cdbafc 100644 --- a/extras/vpnupgrade_centos.sh +++ b/extras/vpnupgrade_centos.sh @@ -20,10 +20,6 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" exiterr() { echo "Error: ${1}" >&2; exit 1; } exiterr2() { echo "Error: 'yum install' failed." >&2; exit 1; } -if [ ! -f /etc/redhat-release ]; then - exiterr "This script only supports CentOS/RHEL." -fi - if ! grep -qs -e "release 6" -e "release 7" /etc/redhat-release; then exiterr "This script only supports CentOS/RHEL 6 and 7." fi diff --git a/vpnsetup.sh b/vpnsetup.sh index 42ca10b..e3abe02 100755 --- a/vpnsetup.sh +++ b/vpnsetup.sh @@ -50,7 +50,9 @@ if [ "$os_type" != "Ubuntu" ] && [ "$os_type" != "Debian" ] && [ "$os_type" != " fi if [ -f /proc/user_beancounters ]; then - exiterr "This script does not support OpenVZ VPS." + echo "Error: This script does not support OpenVZ VPS." >&2 + echo "Try OpenVPN: https://github.com/Nyr/openvpn-install" >&2 + exit 1 fi if [ "$(id -u)" != 0 ]; then @@ -68,12 +70,9 @@ cat 1>&2 <<'EOF' DO NOT RUN THIS SCRIPT ON YOUR PC OR MAC! If running on a server, you may fix this error by first -finding the active network interface: -route | grep '^default' | grep -o '[^ ]*$' - -Then set this variable and re-run the script: -export VPN_IFACE="YOUR_INTERFACE" +setting this variable and re-run the script: +export VPN_IFACE="$(route | grep '^default' | grep -o '[^ ]*$')" EOF exit 1 fi @@ -161,8 +160,6 @@ apt-get -yq install ppp xl2tpd || exiterr2 # Install Fail2Ban to protect SSH server apt-get -yq install fail2ban || exiterr2 -update-rc.d fail2ban enable -systemctl enable fail2ban 2>/dev/null # Compile and install Libreswan swan_ver=3.18 @@ -377,7 +374,7 @@ if [ "$ipt_flag" = "1" ]; then fi fi -# Load IPTables rules at system boot +# Load IPTables rules at boot mkdir -p /etc/network/if-pre-up.d cat > /etc/network/if-pre-up.d/iptablesload <<'EOF' #!/bin/sh @@ -386,22 +383,22 @@ exit 0 EOF # Start services at boot +update-rc.d fail2ban enable >/dev/null 2>&1 +systemctl enable fail2ban >/dev/null 2>&1 if ! grep -qs "hwdsl2 VPN script" /etc/rc.local; then conf_bk "/etc/rc.local" - sed --follow-symlinks -i -e '/^exit 0/d' /etc/rc.local + sed --follow-symlinks -i '/^exit 0/d' /etc/rc.local cat >> /etc/rc.local <<'EOF' # Added by hwdsl2 VPN script -EOF - if grep -qs raspbian /etc/os-release; then - echo "sleep 30" >> /etc/rc.local - fi -cat >> /etc/rc.local <<'EOF' service ipsec start service xl2tpd start echo 1 > /proc/sys/net/ipv4/ip_forward exit 0 EOF + if grep -qs raspbian /etc/os-release; then + sed --follow-symlinks -i '/hwdsl2 VPN script/a sleep 15' /etc/rc.local + fi fi # Reload sysctl.conf diff --git a/vpnsetup_centos.sh b/vpnsetup_centos.sh index e14feec..e1db0bd 100755 --- a/vpnsetup_centos.sh +++ b/vpnsetup_centos.sh @@ -44,16 +44,14 @@ check_ip() { printf %s "${1}" | tr -d '\n' | grep -Eq "$IP_REGEX" } -if [ ! -f /etc/redhat-release ]; then - exiterr "This script only supports CentOS/RHEL." -fi - if ! grep -qs -e "release 6" -e "release 7" /etc/redhat-release; then exiterr "This script only supports CentOS/RHEL 6 and 7." fi if [ -f /proc/user_beancounters ]; then - exiterr "This script does not support OpenVZ VPS." + echo "Error: This script does not support OpenVZ VPS." >&2 + echo "Try OpenVPN: https://github.com/Nyr/openvpn-install" >&2 + exit 1 fi if [ "$(id -u)" != 0 ]; then @@ -71,12 +69,9 @@ cat 1>&2 <<'EOF' DO NOT RUN THIS SCRIPT ON YOUR PC OR MAC! If running on a server, you may fix this error by first -finding the active network interface: -route | grep '^default' | grep -o '[^ ]*$' - -Then set this variable and re-run the script: -export VPN_IFACE="YOUR_INTERFACE" +setting this variable and re-run the script: +export VPN_IFACE="$(route | grep '^default' | grep -o '[^ ]*$')" EOF exit 1 fi @@ -380,7 +375,7 @@ if grep -qs "release 6" /etc/redhat-release; then else systemctl --now mask firewalld yum -y install iptables-services || exiterr2 - systemctl enable iptables fail2ban + systemctl enable iptables fail2ban >/dev/null 2>&1 fi if ! grep -qs "hwdsl2 VPN script" /etc/rc.local; then conf_bk "/etc/rc.local"