unify quoting style for echo

This commit is contained in:
a1346054 2021-09-18 12:08:36 +00:00 committed by goonix
parent a534a3cc5f
commit a5bd8532be
6 changed files with 112 additions and 112 deletions

View File

@ -54,25 +54,25 @@ adapter_check=$( ip a s tun06 2>&1 )
should_read="Device \"tun06\" does not exist" should_read="Device \"tun06\" does not exist"
pid_filepath="/opt/piavpn-manual/pia_pid" pid_filepath="/opt/piavpn-manual/pia_pid"
if [[ $adapter_check != *"$should_read"* ]]; then if [[ $adapter_check != *"$should_read"* ]]; then
echo -e ${RED}The tun06 adapter already exists, that interface is required echo -e "${RED}The tun06 adapter already exists, that interface is required"
echo -e for this configuration.${NC} echo -e "for this configuration.${NC}"
if [[ -f $pid_filepath ]]; then if [[ -f $pid_filepath ]]; then
old_pid=$( cat "$pid_filepath" ) old_pid=$( cat "$pid_filepath" )
old_pid_name=$( ps -p "$old_pid" -o comm= ) old_pid_name=$( ps -p "$old_pid" -o comm= )
if [[ $old_pid_name == "openvpn" ]]; then if [[ $old_pid_name == "openvpn" ]]; then
echo echo
echo -e It seems likely that process ${RED}"$old_pid"${NC} is an OpenVPN connection echo -e "It seems likely that process ${RED}$old_pid${NC} is an OpenVPN connection"
echo that was established by using this script. Unless it is closed echo "that was established by using this script. Unless it is closed"
echo you would not be able to get a new connection. echo "you would not be able to get a new connection."
echo -ne "Do you want to run ${RED}$ kill $old_pid${NC} (Y/n): " echo -ne "Do you want to run ${RED}$ kill $old_pid${NC} (Y/n): "
read -r close_connection read -r close_connection
fi fi
if echo "${close_connection:0:1}" | grep -iq n; then if echo "${close_connection:0:1}" | grep -iq n; then
echo -e ${RED}Closing script. Resolve tun06 adapter conflict and run the script again. echo -e "${RED}Closing script. Resolve tun06 adapter conflict and run the script again."
exit 1 exit 1
fi fi
echo echo
echo -e ${GREEN}Killing the existing OpenVPN process and waiting 5 seconds...${NC} echo -e "${GREEN}Killing the existing OpenVPN process and waiting 5 seconds...${NC}"
kill "$old_pid" kill "$old_pid"
echo echo
for i in {5..1}; do for i in {5..1}; do
@ -92,9 +92,9 @@ if [[ -f /proc/net/if_inet6 ]] &&
[[ $(sysctl -n net.ipv6.conf.all.disable_ipv6) -ne 1 || [[ $(sysctl -n net.ipv6.conf.all.disable_ipv6) -ne 1 ||
$(sysctl -n net.ipv6.conf.default.disable_ipv6) -ne 1 ]] $(sysctl -n net.ipv6.conf.default.disable_ipv6) -ne 1 ]]
then then
echo -e ${RED}'You should consider disabling IPv6 by running:' echo -e "${RED}You should consider disabling IPv6 by running:"
echo 'sysctl -w net.ipv6.conf.all.disable_ipv6=1' echo "sysctl -w net.ipv6.conf.all.disable_ipv6=1"
echo -e 'sysctl -w net.ipv6.conf.default.disable_ipv6=1'${NC} echo -e "sysctl -w net.ipv6.conf.default.disable_ipv6=1${NC}"
fi fi
# Check if the mandatory environment variables are set. # Check if the mandatory environment variables are set.
@ -102,25 +102,25 @@ if [[ -z $OVPN_SERVER_IP ||
-z $OVPN_HOSTNAME || -z $OVPN_HOSTNAME ||
-z $PIA_TOKEN || -z $PIA_TOKEN ||
-z $CONNECTION_SETTINGS ]]; then -z $CONNECTION_SETTINGS ]]; then
echo -e ${RED}'This script requires 4 env vars:' echo -e "${RED}This script requires 4 env vars:"
echo 'PIA_TOKEN - the token used for authentication' echo "PIA_TOKEN - the token used for authentication"
echo 'OVPN_SERVER_IP - IP that you want to connect to' echo "OVPN_SERVER_IP - IP that you want to connect to"
echo 'OVPN_HOSTNAME - name of the server, required for ssl' echo "OVPN_HOSTNAME - name of the server, required for ssl"
echo 'CONNECTION_SETTINGS - the protocol and encryption specification' echo "CONNECTION_SETTINGS - the protocol and encryption specification"
echo ' - available options for CONNECTION_SETTINGS are:' echo " - available options for CONNECTION_SETTINGS are:"
echo ' * openvpn_udp_standard' echo " * openvpn_udp_standard"
echo ' * openvpn_udp_strong' echo " * openvpn_udp_strong"
echo ' * openvpn_tcp_standard' echo " * openvpn_tcp_standard"
echo ' * openvpn_tcp_strong' echo " * openvpn_tcp_strong"
echo echo
echo You can also specify optional env vars: echo "You can also specify optional env vars:"
echo "PIA_PF - enable port forwarding" echo "PIA_PF - enable port forwarding"
echo "PAYLOAD_AND_SIGNATURE - In case you already have a port." echo "PAYLOAD_AND_SIGNATURE - In case you already have a port."
echo echo
echo An easy solution is to just run get_region_and_token.sh echo "An easy solution is to just run get_region_and_token.sh"
echo as it will guide you through getting the best server and echo "as it will guide you through getting the best server and"
echo also a token. Detailed information can be found here: echo "also a token. Detailed information can be found here:"
echo -e https://github.com/pia-foss/manual-connections${NC} echo -e "https://github.com/pia-foss/manual-connections${NC}"
exit 1 exit 1
fi fi
@ -128,8 +128,8 @@ fi
echo -n "Trying to write /opt/piavpn-manual/pia.ovpn..." echo -n "Trying to write /opt/piavpn-manual/pia.ovpn..."
mkdir -p /opt/piavpn-manual mkdir -p /opt/piavpn-manual
rm -f /opt/piavpn-manual/credentials /opt/piavpn-manual/route_info rm -f /opt/piavpn-manual/credentials /opt/piavpn-manual/route_info
echo "${PIA_TOKEN:0:62}"" echo "${PIA_TOKEN:0:62}
""${PIA_TOKEN:62}" > /opt/piavpn-manual/credentials || exit 1 ${PIA_TOKEN:62}" > /opt/piavpn-manual/credentials || exit 1
chmod 600 /opt/piavpn-manual/credentials chmod 600 /opt/piavpn-manual/credentials
echo -e "${GREEN}OK!${NC}" echo -e "${GREEN}OK!${NC}"
@ -168,9 +168,9 @@ echo "remote $OVPN_SERVER_IP $port $protocol" >> /opt/piavpn-manual/pia.ovpn
if [[ $PIA_DNS != "true" ]]; then if [[ $PIA_DNS != "true" ]]; then
cp openvpn_config/openvpn_up.sh /opt/piavpn-manual/ cp openvpn_config/openvpn_up.sh /opt/piavpn-manual/
cp openvpn_config/openvpn_down.sh /opt/piavpn-manual/ cp openvpn_config/openvpn_down.sh /opt/piavpn-manual/
echo -e ${RED}This configuration will not use PIA DNS.${NC} echo -e "${RED}This configuration will not use PIA DNS.${NC}"
echo If you want to also enable PIA DNS, please start the script echo "If you want to also enable PIA DNS, please start the script"
echo with the env var PIA_DNS=true. Example: echo "with the env var PIA_DNS=true. Example:"
echo $ OVPN_SERVER_IP=\""$OVPN_SERVER_IP"\" OVPN_HOSTNAME=\""$OVPN_HOSTNAME"\" \ echo $ OVPN_SERVER_IP=\""$OVPN_SERVER_IP"\" OVPN_HOSTNAME=\""$OVPN_HOSTNAME"\" \
PIA_TOKEN=\""$PIA_TOKEN"\" CONNECTION_SETTINGS=\""$CONNECTION_SETTINGS"\" \ PIA_TOKEN=\""$PIA_TOKEN"\" CONNECTION_SETTINGS=\""$CONNECTION_SETTINGS"\" \
PIA_PF=true PIA_DNS=true ./connect_to_openvpn_with_token.sh PIA_PF=true PIA_DNS=true ./connect_to_openvpn_with_token.sh
@ -233,14 +233,14 @@ To disconnect the VPN, run:
# This section will stop the script if PIA_PF is not set to "true". # This section will stop the script if PIA_PF is not set to "true".
if [[ $PIA_PF != "true" ]]; then if [[ $PIA_PF != "true" ]]; then
echo If you want to also enable port forwarding, you can start the script: echo "If you want to also enable port forwarding, you can start the script:"
echo -e $ ${GREEN}PIA_TOKEN="$PIA_TOKEN" \ echo -e "$ ${GREEN}PIA_TOKEN=$PIA_TOKEN" \
PF_GATEWAY="$gateway_ip" \ "PF_GATEWAY=$gateway_ip" \
PF_HOSTNAME="$OVPN_HOSTNAME" \ "PF_HOSTNAME=$OVPN_HOSTNAME" \
./port_forwarding.sh${NC} "./port_forwarding.sh${NC}"
echo echo
echo The location used must be port forwarding enabled, or this will fail. echo "The location used must be port forwarding enabled, or this will fail."
echo Calling the ./get_region script with PIA_PF=true will provide a filtered list. echo "Calling the ./get_region script with PIA_PF=true will provide a filtered list."
exit 1 exit 1
fi fi

