From 7c933b10d52170495c73591c633ac47b2af4fec5 Mon Sep 17 00:00:00 2001 From: gunix Date: Fri, 25 Sep 2020 01:28:57 +0300 Subject: [PATCH] improved output and comments for better user experience --- get_region_and_token.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/get_region_and_token.sh b/get_region_and_token.sh index 6cca76a..f9e5057 100755 --- a/get_region_and_token.sh +++ b/get_region_and_token.sh @@ -76,8 +76,8 @@ fi # Notify the user that we got the server list. echo "OK!" -# Test one server from each region to get the closest region -# Only filter port forwarding enabled servers if specified +# Test one server from each region to get the closest region. +# If port forwarding is enabled, filter out regions that don't support it. if [[ $PIA_PF == "true" ]]; then echo Port Forwarding is enabled, so regions that do not support echo port forwarding will get filtered out. @@ -95,6 +95,14 @@ bestRegion="$(echo "$summarized_region_data" | xargs -i bash -c 'printServerLatency {}' | sort | head -1 | awk '{ print $2 }')" +if [ -z "$bestRegion" ]; then + echo ... + echo No region responded within ${MAX_LATENCY}s, consider using a higher timeout. + echo For example, to wait 1 second for each region, inject MAX_LATENCY=1 like this: + echo $ MAX_LATENCY=1 ./get_region_and_token.sh + exit 1 +fi + # Get all data for the best region regionData="$( echo $all_region_data | jq --arg REGION_ID "$bestRegion" -r \ @@ -160,8 +168,9 @@ echo "This token will expire in 24 hours. if [ "$PIA_AUTOCONNECT" != wireguard ]; then echo If you wish to automatically connect to WireGuard after detecting the best - echo region, please run the script with the env var PIA_AUTOCONNECT=wireguard. You can - echo also specify the env var PIA_PF=true to get port forwarding. Example: + echo region, please run the script with the env var PIA_AUTOCONNECT=wireguard. + echo You can echo also specify the env var PIA_PF=true to get port forwarding. + echo Example: echo $ PIA_USER=p0123456 PIA_PASS=xxx \ PIA_AUTOCONNECT=true PIA_PF=true ./sort_regions_by_latency.sh echo @@ -175,8 +184,9 @@ if [ "$PIA_PF" != true ]; then PIA_PF="false" fi -echo "The ./get_region_and_token.sh script got started with PIA_AUTOCONNECT=wireguard, -so we will automatically connect to WireGuard, by running this command: +echo "The ./get_region_and_token.sh script got started with +PIA_AUTOCONNECT=wireguard, so we will automatically connect to WireGuard, +by running this command: $ WG_TOKEN=\"$token\" \\ WG_SERVER_IP=$bestServer_WG_IP WG_HOSTNAME=$bestServer_WG_hostname \\ PIA_PF=$PIA_PF ./connect_to_wireguard_with_token.sh