From d182d9651a7afa1d72818aff9a22071ac6c56aed Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Sun, 13 Mar 2022 15:03:28 -0500 Subject: [PATCH] Improve VPN setup - Download the add/delete VPN user helper scripts during setup, so users can use them directly without manual download. --- vpnsetup_alpine.sh | 32 ++++++++++++++++++++------------ vpnsetup_amzn.sh | 32 ++++++++++++++++++++------------ vpnsetup_centos.sh | 32 ++++++++++++++++++++------------ vpnsetup_ubuntu.sh | 32 ++++++++++++++++++++------------ 4 files changed, 80 insertions(+), 48 deletions(-) diff --git a/vpnsetup_alpine.sh b/vpnsetup_alpine.sh index 947c9ea..ec28d64 100755 --- a/vpnsetup_alpine.sh +++ b/vpnsetup_alpine.sh @@ -191,6 +191,25 @@ install_fail2ban() { ) || exiterr2 } +get_helper_scripts() { + bigecho "Downloading helper scripts..." + base_url="https://github.com/hwdsl2/setup-ipsec-vpn/raw/master/extras" + ikev2_url="$base_url/ikev2setup.sh" + add_url="$base_url/add_vpn_user.sh" + del_url="$base_url/del_vpn_user.sh" + cd /opt/src || exit 1 + for sc in ikev2.sh addvpnuser.sh delvpnuser.sh; do + [ "$sc" = "ikev2.sh" ] && dl_url="$ikev2_url" + [ "$sc" = "addvpnuser.sh" ] && dl_url="$add_url" + [ "$sc" = "delvpnuser.sh" ] && dl_url="$del_url" + ( + set -x + wget -t 3 -T 30 -q -O "$sc" "$dl_url" + ) || /bin/rm -f "$sc" + [ -s "$sc" ] && chmod +x "$sc" && ln -s "/opt/src/$sc" /usr/bin 2>/dev/null + done +} + get_swan_ver() { SWAN_VER=4.6 base_url="https://github.com/hwdsl2/vpn-extras/releases/download/v1.0.0" @@ -261,17 +280,6 @@ EOF fi } -get_ikev2_script() { - bigecho "Downloading IKEv2 script..." - cd /opt/src || exit 1 - ikev2_url="https://github.com/hwdsl2/setup-ipsec-vpn/raw/master/extras/ikev2setup.sh" - ( - set -x - wget -t 3 -T 30 -q -O ikev2.sh "$ikev2_url" - ) || /bin/rm -f ikev2.sh - [ -s ikev2.sh ] && chmod +x ikev2.sh && ln -s /opt/src/ikev2.sh /usr/bin 2>/dev/null -} - create_vpn_config() { bigecho "Creating VPN configuration..." @@ -555,7 +563,7 @@ vpnsetup() { detect_ip install_vpn_pkgs install_fail2ban - get_ikev2_script + get_helper_scripts get_libreswan install_libreswan create_vpn_config diff --git a/vpnsetup_amzn.sh b/vpnsetup_amzn.sh index 7ec74e7..3fa922f 100755 --- a/vpnsetup_amzn.sh +++ b/vpnsetup_amzn.sh @@ -191,6 +191,25 @@ install_fail2ban() { ) || exiterr2 } +get_helper_scripts() { + bigecho "Downloading helper scripts..." + base_url="https://github.com/hwdsl2/setup-ipsec-vpn/raw/master/extras" + ikev2_url="$base_url/ikev2setup.sh" + add_url="$base_url/add_vpn_user.sh" + del_url="$base_url/del_vpn_user.sh" + cd /opt/src || exit 1 + for sc in ikev2.sh addvpnuser.sh delvpnuser.sh; do + [ "$sc" = "ikev2.sh" ] && dl_url="$ikev2_url" + [ "$sc" = "addvpnuser.sh" ] && dl_url="$add_url" + [ "$sc" = "delvpnuser.sh" ] && dl_url="$del_url" + ( + set -x + wget -t 3 -T 30 -q -O "$sc" "$dl_url" + ) || /bin/rm -f "$sc" + [ -s "$sc" ] && chmod +x "$sc" && ln -s "/opt/src/$sc" /usr/bin 2>/dev/null + done +} + get_swan_ver() { SWAN_VER=4.6 base_url="https://github.com/hwdsl2/vpn-extras/releases/download/v1.0.0" @@ -263,17 +282,6 @@ EOF fi } -get_ikev2_script() { - bigecho "Downloading IKEv2 script..." - cd /opt/src || exit 1 - ikev2_url="https://github.com/hwdsl2/setup-ipsec-vpn/raw/master/extras/ikev2setup.sh" - ( - set -x - wget -t 3 -T 30 -q -O ikev2.sh "$ikev2_url" - ) || /bin/rm -f ikev2.sh - [ -s ikev2.sh ] && chmod +x ikev2.sh && ln -s /opt/src/ikev2.sh /usr/bin 2>/dev/null -} - create_vpn_config() { bigecho "Creating VPN configuration..." @@ -584,7 +592,7 @@ vpnsetup() { install_vpn_pkgs_1 install_vpn_pkgs_2 install_fail2ban - get_ikev2_script + get_helper_scripts get_libreswan install_libreswan create_vpn_config diff --git a/vpnsetup_centos.sh b/vpnsetup_centos.sh index 640b7ec..785df2c 100755 --- a/vpnsetup_centos.sh +++ b/vpnsetup_centos.sh @@ -251,6 +251,25 @@ install_fail2ban() { ) || exiterr2 } +get_helper_scripts() { + bigecho "Downloading helper scripts..." + base_url="https://github.com/hwdsl2/setup-ipsec-vpn/raw/master/extras" + ikev2_url="$base_url/ikev2setup.sh" + add_url="$base_url/add_vpn_user.sh" + del_url="$base_url/del_vpn_user.sh" + cd /opt/src || exit 1 + for sc in ikev2.sh addvpnuser.sh delvpnuser.sh; do + [ "$sc" = "ikev2.sh" ] && dl_url="$ikev2_url" + [ "$sc" = "addvpnuser.sh" ] && dl_url="$add_url" + [ "$sc" = "delvpnuser.sh" ] && dl_url="$del_url" + ( + set -x + wget -t 3 -T 30 -q -O "$sc" "$dl_url" + ) || /bin/rm -f "$sc" + [ -s "$sc" ] && chmod +x "$sc" && ln -s "/opt/src/$sc" /usr/bin 2>/dev/null + done +} + get_swan_ver() { SWAN_VER=4.6 base_url="https://github.com/hwdsl2/vpn-extras/releases/download/v1.0.0" @@ -323,17 +342,6 @@ EOF fi } -get_ikev2_script() { - bigecho "Downloading IKEv2 script..." - cd /opt/src || exit 1 - ikev2_url="https://github.com/hwdsl2/setup-ipsec-vpn/raw/master/extras/ikev2setup.sh" - ( - set -x - wget -t 3 -T 30 -q -O ikev2.sh "$ikev2_url" - ) || /bin/rm -f ikev2.sh - [ -s ikev2.sh ] && chmod +x ikev2.sh && ln -s /opt/src/ikev2.sh /usr/bin 2>/dev/null -} - create_vpn_config() { bigecho "Creating VPN configuration..." @@ -702,7 +710,7 @@ vpnsetup() { install_vpn_pkgs_2 install_vpn_pkgs_3 install_fail2ban - get_ikev2_script + get_helper_scripts get_libreswan install_libreswan create_vpn_config diff --git a/vpnsetup_ubuntu.sh b/vpnsetup_ubuntu.sh index 7eac4b9..4fad926 100755 --- a/vpnsetup_ubuntu.sh +++ b/vpnsetup_ubuntu.sh @@ -231,6 +231,25 @@ install_fail2ban() { ) || exiterr2 } +get_helper_scripts() { + bigecho "Downloading helper scripts..." + base_url="https://github.com/hwdsl2/setup-ipsec-vpn/raw/master/extras" + ikev2_url="$base_url/ikev2setup.sh" + add_url="$base_url/add_vpn_user.sh" + del_url="$base_url/del_vpn_user.sh" + cd /opt/src || exit 1 + for sc in ikev2.sh addvpnuser.sh delvpnuser.sh; do + [ "$sc" = "ikev2.sh" ] && dl_url="$ikev2_url" + [ "$sc" = "addvpnuser.sh" ] && dl_url="$add_url" + [ "$sc" = "delvpnuser.sh" ] && dl_url="$del_url" + ( + set -x + wget -t 3 -T 30 -q -O "$sc" "$dl_url" + ) || /bin/rm -f "$sc" + [ -s "$sc" ] && chmod +x "$sc" && ln -s "/opt/src/$sc" /usr/bin 2>/dev/null + done +} + get_swan_ver() { SWAN_VER=4.6 base_url="https://github.com/hwdsl2/vpn-extras/releases/download/v1.0.0" @@ -311,17 +330,6 @@ EOF fi } -get_ikev2_script() { - bigecho "Downloading IKEv2 script..." - cd /opt/src || exit 1 - ikev2_url="https://github.com/hwdsl2/setup-ipsec-vpn/raw/master/extras/ikev2setup.sh" - ( - set -x - wget -t 3 -T 30 -q -O ikev2.sh "$ikev2_url" - ) || /bin/rm -f ikev2.sh - [ -s ikev2.sh ] && chmod +x ikev2.sh && ln -s /opt/src/ikev2.sh /usr/bin 2>/dev/null -} - create_vpn_config() { bigecho "Creating VPN configuration..." @@ -687,7 +695,7 @@ vpnsetup() { detect_ip install_vpn_pkgs install_fail2ban - get_ikev2_script + get_helper_scripts get_libreswan install_libreswan create_vpn_config