This commit is contained in:
2026-03-07 09:35:43 -05:00
parent cef327aa59
commit 987deb9eae

View File

@@ -5,15 +5,10 @@
# Allow local variable scoping, therefore not strictly POSIX
# shellcheck disable=SC3043
err() {
printf '[ERROR]: %s\n' "$1" >&2
exit 1
}
info() {
[ "$PIAWG_VERBOSE" -eq 1 ] &&
printf '[INFO]: %s\n' "$1" >&2
}
msg() { printf '[%s]: %s\n' "${2-INFO}" "$1"; }
info() { [ "$PIAWG_VERBOSE" -eq 1 ] && msg "$1"; }
warn() { msg "$1" 'WARN'; }
err() { msg "$1" 'ERROR'; exit 1; }
check_http() {
case $1 in
@@ -23,9 +18,7 @@ check_http() {
}
# Check for plausible looking PIA token
check_token() {
printf '%s\n' "$1" | grep -q '^[0-9A-Fa-f]\{128\}$'
}
check_token() { printf '%s\n' "$1" | grep -q '^[0-9A-Fa-f]\{128\}$'; }
_curl() {
curl -sS --connect-timeout 5 --max-time 20 \
@@ -157,7 +150,7 @@ pia_addkey() {
fi
}
tunnel_check() {
check_tunnel() {
local tunneladdr
local response
local peer_status
@@ -332,15 +325,25 @@ unset wg_reply
if [ "$server_ip" != "$piawgsrv_srvaddr" ]; then
info "Updating $OPN_IF tunnel with new IP $server_ip"
pia_addkey
if tunnel_check; then
info "Pausing 2 seconds for new tunnel"
sleep 2
if check_tunnel; then
info "New tunnel on $OPN_IF is working"
else
err "New tunnel on $OPN_IF is broken"
fi
else
if tunnel_check; then
if check_tunnel; then
info "Tunnel on $OPN_IF is working"
else
err "Tunnel on $OPN_IF is broken"
warn "Tunnel on $OPN_IF is broken"
pia_addkey
info "Pausing 2 seconds for new tunnel"
sleep 2
if check_tunnel; then
info "New tunnel on $OPN_IF is working"
else
err "New tunnel on $OPN_IF is broken"
fi
fi
fi