From 2a35a3db16cb45e6c1d53f3def81f3a029c14f97 Mon Sep 17 00:00:00 2001 From: Henry N Date: Mon, 27 Apr 2020 16:24:30 +0200 Subject: [PATCH] refactor(install): simplify detection of public IP4, add fallback to IPv6 (#589) --- openvpn-install.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openvpn-install.sh b/openvpn-install.sh index 4b1479f..0354bc3 100755 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -208,7 +208,11 @@ function installQuestions() { echo "Unless your server is behind NAT, it should be your public IPv4 address." # Detect public IPv4 address and pre-fill for the user - IP=$(ip addr | grep 'inet' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1) + IP=$(ip -4 addr | sed -ne 's|^.* inet \([^/]*\)/.* scope global.*$|\1|p' | head -1) + if [[ -z "$IP" ]]; then + # Detect public IPv6 address + IP=$(ip -6 addr | sed -ne 's|^.* inet6 \([^/]*\)/.* scope global.*$|\1|p' | head -1) + fi APPROVE_IP=${APPROVE_IP:-n} if [[ $APPROVE_IP =~ n ]]; then read -rp "IP address: " -e -i "$IP" IP