Improve IPv6 check

This commit is contained in:
hwdsl2
2026-03-18 22:14:04 -05:00
parent d9333fadc8
commit b02d196ad2
9 changed files with 17 additions and 21 deletions

View File

@@ -6,7 +6,7 @@
# The latest version of this script is available at: # The latest version of this script is available at:
# https://github.com/hwdsl2/setup-ipsec-vpn # https://github.com/hwdsl2/setup-ipsec-vpn
# #
# Copyright (C) 2021-2025 Lin Song <linsongui@gmail.com> # Copyright (C) 2021-2026 Lin Song <linsongui@gmail.com>
# #
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 # This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
# Unported License: http://creativecommons.org/licenses/by-sa/3.0/ # Unported License: http://creativecommons.org/licenses/by-sa/3.0/

View File

@@ -5,7 +5,7 @@
# The latest version of this script is available at: # The latest version of this script is available at:
# https://github.com/hwdsl2/setup-ipsec-vpn # https://github.com/hwdsl2/setup-ipsec-vpn
# #
# Copyright (C) 2021-2025 Lin Song <linsongui@gmail.com> # Copyright (C) 2021-2026 Lin Song <linsongui@gmail.com>
# #
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 # This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
# Unported License: http://creativecommons.org/licenses/by-sa/3.0/ # Unported License: http://creativecommons.org/licenses/by-sa/3.0/

View File

@@ -5,7 +5,7 @@
# The latest version of this script is available at: # The latest version of this script is available at:
# https://github.com/hwdsl2/setup-ipsec-vpn # https://github.com/hwdsl2/setup-ipsec-vpn
# #
# Copyright (C) 2020-2025 Lin Song <linsongui@gmail.com> # Copyright (C) 2020-2026 Lin Song <linsongui@gmail.com>
# #
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 # This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
# Unported License: http://creativecommons.org/licenses/by-sa/3.0/ # Unported License: http://creativecommons.org/licenses/by-sa/3.0/

View File

@@ -5,7 +5,7 @@
# The latest version of this script is available at: # The latest version of this script is available at:
# https://github.com/hwdsl2/setup-ipsec-vpn # https://github.com/hwdsl2/setup-ipsec-vpn
# #
# Copyright (C) 2016-2025 Lin Song <linsongui@gmail.com> # Copyright (C) 2016-2026 Lin Song <linsongui@gmail.com>
# #
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 # This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
# Unported License: http://creativecommons.org/licenses/by-sa/3.0/ # Unported License: http://creativecommons.org/licenses/by-sa/3.0/

View File

@@ -5,7 +5,7 @@
# The latest version of this script is available at: # The latest version of this script is available at:
# https://github.com/hwdsl2/setup-ipsec-vpn # https://github.com/hwdsl2/setup-ipsec-vpn
# #
# Copyright (C) 2016-2025 Lin Song <linsongui@gmail.com> # Copyright (C) 2016-2026 Lin Song <linsongui@gmail.com>
# #
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 # This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
# Unported License: http://creativecommons.org/licenses/by-sa/3.0/ # Unported License: http://creativecommons.org/licenses/by-sa/3.0/

View File

@@ -200,11 +200,10 @@ detect_ipv6() {
fi fi
if [ -n "$VPN_PUBLIC_IP6" ]; then if [ -n "$VPN_PUBLIC_IP6" ]; then
ip6="$VPN_PUBLIC_IP6" ip6="$VPN_PUBLIC_IP6"
check_ip6 "$ip6" || exiterr "Invalid IPv6 address. Check variable 'VPN_PUBLIC_IP6'." check_ip6 "$ip6" || { echo "Warning: Invalid IPv6 address in 'VPN_PUBLIC_IP6'. Detecting IPv6..." >&2; ip6=""; }
else
ip6_addr=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
[ -n "$ip6_addr" ] && ip6="$ip6_addr"
fi fi
[ -z "$ip6" ] && ip6=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
check_ip6 "$ip6" || ip6=""
} }
install_vpn_pkgs() { install_vpn_pkgs() {

View File

@@ -187,11 +187,10 @@ detect_ipv6() {
fi fi
if [ -n "$VPN_PUBLIC_IP6" ]; then if [ -n "$VPN_PUBLIC_IP6" ]; then
ip6="$VPN_PUBLIC_IP6" ip6="$VPN_PUBLIC_IP6"
check_ip6 "$ip6" || exiterr "Invalid IPv6 address. Check variable 'VPN_PUBLIC_IP6'." check_ip6 "$ip6" || { echo "Warning: Invalid IPv6 address in 'VPN_PUBLIC_IP6'. Detecting IPv6..." >&2; ip6=""; }
else
ip6_addr=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
[ -n "$ip6_addr" ] && ip6="$ip6_addr"
fi fi
[ -z "$ip6" ] && ip6=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
check_ip6 "$ip6" || ip6=""
} }
add_epel_repo() { add_epel_repo() {

View File

@@ -241,11 +241,10 @@ detect_ipv6() {
fi fi
if [ -n "$VPN_PUBLIC_IP6" ]; then if [ -n "$VPN_PUBLIC_IP6" ]; then
ip6="$VPN_PUBLIC_IP6" ip6="$VPN_PUBLIC_IP6"
check_ip6 "$ip6" || exiterr "Invalid IPv6 address. Check variable 'VPN_PUBLIC_IP6'." check_ip6 "$ip6" || { echo "Warning: Invalid IPv6 address in 'VPN_PUBLIC_IP6'. Detecting IPv6..." >&2; ip6=""; }
else
ip6_addr=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
[ -n "$ip6_addr" ] && ip6="$ip6_addr"
fi fi
[ -z "$ip6" ] && ip6=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
check_ip6 "$ip6" || ip6=""
} }
add_epel_repo() { add_epel_repo() {

View File

@@ -265,11 +265,10 @@ detect_ipv6() {
fi fi
if [ -n "$VPN_PUBLIC_IP6" ]; then if [ -n "$VPN_PUBLIC_IP6" ]; then
ip6="$VPN_PUBLIC_IP6" ip6="$VPN_PUBLIC_IP6"
check_ip6 "$ip6" || exiterr "Invalid IPv6 address. Check variable 'VPN_PUBLIC_IP6'." check_ip6 "$ip6" || { echo "Warning: Invalid IPv6 address in 'VPN_PUBLIC_IP6'. Detecting IPv6..." >&2; ip6=""; }
else
ip6_addr=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
[ -n "$ip6_addr" ] && ip6="$ip6_addr"
fi fi
[ -z "$ip6" ] && ip6=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
check_ip6 "$ip6" || ip6=""
} }
install_vpn_pkgs() { install_vpn_pkgs() {