Skip to content

Commit b02d196

Browse files
committed
Improve IPv6 check
1 parent d9333fa commit b02d196

9 files changed

Lines changed: 17 additions & 21 deletions

extras/vpnupgrade.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# The latest version of this script is available at:
77
# https://github.com/hwdsl2/setup-ipsec-vpn
88
#
9-
# Copyright (C) 2021-2025 Lin Song <linsongui@gmail.com>
9+
# Copyright (C) 2021-2026 Lin Song <linsongui@gmail.com>
1010
#
1111
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
1212
# Unported License: http://creativecommons.org/licenses/by-sa/3.0/

extras/vpnupgrade_alpine.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# The latest version of this script is available at:
66
# https://github.com/hwdsl2/setup-ipsec-vpn
77
#
8-
# Copyright (C) 2021-2025 Lin Song <linsongui@gmail.com>
8+
# Copyright (C) 2021-2026 Lin Song <linsongui@gmail.com>
99
#
1010
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
1111
# Unported License: http://creativecommons.org/licenses/by-sa/3.0/

extras/vpnupgrade_amzn.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# The latest version of this script is available at:
66
# https://github.com/hwdsl2/setup-ipsec-vpn
77
#
8-
# Copyright (C) 2020-2025 Lin Song <linsongui@gmail.com>
8+
# Copyright (C) 2020-2026 Lin Song <linsongui@gmail.com>
99
#
1010
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
1111
# Unported License: http://creativecommons.org/licenses/by-sa/3.0/

extras/vpnupgrade_centos.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# The latest version of this script is available at:
66
# https://github.com/hwdsl2/setup-ipsec-vpn
77
#
8-
# Copyright (C) 2016-2025 Lin Song <linsongui@gmail.com>
8+
# Copyright (C) 2016-2026 Lin Song <linsongui@gmail.com>
99
#
1010
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
1111
# Unported License: http://creativecommons.org/licenses/by-sa/3.0/

extras/vpnupgrade_ubuntu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# The latest version of this script is available at:
66
# https://github.com/hwdsl2/setup-ipsec-vpn
77
#
8-
# Copyright (C) 2016-2025 Lin Song <linsongui@gmail.com>
8+
# Copyright (C) 2016-2026 Lin Song <linsongui@gmail.com>
99
#
1010
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
1111
# Unported License: http://creativecommons.org/licenses/by-sa/3.0/

vpnsetup_alpine.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,10 @@ detect_ipv6() {
200200
fi
201201
if [ -n "$VPN_PUBLIC_IP6" ]; then
202202
ip6="$VPN_PUBLIC_IP6"
203-
check_ip6 "$ip6" || exiterr "Invalid IPv6 address. Check variable 'VPN_PUBLIC_IP6'."
204-
else
205-
ip6_addr=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
206-
[ -n "$ip6_addr" ] && ip6="$ip6_addr"
203+
check_ip6 "$ip6" || { echo "Warning: Invalid IPv6 address in 'VPN_PUBLIC_IP6'. Detecting IPv6..." >&2; ip6=""; }
207204
fi
205+
[ -z "$ip6" ] && ip6=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
206+
check_ip6 "$ip6" || ip6=""
208207
}
209208

210209
install_vpn_pkgs() {

vpnsetup_amzn.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,10 @@ detect_ipv6() {
187187
fi
188188
if [ -n "$VPN_PUBLIC_IP6" ]; then
189189
ip6="$VPN_PUBLIC_IP6"
190-
check_ip6 "$ip6" || exiterr "Invalid IPv6 address. Check variable 'VPN_PUBLIC_IP6'."
191-
else
192-
ip6_addr=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
193-
[ -n "$ip6_addr" ] && ip6="$ip6_addr"
190+
check_ip6 "$ip6" || { echo "Warning: Invalid IPv6 address in 'VPN_PUBLIC_IP6'. Detecting IPv6..." >&2; ip6=""; }
194191
fi
192+
[ -z "$ip6" ] && ip6=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
193+
check_ip6 "$ip6" || ip6=""
195194
}
196195

197196
add_epel_repo() {

vpnsetup_centos.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,10 @@ detect_ipv6() {
241241
fi
242242
if [ -n "$VPN_PUBLIC_IP6" ]; then
243243
ip6="$VPN_PUBLIC_IP6"
244-
check_ip6 "$ip6" || exiterr "Invalid IPv6 address. Check variable 'VPN_PUBLIC_IP6'."
245-
else
246-
ip6_addr=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
247-
[ -n "$ip6_addr" ] && ip6="$ip6_addr"
244+
check_ip6 "$ip6" || { echo "Warning: Invalid IPv6 address in 'VPN_PUBLIC_IP6'. Detecting IPv6..." >&2; ip6=""; }
248245
fi
246+
[ -z "$ip6" ] && ip6=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
247+
check_ip6 "$ip6" || ip6=""
249248
}
250249

251250
add_epel_repo() {

vpnsetup_ubuntu.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,10 @@ detect_ipv6() {
265265
fi
266266
if [ -n "$VPN_PUBLIC_IP6" ]; then
267267
ip6="$VPN_PUBLIC_IP6"
268-
check_ip6 "$ip6" || exiterr "Invalid IPv6 address. Check variable 'VPN_PUBLIC_IP6'."
269-
else
270-
ip6_addr=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
271-
[ -n "$ip6_addr" ] && ip6="$ip6_addr"
268+
check_ip6 "$ip6" || { echo "Warning: Invalid IPv6 address in 'VPN_PUBLIC_IP6'. Detecting IPv6..." >&2; ip6=""; }
272269
fi
270+
[ -z "$ip6" ] && ip6=$(ip -6 addr 2>/dev/null | awk '/inet6 [23]/ {print $2}' | cut -d'/' -f1 | head -n1)
271+
check_ip6 "$ip6" || ip6=""
273272
}
274273

275274
install_vpn_pkgs() {

0 commit comments

Comments
 (0)