From 051f086646eb6256b80ca4406a8a4c7829b6f349 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Sat, 7 Mar 2026 09:31:15 -0500 Subject: [PATCH] testing --- piawg.sh | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/piawg.sh b/piawg.sh index eeb497b..207bcd6 100755 --- a/piawg.sh +++ b/piawg.sh @@ -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,21 @@ 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 + 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 + if check_tunnel; then + info "New tunnel on $OPN_IF is working" + else + err "New tunnel on $OPN_IF is broken" + fi fi fi