View File

@ -55,28 +55,28 @@ if [[ -f /proc/net/if_inet6 ]] &&
[[ $(sysctl -n net.ipv6.conf.all.disable_ipv6) -ne 1 || [[ $(sysctl -n net.ipv6.conf.all.disable_ipv6) -ne 1 ||
$(sysctl -n net.ipv6.conf.default.disable_ipv6) -ne 1 ]] $(sysctl -n net.ipv6.conf.default.disable_ipv6) -ne 1 ]]
then then
echo 'You should consider disabling IPv6 by running:' echo "You should consider disabling IPv6 by running:"
echo 'sysctl -w net.ipv6.conf.all.disable_ipv6=1' echo "sysctl -w net.ipv6.conf.all.disable_ipv6=1"
echo 'sysctl -w net.ipv6.conf.default.disable_ipv6=1' echo "sysctl -w net.ipv6.conf.default.disable_ipv6=1"
fi fi
# Check if the mandatory environment variables are set. # Check if the mandatory environment variables are set.
if [[ -z $WG_SERVER_IP || if [[ -z $WG_SERVER_IP ||
-z $WG_HOSTNAME || -z $WG_HOSTNAME ||
-z $PIA_TOKEN ]]; then -z $PIA_TOKEN ]]; then
echo -e ${RED}This script requires 3 env vars: echo -e "${RED}This script requires 3 env vars:"
echo WG_SERVER_IP - IP that you want to connect to echo "WG_SERVER_IP - IP that you want to connect to"
echo WG_HOSTNAME - name of the server, required for ssl echo "WG_HOSTNAME - name of the server, required for ssl"
echo PIA_TOKEN - your authentication token echo "PIA_TOKEN - your authentication token"
echo echo
echo You can also specify optional env vars: echo "You can also specify optional env vars:"
echo "PIA_PF - enable port forwarding" echo "PIA_PF - enable port forwarding"
echo "PAYLOAD_AND_SIGNATURE - In case you already have a port." echo "PAYLOAD_AND_SIGNATURE - In case you already have a port."
echo echo
echo An easy solution is to just run get_region_and_token.sh echo "An easy solution is to just run get_region_and_token.sh"
echo as it will guide you through getting the best server and echo "as it will guide you through getting the best server and"
echo also a token. Detailed information can be found here: echo "also a token. Detailed information can be found here:"
echo -e https://github.com/pia-foss/manual-connections${NC} echo -e "https://github.com/pia-foss/manual-connections${NC}"
exit 1 exit 1
fi fi
@ -92,7 +92,7 @@ export pubKey
# In case you didn't clone the entire repo, get the certificate from: # In case you didn't clone the entire repo, get the certificate from:
# https://github.com/pia-foss/manual-connections/blob/master/ca.rsa.4096.crt # https://github.com/pia-foss/manual-connections/blob/master/ca.rsa.4096.crt
# In case you want to troubleshoot the script, replace -s with -v. # In case you want to troubleshoot the script, replace -s with -v.
echo Trying to connect to the PIA WireGuard API on "$WG_SERVER_IP"... echo "Trying to connect to the PIA WireGuard API on $WG_SERVER_IP..."
wireguard_json="$(curl -s -G \ wireguard_json="$(curl -s -G \
--connect-to "$WG_HOSTNAME::$WG_SERVER_IP:" \ --connect-to "$WG_HOSTNAME::$WG_SERVER_IP:" \
--cacert "ca.rsa.4096.crt" \ --cacert "ca.rsa.4096.crt" \
@ -111,7 +111,7 @@ fi
# get multi-hop running with both WireGuard and OpenVPN by playing with # get multi-hop running with both WireGuard and OpenVPN by playing with
# these scripts. Feel free to fork the project and test it out. # these scripts. Feel free to fork the project and test it out.
echo echo
echo Trying to disable a PIA WG connection in case it exists... echo "Trying to disable a PIA WG connection in case it exists..."
wg-quick down pia && echo -e "${GREEN}\nPIA WG connection disabled!${NC}" wg-quick down pia && echo -e "${GREEN}\nPIA WG connection disabled!${NC}"
echo echo
@ -142,14 +142,14 @@ PublicKey = $(echo "$wireguard_json" | jq -r '.server_key')
AllowedIPs = 0.0.0.0/0 AllowedIPs = 0.0.0.0/0
Endpoint = ${WG_SERVER_IP}:$(echo "$wireguard_json" | jq -r '.server_port') Endpoint = ${WG_SERVER_IP}:$(echo "$wireguard_json" | jq -r '.server_port')
" > /etc/wireguard/pia.conf || exit 1 " > /etc/wireguard/pia.conf || exit 1
echo -e ${GREEN}OK!${NC} echo -e "${GREEN}OK!${NC}"
# Start the WireGuard interface. # Start the WireGuard interface.
# If something failed, stop this script. # If something failed, stop this script.
# If you get DNS errors because you miss some packages, # If you get DNS errors because you miss some packages,
# just hardcode /etc/resolv.conf to "nameserver 10.0.0.242". # just hardcode /etc/resolv.conf to "nameserver 10.0.0.242".
echo echo
echo Trying to create the wireguard interface... echo "Trying to create the wireguard interface..."
wg-quick up pia || exit 1 wg-quick up pia || exit 1
echo echo
echo -e "${GREEN}The WireGuard interface got created.${NC} echo -e "${GREEN}The WireGuard interface got created.${NC}
@ -163,14 +163,14 @@ To disconnect the VPN, run:
# This section will stop the script if PIA_PF is not set to "true". # This section will stop the script if PIA_PF is not set to "true".
if [[ $PIA_PF != "true" ]]; then if [[ $PIA_PF != "true" ]]; then
echo If you want to also enable port forwarding, you can start the script: echo "If you want to also enable port forwarding, you can start the script:"
echo -e $ ${GREEN}PIA_TOKEN="$PIA_TOKEN" \ echo -e "$ ${GREEN}PIA_TOKEN=$PIA_TOKEN" \
PF_GATEWAY="$WG_SERVER_IP" \ "PF_GATEWAY=$WG_SERVER_IP" \
PF_HOSTNAME="$WG_HOSTNAME" \ "PF_HOSTNAME=$WG_HOSTNAME" \
./port_forwarding.sh${NC} "./port_forwarding.sh${NC}"
echo echo
echo The location used must be port forwarding enabled, or this will fail. echo "The location used must be port forwarding enabled, or this will fail."
echo Calling the ./get_region script with PIA_PF=true will provide a filtered list. echo "Calling the ./get_region script with PIA_PF=true will provide a filtered list."
exit 1 exit 1
fi fi

View File

@ -147,7 +147,7 @@ if [[ $selectedRegion == "none" ]]; then
# Test one server from each region to get the closest region. # 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 port forwarding is enabled, filter out regions that don't support it.
if [[ $PIA_PF == "true" ]]; then if [[ $PIA_PF == "true" ]]; then
echo Port Forwarding is enabled, non-PF servers excluded. echo "Port Forwarding is enabled, non-PF servers excluded."
echo echo
summarized_region_data="$( echo "$all_region_data" | summarized_region_data="$( echo "$all_region_data" |
jq -r '.regions[] | select(.port_forward==true) | jq -r '.regions[] | select(.port_forward==true) |
@ -158,7 +158,7 @@ if [[ $selectedRegion == "none" ]]; then
.servers.meta[0].ip+" "+.id+" "+.name+" "+(.geo|tostring)' )" .servers.meta[0].ip+" "+.id+" "+.name+" "+(.geo|tostring)' )"
fi fi
echo -e Testing regions that respond \ echo -e Testing regions that respond \
faster than ${GREEN}"$MAX_LATENCY"${NC} seconds: faster than "${GREEN}$MAX_LATENCY${NC}" seconds:
selectedRegion="$(echo "$summarized_region_data" | selectedRegion="$(echo "$summarized_region_data" |
xargs -I{} bash -c 'printServerLatency {}' | xargs -I{} bash -c 'printServerLatency {}' |
sort | head -1 | awk '{ print $2 }')" sort | head -1 | awk '{ print $2 }')"
@ -166,8 +166,8 @@ if [[ $selectedRegion == "none" ]]; then
if [[ -z $selectedRegion ]]; then if [[ -z $selectedRegion ]]; then
echo -e "${RED}No region responded within ${MAX_LATENCY}s, consider using a higher timeout." echo -e "${RED}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 "For example, to wait 1 second for each region, inject MAX_LATENCY=1 like this:"
echo -e $ MAX_LATENCY=1 ./get_region.sh${NC} echo -e "$ MAX_LATENCY=1 ./get_region.sh${NC}"
exit 1 exit 1
else else
echo -e "A list of servers and connection details, ordered by latency can be echo -e "A list of servers and connection details, ordered by latency can be
@ -192,7 +192,7 @@ bestServer_OU_hostname=$(echo "$regionData" | jq -r '.servers.ovpnudp[0].cn')
if [[ $VPN_PROTOCOL == "no" ]]; then if [[ $VPN_PROTOCOL == "no" ]]; then
echo -ne The $selectedOrLowestLatency region is ${GREEN}"$(echo "$regionData" | jq -r '.name')"${NC} echo -ne "The $selectedOrLowestLatency region is ${GREEN}$(echo "$regionData" | jq -r '.name')${NC}"
if echo "$regionData" | jq -r '.geo' | grep true > /dev/null; then if echo "$regionData" | jq -r '.geo' | grep true > /dev/null; then
echo " (geolocated region)." echo " (geolocated region)."
else else
@ -216,9 +216,9 @@ fi
# If no token exists, the script will check for login credentials to generate one # If no token exists, the script will check for login credentials to generate one
if [[ -z $PIA_TOKEN ]]; then if [[ -z $PIA_TOKEN ]]; then
if [[ -z $PIA_USER || -z $PIA_PASS ]]; then if [[ -z $PIA_USER || -z $PIA_PASS ]]; then
echo -e ${RED}If you want this script to automatically get an authentication echo -e "${RED}If you want this script to automatically get an authentication"
echo token, please add the variables PIA_USER and PIA_PASS. Example: echo "token, please add the variables PIA_USER and PIA_PASS. Example:"
echo -e $ PIA_USER=p0123456 PIA_PASS=xxx ./get_region.sh${NC} echo -e "$ PIA_USER=p0123456 PIA_PASS=xxx ./get_region.sh${NC}"
exit 0 exit 0
fi fi
./get_token.sh ./get_token.sh
@ -232,12 +232,12 @@ fi
# Connect with WireGuard and clear authentication token file and latencyList # Connect with WireGuard and clear authentication token file and latencyList
if [[ $VPN_PROTOCOL == "wireguard" ]]; then if [[ $VPN_PROTOCOL == "wireguard" ]]; then
echo The ./get_region.sh script got started with echo "The ./get_region.sh script got started with"
echo -e ${GREEN}VPN_PROTOCOL=wireguard${NC}, so we will automatically connect to WireGuard, echo -e "${GREEN}VPN_PROTOCOL=wireguard${NC}, so we will automatically connect to WireGuard,"
echo by running this command: echo "by running this command:"
echo -e $ ${GREEN}PIA_TOKEN="$PIA_TOKEN" \\ echo -e "$ ${GREEN}PIA_TOKEN=$PIA_TOKEN \\"
echo WG_SERVER_IP="$bestServer_WG_IP" WG_HOSTNAME="$bestServer_WG_hostname" \\ echo "WG_SERVER_IP=$bestServer_WG_IP WG_HOSTNAME=$bestServer_WG_hostname \\"
echo -e PIA_PF=$PIA_PF ./connect_to_wireguard_with_token.sh${NC} echo -e "PIA_PF=$PIA_PF ./connect_to_wireguard_with_token.sh${NC}"
echo echo
PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN WG_SERVER_IP=$bestServer_WG_IP \ PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN WG_SERVER_IP=$bestServer_WG_IP \
WG_HOSTNAME=$bestServer_WG_hostname ./connect_to_wireguard_with_token.sh WG_HOSTNAME=$bestServer_WG_hostname ./connect_to_wireguard_with_token.sh
@ -253,14 +253,14 @@ if [[ $VPN_PROTOCOL == openvpn* ]]; then
serverIP=$bestServer_OT_IP serverIP=$bestServer_OT_IP
serverHostname=$bestServer_OT_hostname serverHostname=$bestServer_OT_hostname
fi fi
echo The ./get_region.sh script got started with echo "The ./get_region.sh script got started with"
echo -e ${GREEN}VPN_PROTOCOL=$VPN_PROTOCOL${NC}, so we will automatically echo -e "${GREEN}VPN_PROTOCOL=$VPN_PROTOCOL${NC}, so we will automatically"
echo connect to OpenVPN, by running this command: echo "connect to OpenVPN, by running this command:"
echo -e $ ${GREEN}PIA_PF=$PIA_PF PIA_TOKEN="$PIA_TOKEN" \\ echo -e "$ ${GREEN}PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN \\"
echo OVPN_SERVER_IP="$serverIP" \\ echo " OVPN_SERVER_IP=$serverIP \\"
echo OVPN_HOSTNAME="$serverHostname" \\ echo " OVPN_HOSTNAME=$serverHostname \\"
echo CONNECTION_SETTINGS=$VPN_PROTOCOL \\ echo " CONNECTION_SETTINGS=$VPN_PROTOCOL \\"
echo -e ./connect_to_openvpn_with_token.sh${NC} echo -e " ./connect_to_openvpn_with_token.sh${NC}"
echo echo
PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN \ PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN \
OVPN_SERVER_IP=$serverIP \ OVPN_SERVER_IP=$serverIP \

View File

@ -60,9 +60,9 @@ fi
mkdir -p /opt/piavpn-manual mkdir -p /opt/piavpn-manual
if [[ -z $PIA_USER || -z $PIA_PASS ]]; then if [[ -z $PIA_USER || -z $PIA_PASS ]]; then
echo If you want this script to automatically get a token from the Meta echo "If you want this script to automatically get a token from the Meta"
echo service, please add the variables PIA_USER and PIA_PASS. Example: echo "service, please add the variables PIA_USER and PIA_PASS. Example:"
echo $ PIA_USER=p0123456 PIA_PASS=xxx ./get_token.sh echo "$ PIA_USER=p0123456 PIA_PASS=xxx ./get_token.sh"
exit 1 exit 1
fi fi
@ -81,7 +81,7 @@ if [[ $(echo "$generateTokenResponse" | jq -r '.status') != "OK" ]]; then
exit exit
fi fi
echo -e ${GREEN}OK! echo -e "${GREEN}OK!"
echo echo
token=$(echo "$generateTokenResponse" | jq -r '.token') token=$(echo "$generateTokenResponse" | jq -r '.token')
tokenExpiration=$(timeout_timestamp) tokenExpiration=$(timeout_timestamp)

View File

@ -34,15 +34,15 @@ check_tool jq
# Check if the mandatory environment variables are set. # Check if the mandatory environment variables are set.
if [[ -z $PF_GATEWAY || -z $PIA_TOKEN || -z $PF_HOSTNAME ]]; then if [[ -z $PF_GATEWAY || -z $PIA_TOKEN || -z $PF_HOSTNAME ]]; then
echo This script requires 3 env vars: echo "This script requires 3 env vars:"
echo PF_GATEWAY - the IP of your gateway echo "PF_GATEWAY - the IP of your gateway"
echo PF_HOSTNAME - name of the host used for SSL/TLS certificate verification echo "PF_HOSTNAME - name of the host used for SSL/TLS certificate verification"
echo PIA_TOKEN - the token you use to connect to the vpn services echo "PIA_TOKEN - the token you use to connect to the vpn services"
echo echo
echo An easy solution is to just run get_region_and_token.sh echo "An easy solution is to just run get_region_and_token.sh"
echo as it will guide you through getting the best server and echo "as it will guide you through getting the best server and"
echo also a token. Detailed information can be found here: echo "also a token. Detailed information can be found here:"
echo https://github.com/pia-foss/manual-connections echo "https://github.com/pia-foss/manual-connections"
exit 1 exit 1
fi fi
@ -142,12 +142,12 @@ while true; do
# This script will exit in 2 months, since the port will expire. # This script will exit in 2 months, since the port will expire.
export bind_port_response export bind_port_response
if [[ $(echo "$bind_port_response" | jq -r '.status') != "OK" ]]; then if [[ $(echo "$bind_port_response" | jq -r '.status') != "OK" ]]; then
echo -e "${RED}The API did not return OK when trying to bind port... Exiting." echo -e "${RED}The API did not return OK when trying to bind port... Exiting.${NC}"
exit 1 exit 1
fi fi
echo -e Forwarded port'\t'${GREEN}"$port"${NC} echo -e Forwarded port'\t'"${GREEN}$port${NC}"
echo -e Refreshed on'\t'${GREEN}"$(date)"${NC} echo -e Refreshed on'\t'"${GREEN}$(date)${NC}"
echo -e Expires on'\t'${RED}"$(date --date="$expires_at")"${NC} echo -e Expires on'\t'"${RED}$(date --date="$expires_at")${NC}"
echo -e "\n${GREEN}This script will need to remain active to use port forwarding, and will refresh every 15 minutes.${NC}\n" echo -e "\n${GREEN}This script will need to remain active to use port forwarding, and will refresh every 15 minutes.${NC}\n"
# sleep 15 minutes # sleep 15 minutes

View File

@ -130,7 +130,7 @@ if [[ $PIA_PF != "true" ]]; then
PIA_PF="false" PIA_PF="false"
fi fi
export PIA_PF export PIA_PF
echo -e ${GREEN}PIA_PF=$PIA_PF${NC} echo -e "${GREEN}PIA_PF=$PIA_PF${NC}"
echo echo
# Check for in-line definition of DISABLE_IPV6 and prompt for input # Check for in-line definition of DISABLE_IPV6 and prompt for input
@ -143,8 +143,8 @@ if [[ -z $DISABLE_IPV6 ]]; then
fi fi
if echo "${DISABLE_IPV6:0:1}" | grep -iq n; then if echo "${DISABLE_IPV6:0:1}" | grep -iq n; then
echo -e ${RED}"IPv6 settings have not been altered. echo -e "${RED}IPv6 settings have not been altered.
"${NC} ${NC}"
else else
echo -e "The variable ${GREEN}DISABLE_IPV6=$DISABLE_IPV6${NC}, does not start with 'n' for 'no'. echo -e "The variable ${GREEN}DISABLE_IPV6=$DISABLE_IPV6${NC}, does not start with 'n' for 'no'.
${GREEN}Defaulting to yes.${NC} ${GREEN}Defaulting to yes.${NC}
@ -155,13 +155,13 @@ ${GREEN}Defaulting to yes.${NC}
echo -e "${RED}IPv6 has been disabled${NC}, you can ${GREEN}enable it again with: " echo -e "${RED}IPv6 has been disabled${NC}, you can ${GREEN}enable it again with: "
echo "sysctl -w net.ipv6.conf.all.disable_ipv6=0" echo "sysctl -w net.ipv6.conf.all.disable_ipv6=0"
echo "sysctl -w net.ipv6.conf.default.disable_ipv6=0" echo "sysctl -w net.ipv6.conf.default.disable_ipv6=0"
echo -e ${NC} echo -e "${NC}"
fi fi
# Input validation and check for conflicting declarations of AUTOCONNECT and PREFERRED_REGION # Input validation and check for conflicting declarations of AUTOCONNECT and PREFERRED_REGION
# If both variables are set, AUTOCONNECT has superiority and PREFERRED_REGION is ignored # If both variables are set, AUTOCONNECT has superiority and PREFERRED_REGION is ignored
if [[ -z $AUTOCONNECT ]]; then if [[ -z $AUTOCONNECT ]]; then
echo AUTOCONNECT was not declared. echo "AUTOCONNECT was not declared."
echo echo
selectServer="ask" selectServer="ask"
elif echo "${AUTOCONNECT:0:1}" | grep -iq f; then elif echo "${AUTOCONNECT:0:1}" | grep -iq f; then
@ -184,7 +184,7 @@ else
echo echo
else else
echo echo
echo AUTOCONNECT supersedes in-line definitions of PREFERRED_REGION. echo "AUTOCONNECT supersedes in-line definitions of PREFERRED_REGION."
echo -e "${RED}PREFERRED_REGION=$PREFERRED_REGION will be ignored.${NC} echo -e "${RED}PREFERRED_REGION=$PREFERRED_REGION will be ignored.${NC}
" "
PREFERRED_REGION="" PREFERRED_REGION=""
@ -287,7 +287,7 @@ For example, you can try 0.2 for 200ms allowed latency.
else else
PREFERRED_REGION=$( awk 'NR == '"$serverSelection"' {print $2}' /opt/piavpn-manual/latencyList ) PREFERRED_REGION=$( awk 'NR == '"$serverSelection"' {print $2}' /opt/piavpn-manual/latencyList )
echo echo
echo -e ${GREEN}PREFERRED_REGION="$PREFERRED_REGION"${NC} echo -e "${GREEN}PREFERRED_REGION=$PREFERRED_REGION${NC}"
break break
fi fi
done done
@ -300,13 +300,13 @@ For example, you can try 0.2 for 200ms allowed latency.
exit 1 exit 1
fi fi
else else
echo -e ${GREEN}You will auto-connect to the server with the lowest latency.${NC} echo -e "${GREEN}You will auto-connect to the server with the lowest latency.${NC}"
echo echo
break break
fi fi
else else
# Validate in-line declaration of PREFERRED_REGION; if invalid remove input to initiate prompts # Validate in-line declaration of PREFERRED_REGION; if invalid remove input to initiate prompts
echo Region input is : "$PREFERRED_REGION" echo "Region input is : $PREFERRED_REGION"
export PREFERRED_REGION export PREFERRED_REGION
VPN_PROTOCOL=no ./get_region.sh VPN_PROTOCOL=no ./get_region.sh
if [[ $? != 1 ]]; then if [[ $? != 1 ]]; then
@ -357,15 +357,15 @@ case $VPN_PROTOCOL in
;; ;;
esac esac
export VPN_PROTOCOL export VPN_PROTOCOL
echo -e ${GREEN}VPN_PROTOCOL=$VPN_PROTOCOL" echo -e "${GREEN}VPN_PROTOCOL=$VPN_PROTOCOL
${NC}" ${NC}"
# Check for the required presence of resolvconf for setting DNS on wireguard connections # Check for the required presence of resolvconf for setting DNS on wireguard connections
setDNS="yes" setDNS="yes"
if ! command -v resolvconf &>/dev/null && [[ $VPN_PROTOCOL == "wireguard" ]]; then if ! command -v resolvconf &>/dev/null && [[ $VPN_PROTOCOL == "wireguard" ]]; then
echo -e ${RED}The resolvconf package could not be found. echo -e "${RED}The resolvconf package could not be found."
echo This script can not set DNS for you and you will echo "This script can not set DNS for you and you will"
echo -e need to invoke DNS protection some other way.${NC} echo -e "need to invoke DNS protection some other way.${NC}"
echo echo
setDNS="no" setDNS="no"
fi fi
@ -373,7 +373,7 @@ fi
# Check for in-line definition of PIA_DNS and prompt for input # Check for in-line definition of PIA_DNS and prompt for input
if [[ $setDNS == "yes" ]]; then if [[ $setDNS == "yes" ]]; then
if [[ -z $PIA_DNS ]]; then if [[ -z $PIA_DNS ]]; then
echo Using third party DNS could allow DNS monitoring. echo "Using third party DNS could allow DNS monitoring."
echo -n "Do you want to force PIA DNS ([Y]es/[n]o): " echo -n "Do you want to force PIA DNS ([Y]es/[n]o): "
read -r setDNS read -r setDNS
echo echo