diff --git a/README.md b/README.md index e6c70c1..9663944 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ In order to help you use VPN services and PF on any device, we have prepared a f The easiest way to trigger a fully automated connection is by running this oneliner: ``` -sudo VPN_PROTOCOL=wireguard DISABLE_IPV6="no" AUTOCONNECT=true PIA_PF=false PIA_USER=p0123456 PIA_PASS=xxxxxxxx ./run_setup.sh +sudo VPN_PROTOCOL=wireguard DISABLE_IPV6=yes DIP_TOKEN=no AUTOCONNECT=true PIA_PF=false PIA_DNS=true PIA_USER=p0123456 PIA_PASS=xxxxxxxx ./run_setup.sh ``` Here is a list of scripts you could find useful: @@ -100,6 +100,7 @@ Here is a list of scripts you could find useful: * `DISABLE_IPV6` - yes/no * [Get region details](get_region.sh): This script will provide server details, validate `PREFERRED_REGION` input, and can determine the lowest latency location. The script can also trigger VPN connections, if you specify `VPN_PROTOCOL=wireguard` or `VPN_PROTOCOL=openvpn`; doing so requires a token. This script can reference `get_token.sh` with use of `PIA_USER` and `PIA_PASS`. If called without specifying `PREFERRED_REGION` this script writes a list of servers within lower than `MAX_LATENCY` to a `/opt/piavpn-manual/latencyList` for reference. * [Get a token](get_token.sh): This script allows you to get an authentication token with a valid 'PIA_USER' and 'PIA_PASS'. It will write the token and its expiration date to `/opt/piavpn-manual/token` for reference. + * [Get DIP details](get_dip.sh): This script will provide necessary connection details to use a dedicated IP. * [Connect to WireGuard](connect_to_wireguard_with_token.sh): This script allows you to connect to the VPN server via WireGuard. * [Connect to OpenVPN](connect_to_openvpn_with_token.sh): This script allows you to connect to the VPN server via OpenVPN. * [Enable Port Forwarding](port_forwarding.sh): Enables you to add Port Forwarding to an existing VPN connection. Adding the environment variable `PIA_PF=true` to any of the previous scripts will also trigger this script. diff --git a/get_dip.sh b/get_dip.sh index cb58932..1610aed 100755 --- a/get_dip.sh +++ b/get_dip.sh @@ -64,7 +64,6 @@ fi dipSavedLocation=/opt/piavpn-manual/dipAddress -echo echo -n "Checking DIP token..." generateDIPResponse=$(curl -s --location --request POST \ diff --git a/run_setup.sh b/run_setup.sh index 9afa5a2..f92f961 100755 --- a/run_setup.sh +++ b/run_setup.sh @@ -117,21 +117,33 @@ while :; do fi done -# Check for dedicated IP -echo -n "Do you want to use a dedicated IP token ([N]o/[y]es): " -read useDIP -echo -pfOption="true" +# Check for in-line definition of $DIP_TOKEN +if [[ -z $DIP_TOKEN ]]; then + # Check for dedicated IP + echo -n "Do you want to use a dedicated IP token ([N]o/[y]es): " + read useDIP + echo + pfOption="true" +else + if echo ${DIP_TOKEN:0:1} | grep -iq n; then + useDIP="no" + echo -e "${red}Not using a dedicated IP.${nc}" + echo + DIP_TOKEN="" + else + useDIP="yes" + fi +fi + if echo ${useDIP:0:1} | grep -iq y; then -useDIP="true" + useDIP="true" while :; do while :; do # Check for in-line definition of $DIP_TOKEN if [[ -z $DIP_TOKEN ]]; then read -p "Dedicated token (DIP#############################): " DIP_TOKEN fi - - # Confirm format of PIA_USER input + # Confirm format of DIP_TOKEN input dipPrefix=$( echo ${DIP_TOKEN:0:3} ) if [[ -z "$DIP_TOKEN" ]]; then echo -e "\n${red}You must provide input.${nc}" @@ -142,32 +154,39 @@ useDIP="true" else break fi + echo DIP_TOKEN="" done export DIP_TOKEN - # Confirm DIP_TOKEN and retrieve connection details ./get_dip.sh - dipDetails="/opt/piavpn-manual/dipAddress" # If the script failed to generate retrieve dedicated IP information, the script will exit early. - if [ ! -f "$dipDetails" ]; then - read -p "Do you want to try again ([N]o/[y]es): " tryAgain - if ! echo ${tryAgain:0:1} | grep -iq y; then - exit 1 + if [ ! -f "$dipDetails" ]; then + read -p "Do you want to try again ([N]o/[y]es): " tryAgain + echo + if ! echo ${tryAgain:0:1} | grep -iq y; then + exit 1 + fi + DIP_TOKEN="" + else + dipAddress=$( awk 'NR == 1' /opt/piavpn-manual/dipAddress ) + dipHostname=$( awk 'NR == 2' /opt/piavpn-manual/dipAddress) + dipKey=$( awk 'NR == 3' /opt/piavpn-manual/dipAddress ) + pfOption=$( awk 'NR == 5' /opt/piavpn-manual/dipAddress ) + rm -f /opt/piavpn-manual/dipAddress + break fi - DIP_TOKEN="" - else - dipAddress=$( awk 'NR == 1' /opt/piavpn-manual/dipAddress ) - dipHostname=$( awk 'NR == 2' /opt/piavpn-manual/dipAddress) - dipKey=$( awk 'NR == 3' /opt/piavpn-manual/dipAddress ) - pfOption=$( awk 'NR == 5' /opt/piavpn-manual/dipAddress ) - rm -f /opt/piavpn-manual/dipAddress - break - fi done fi +if [[ -z $DIP_TOKEN ]]; then + echo "${green}DIP_TOKEN=none${nc}" +else + echo "${green}DIP_TOKEN=$DIP_TOKEN${nc}" +fi +echo + # Erase previous connection details if present rm -f /opt/piavpn-manual/token /opt/piavpn-manual/latencyList @@ -328,7 +347,7 @@ if [[ -z $DIP_TOKEN ]]; then location3=$( awk 'NR == '$i' {print $6}' /opt/piavpn-manual/latencyList ) location4=$( awk 'NR == '$i' {print $7}' /opt/piavpn-manual/latencyList ) location="$location1 $location2 $location3 $location4" - printf "%3s : %-8s %-15s %17s" $i "$time" "$ip" "$id" + printf "%3s : %-8s %-15s %23s" $i "$time" "$ip" "$id" echo " - $location" done < /opt/piavpn-manual/latencyList echo