From d189d735e3d7d86aefb42fe7e9a072bcb19d2ae2 Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Tue, 4 Oct 2022 23:50:06 -0500 Subject: [PATCH] Improve IP check - Install iproute (for the "ip" command) in the unlikely cases that it is not already installed. - Abort and exit if server IP cannot be detected. - Cleanup --- openvpn-install.sh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/openvpn-install.sh b/openvpn-install.sh index 884aa55..8007d46 100644 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -115,7 +115,7 @@ new_client() { show_header() { cat <<'EOF' -OpenVPN Script 3 Oct 2022 +OpenVPN Script https://github.com/hwdsl2/openvpn-install EOF } @@ -260,6 +260,25 @@ if [[ ! -e /etc/openvpn/server/server.conf ]]; then apt-get -yqq install wget >/dev/null ) || exit 1 fi + if ! hash ip 2>/dev/null; then + if [ "$auto" = 0 ]; then + echo "iproute is required to use this installer." + read -n1 -r -p "Press any key to install iproute and continue..." + fi + if [ "$os" = "debian" ] || [ "$os" = "ubuntu" ]; then + export DEBIAN_FRONTEND=noninteractive + ( + set -x + apt-get -yqq update || apt-get -yqq update + apt-get -yqq install iproute2 >/dev/null + ) || exit 1 + else + ( + set -x + yum -y -q install iproute >/dev/null + ) || exit 1 + fi + fi if [ "$auto" = 0 ]; then echo echo 'Welcome to this OpenVPN server installer!' @@ -309,6 +328,11 @@ if [[ ! -e /etc/openvpn/server/server.conf ]]; then fi fi fi + if ! check_ip "$ip"; then + echo "Error: Could not detect this server's IP address." >&2 + echo "Abort. No changes were made." >&2 + exit 1 + fi # If $ip is a private IP address, the server must be behind NAT if printf '%s' "$ip" | grep -qE '^(10|127|172\.(1[6-9]|2[0-9]|3[0-1])|192\.168|169\.254)\.'; then find_public_ip