From 65213b975586c6009dc9d2e314ed3dbe6420dfc2 Mon Sep 17 00:00:00 2001 From: Ross Hettel Date: Tue, 20 Dec 2016 15:26:21 -0600 Subject: [PATCH 1/2] added more robust error handling around checking for new port from PIA --- transmission/updatePort.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/transmission/updatePort.sh b/transmission/updatePort.sh index d56e76fb0..9cbb266c2 100755 --- a/transmission/updatePort.sh +++ b/transmission/updatePort.sh @@ -31,10 +31,27 @@ if [ -z ${pia_client_id} ]; then fi # Get the port -pia_response=$(curl -d "user=$pia_username&pass=$pia_passwd&client_id=$pia_client_id&local_ip=$local_vpn_ip" $port_assignment_url) +pia_response=$(curl -s -f -d "user=$pia_username&pass=$pia_passwd&client_id=$pia_client_id&local_ip=$local_vpn_ip" $port_assignment_url) +# Check for curl error (curl will fail on HTTP errors with -f flag) +if [ $? -ne 0 ]; then + echo "Encountered an error looking up new port: $?" +fi + +# Check for errors in PIA response +error=$(echo $pia_response | grep -oE "\"error\".*\"") +if [ ! -z "$error" ]; then + echo "PIA returned an error: $error" + exit +fi + +# Get new port, check if empty new_port=$(echo $pia_response | grep -oE "[0-9]+") -echo "Got new port $new_port from pia" +if [ -z "$new_port" ]; then + echo "Could not find new port from PIA" + exit +fi +echo "Got new port $new_port from PIA" # # Now, set port in Transmission @@ -61,4 +78,3 @@ if [ "$new_port" != "$transmission_peer_port" ] else echo "No action needed, port hasn't changed" fi - From 9e634a70dac66e807d7d6e1a95e2c9f43cfcdd9d Mon Sep 17 00:00:00 2001 From: Ross Hettel Date: Wed, 21 Dec 2016 09:45:54 -0600 Subject: [PATCH 2/2] change logging --- transmission/updatePort.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/transmission/updatePort.sh b/transmission/updatePort.sh index 9cbb266c2..1af6b15e3 100755 --- a/transmission/updatePort.sh +++ b/transmission/updatePort.sh @@ -34,8 +34,9 @@ fi pia_response=$(curl -s -f -d "user=$pia_username&pass=$pia_passwd&client_id=$pia_client_id&local_ip=$local_vpn_ip" $port_assignment_url) # Check for curl error (curl will fail on HTTP errors with -f flag) -if [ $? -ne 0 ]; then - echo "Encountered an error looking up new port: $?" +ret=$? +if [ $ret -ne 0 ]; then + echo "curl encountered an error looking up new port: $ret" fi # Check for errors in PIA response