diff --git a/connect_to_openvpn_with_token.sh b/connect_to_openvpn_with_token.sh index 3d19f78..d78874e 100755 --- a/connect_to_openvpn_with_token.sh +++ b/connect_to_openvpn_with_token.sh @@ -37,13 +37,13 @@ check_tool jq if [[ -t 1 ]]; then ncolors=$(tput colors) if [[ -n $ncolors && $ncolors -ge 8 ]]; then - GREEN='\033[0;32m' - RED='\033[0;31m' - NC='\033[0m' # No Color + red=$(tput setaf 1) # ANSI red + green=$(tput setaf 2) # ANSI green + nc=$(tput sgr0) # No Color else - GREEN='' - RED='' - NC='' # No Color + red='' + green='' + nc='' # No Color fi fi @@ -54,25 +54,25 @@ adapter_check=$( ip a s tun06 2>&1 ) should_read="Device \"tun06\" does not exist" pid_filepath="/opt/piavpn-manual/pia_pid" if [[ $adapter_check != *"$should_read"* ]]; then - echo -e "${RED}The tun06 adapter already exists, that interface is required" - echo -e "for this configuration.${NC}" + echo -e "${red}The tun06 adapter already exists, that interface is required" + echo -e "for this configuration.${nc}" if [[ -f $pid_filepath ]]; then old_pid=$( cat "$pid_filepath" ) old_pid_name=$( ps -p "$old_pid" -o comm= ) if [[ $old_pid_name == "openvpn" ]]; then 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 "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 fi 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 fi 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" echo 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.default.disable_ipv6) -ne 1 ]] 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 -e "sysctl -w net.ipv6.conf.default.disable_ipv6=1${NC}" + echo -e "sysctl -w net.ipv6.conf.default.disable_ipv6=1${nc}" fi # Check if the mandatory environment variables are set. @@ -102,7 +102,7 @@ if [[ -z $OVPN_SERVER_IP || -z $OVPN_HOSTNAME || -z $PIA_TOKEN || -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 "OVPN_SERVER_IP - IP that you want to connect to" echo "OVPN_HOSTNAME - name of the server, required for ssl" @@ -120,7 +120,7 @@ if [[ -z $OVPN_SERVER_IP || 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 "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 fi @@ -131,7 +131,7 @@ rm -f /opt/piavpn-manual/credentials /opt/piavpn-manual/route_info echo "${PIA_TOKEN:0:62} ${PIA_TOKEN:62}" > /opt/piavpn-manual/credentials || exit 1 chmod 600 /opt/piavpn-manual/credentials -echo -e "${GREEN}OK!${NC}" +echo -e "${green}OK!${nc}" # Translate connection settings variable IFS='_' @@ -168,7 +168,7 @@ echo "remote $OVPN_SERVER_IP $port $protocol" >> /opt/piavpn-manual/pia.ovpn if [[ $PIA_DNS != "true" ]]; then cp openvpn_config/openvpn_up.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 "with the env var PIA_DNS=true. Example:" echo $ OVPN_SERVER_IP=\""$OVPN_SERVER_IP"\" OVPN_HOSTNAME=\""$OVPN_HOSTNAME"\" \ @@ -213,38 +213,38 @@ gateway_ip=$( cat /opt/piavpn-manual/route_info ) # Report and exit if connection was not initialized within 10 seconds. if [[ $connected != "true" ]]; then - echo -e "${RED}The VPN connection was not established within 10 seconds.${NC}" + echo -e "${red}The VPN connection was not established within 10 seconds.${nc}" kill "$ovpn_pid" exit 1 fi -echo -e "${GREEN}Initialization Sequence Complete!${NC} +echo -e "${green}Initialization Sequence Complete!${nc} At this point, internet should work via VPN. " -echo -e "OpenVPN Process ID: ${GREEN}$ovpn_pid${NC} -VPN route IP: ${GREEN}$gateway_ip${NC} +echo -e "OpenVPN Process ID: ${green}$ovpn_pid${nc} +VPN route IP: ${green}$gateway_ip${nc} To disconnect the VPN, run: ---> ${GREEN}sudo kill $ovpn_pid${NC} <-- +--> ${green}sudo kill $ovpn_pid${nc} <-- " # This section will stop the script if PIA_PF is not set to "true". if [[ $PIA_PF != "true" ]]; then 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_HOSTNAME=$OVPN_HOSTNAME" \ - "./port_forwarding.sh${NC}" + "./port_forwarding.sh${nc}" echo 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." exit 1 fi -echo -ne "This script got started with ${GREEN}PIA_PF=true${NC}. +echo -ne "This script got started with ${green}PIA_PF=true${nc}. Starting port forwarding in " for i in {5..1}; do @@ -255,10 +255,10 @@ echo echo echo -e "Starting procedure to enable port forwarding by running the following command: -$ ${GREEN}PIA_TOKEN=$PIA_TOKEN \\ +$ ${green}PIA_TOKEN=$PIA_TOKEN \\ PF_GATEWAY=$gateway_ip \\ PF_HOSTNAME=$OVPN_HOSTNAME \\ - ./port_forwarding.sh${NC}" + ./port_forwarding.sh${nc}" PIA_TOKEN=$PIA_TOKEN \ PF_GATEWAY=$gateway_ip \ diff --git a/connect_to_wireguard_with_token.sh b/connect_to_wireguard_with_token.sh index bed485a..30aa3a2 100755 --- a/connect_to_wireguard_with_token.sh +++ b/connect_to_wireguard_with_token.sh @@ -37,13 +37,13 @@ check_tool jq if [[ -t 1 ]]; then ncolors=$(tput colors) if [[ -n $ncolors && $ncolors -ge 8 ]]; then - GREEN='\033[0;32m' - RED='\033[0;31m' - NC='\033[0m' # No Color + red=$(tput setaf 1) # ANSI red + green=$(tput setaf 2) # ANSI green + nc=$(tput sgr0) # No Color else - GREEN='' - RED='' - NC='' # No Color + red='' + green='' + nc='' # No Color fi fi @@ -55,16 +55,16 @@ if [[ -f /proc/net/if_inet6 ]] && [[ $(sysctl -n net.ipv6.conf.all.disable_ipv6) -ne 1 || $(sysctl -n net.ipv6.conf.default.disable_ipv6) -ne 1 ]] 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 -e "sysctl -w net.ipv6.conf.default.disable_ipv6=1${NC}" + echo -e "sysctl -w net.ipv6.conf.default.disable_ipv6=1${nc}" fi # Check if the mandatory environment variables are set. if [[ -z $WG_SERVER_IP || -z $WG_HOSTNAME || -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_HOSTNAME - name of the server, required for ssl" echo "PIA_TOKEN - your authentication token" @@ -76,7 +76,7 @@ if [[ -z $WG_SERVER_IP || 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 "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 fi @@ -103,7 +103,7 @@ export wireguard_json # Check if the API returned OK and stop this script if it didn't. if [[ $(echo "$wireguard_json" | jq -r '.status') != "OK" ]]; then - >&2 echo -e "${RED}Server did not return OK. Stopping now.${NC}" + >&2 echo -e "${red}Server did not return OK. Stopping now.${nc}" exit 1 fi @@ -112,7 +112,7 @@ fi # these scripts. Feel free to fork the project and test it out. echo 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 # Create the WireGuard config based on the JSON received from the API @@ -142,7 +142,7 @@ PublicKey = $(echo "$wireguard_json" | jq -r '.server_key') AllowedIPs = 0.0.0.0/0 Endpoint = ${WG_SERVER_IP}:$(echo "$wireguard_json" | jq -r '.server_port') " > /etc/wireguard/pia.conf || exit 1 -echo -e "${GREEN}OK!${NC}" +echo -e "${green}OK!${nc}" # Start the WireGuard interface. # If something failed, stop this script. @@ -152,29 +152,29 @@ echo echo "Trying to create the wireguard interface..." wg-quick up pia || exit 1 echo -echo -e "${GREEN}The WireGuard interface got created.${NC} +echo -e "${green}The WireGuard interface got created.${nc} At this point, internet should work via VPN. To disconnect the VPN, run: ---> ${GREEN}wg-quick down pia${NC} <-- +--> ${green}wg-quick down pia${nc} <-- " # This section will stop the script if PIA_PF is not set to "true". if [[ $PIA_PF != "true" ]]; then 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_HOSTNAME=$WG_HOSTNAME" \ - "./port_forwarding.sh${NC}" + "./port_forwarding.sh${nc}" echo 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." exit 1 fi -echo -ne "This script got started with ${GREEN}PIA_PF=true${NC}. +echo -ne "This script got started with ${green}PIA_PF=true${nc}. Starting port forwarding in " for i in {5..1}; do @@ -185,10 +185,10 @@ echo echo echo -e "Starting procedure to enable port forwarding by running the following command: -$ ${GREEN}PIA_TOKEN=$PIA_TOKEN \\ +$ ${green}PIA_TOKEN=$PIA_TOKEN \\ PF_GATEWAY=$WG_SERVER_IP \\ PF_HOSTNAME=$WG_HOSTNAME \\ - ./port_forwarding.sh${NC}" + ./port_forwarding.sh${nc}" PIA_TOKEN=$PIA_TOKEN \ PF_GATEWAY=$WG_SERVER_IP \ diff --git a/get_region.sh b/get_region.sh index a2aceb2..4b75220 100755 --- a/get_region.sh +++ b/get_region.sh @@ -38,14 +38,14 @@ check_all_region_data() { echo -n "Getting the server list..." if [[ ${#all_region_data} -lt 1000 ]]; then - echo -e "${RED}Could not get correct region data. To debug this, run:" + echo -e "${red}Could not get correct region data. To debug this, run:" echo "$ curl -v $serverlist_url" - echo -e "If it works, you will get a huge JSON as a response.${NC}" + echo -e "If it works, you will get a huge JSON as a response.${nc}" exit 1 fi # Notify the user that we got the server list. - echo -e "${GREEN}OK!${NC} + echo -e "${green}OK!${nc} " } @@ -56,7 +56,7 @@ get_selected_region_data() { jq --arg REGION_ID "$selectedRegion" -r \ '.regions[] | select(.id==$REGION_ID)')" if [[ -z $regionData ]]; then - echo -e "${RED}The REGION_ID $selectedRegion is not valid.${NC} + echo -e "${red}The REGION_ID $selectedRegion is not valid.${nc} " exit 1 fi @@ -66,19 +66,19 @@ get_selected_region_data() { if [[ -t 1 ]]; then ncolors=$(tput colors) if [[ -n $ncolors && $ncolors -ge 8 ]]; then - GREEN='\033[0;32m' - RED='\033[0;31m' - NC='\033[0m' # No Color + red=$(tput setaf 1) # ANSI red + green=$(tput setaf 2) # ANSI green + nc=$(tput sgr0) # No Color else - GREEN='' - RED='' - NC='' # No Color + red='' + green='' + nc='' # No Color fi fi # Only allow script to run as root if (( EUID != 0 )); then - echo -e "${RED}This script needs to be run as root. Try again with 'sudo $0'${NC}" + echo -e "${red}This script needs to be run as root. Try again with 'sudo $0'${nc}" exit 1 fi @@ -158,20 +158,20 @@ if [[ $selectedRegion == "none" ]]; then .servers.meta[0].ip+" "+.id+" "+.name+" "+(.geo|tostring)' )" fi 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" | xargs -I{} bash -c 'printServerLatency {}' | sort | head -1 | awk '{ print $2 }')" echo 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 -e "$ MAX_LATENCY=1 ./get_region.sh${NC}" + echo -e "$ MAX_LATENCY=1 ./get_region.sh${nc}" exit 1 else echo -e "A list of servers and connection details, ordered by latency can be -found in at : ${GREEN}/opt/piavpn-manual/latencyList${NC} +found in at : ${green}/opt/piavpn-manual/latencyList${nc} " fi else @@ -192,7 +192,7 @@ bestServer_OU_hostname=$(echo "$regionData" | jq -r '.servers.ovpnudp[0].cn') 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 echo " (geolocated region)." else @@ -205,20 +205,20 @@ the SSL/TLS certificate actually contains the hostname so that you are sure you are connecting to a secure server, validated by the PIA authority. Please find below the list of best IPs and matching hostnames for each protocol: -${GREEN}Meta Services $bestServer_meta_IP\t- $bestServer_meta_hostname +${green}Meta Services $bestServer_meta_IP\t- $bestServer_meta_hostname WireGuard $bestServer_WG_IP\t- $bestServer_WG_hostname OpenVPN TCP $bestServer_OT_IP\t- $bestServer_OT_hostname OpenVPN UDP $bestServer_OU_IP\t- $bestServer_OU_hostname -${NC}" +${nc}" fi # The script will check for an authentication token, and use it if present # If no token exists, the script will check for login credentials to generate one if [[ -z $PIA_TOKEN ]]; 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 -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 fi ./get_token.sh @@ -226,18 +226,18 @@ if [[ -z $PIA_TOKEN ]]; then export PIA_TOKEN rm -f /opt/piavpn-manual/token else - echo -e "Using existing token ${GREEN}$PIA_TOKEN${NC}." + echo -e "Using existing token ${green}$PIA_TOKEN${nc}." echo fi # Connect with WireGuard and clear authentication token file and latencyList if [[ $VPN_PROTOCOL == "wireguard" ]]; then 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 -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 -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 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 @@ -254,13 +254,13 @@ if [[ $VPN_PROTOCOL == openvpn* ]]; then serverHostname=$bestServer_OT_hostname fi 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 -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_HOSTNAME=$serverHostname \\" echo " CONNECTION_SETTINGS=$VPN_PROTOCOL \\" - echo -e " ./connect_to_openvpn_with_token.sh${NC}" + echo -e " ./connect_to_openvpn_with_token.sh${nc}" echo PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN \ OVPN_SERVER_IP=$serverIP \ diff --git a/get_token.sh b/get_token.sh index 40016ff..38ab5c0 100755 --- a/get_token.sh +++ b/get_token.sh @@ -41,19 +41,19 @@ timeout_timestamp() { if [[ -t 1 ]]; then ncolors=$(tput colors) if [[ -n $ncolors && $ncolors -ge 8 ]]; then - GREEN='\033[0;32m' - RED='\033[0;31m' - NC='\033[0m' # No Color + red=$(tput setaf 1) # ANSI red + green=$(tput setaf 2) # ANSI green + nc=$(tput sgr0) # No Color else - GREEN='' - RED='' - NC='' # No Color + red='' + green='' + nc='' # No Color fi fi # Only allow script to run as root if (( EUID != 0 )); then - echo -e "${RED}This script needs to be run as root. Try again with 'sudo $0'${NC}" + echo -e "${red}This script needs to be run as root. Try again with 'sudo $0'${nc}" exit 1 fi @@ -74,17 +74,17 @@ generateTokenResponse=$(curl -s -u "$PIA_USER:$PIA_PASS" \ if [[ $(echo "$generateTokenResponse" | jq -r '.status') != "OK" ]]; then echo echo - echo -e "${RED}Could not authenticate with the login credentials provided!${NC}" + echo -e "${red}Could not authenticate with the login credentials provided!${nc}" echo exit fi -echo -e "${GREEN}OK!" +echo -e "${green}OK!" echo token=$(echo "$generateTokenResponse" | jq -r '.token') tokenExpiration=$(timeout_timestamp) tokenLocation="/opt/piavpn-manual/token" -echo -e "PIA_TOKEN=$token${NC}" +echo -e "PIA_TOKEN=$token${nc}" echo "$token" > "$tokenLocation" || exit 1 echo "$tokenExpiration" >> "$tokenLocation" echo diff --git a/port_forwarding.sh b/port_forwarding.sh index 0b98cda..58d239d 100755 --- a/port_forwarding.sh +++ b/port_forwarding.sh @@ -50,13 +50,13 @@ fi if [[ -t 1 ]]; then ncolors=$(tput colors) if [[ -n $ncolors && $ncolors -ge 8 ]]; then - GREEN='\033[0;32m' - RED='\033[0;31m' - NC='\033[0m' # No Color + red=$(tput setaf 1) # ANSI red + green=$(tput setaf 2) # ANSI green + nc=$(tput sgr0) # No Color else - GREEN='' - RED='' - NC='' # No Color + red='' + green='' + nc='' # No Color fi fi @@ -97,10 +97,10 @@ export payload_and_signature # Check if the payload and the signature are OK. # If they are not OK, just stop the script. if [[ $(echo "$payload_and_signature" | jq -r '.status') != "OK" ]]; then - echo -e "${RED}The payload_and_signature variable does not contain an OK status.${NC}" + echo -e "${red}The payload_and_signature variable does not contain an OK status.${nc}" exit 1 fi -echo -e "${GREEN}OK!${NC}" +echo -e "${green}OK!${nc}" # We need to get the signature out of the previous response. # The signature will allow the us to bind the port on the server. @@ -118,10 +118,10 @@ port=$(echo "$payload" | base64 -d | jq -r '.port') expires_at=$(echo "$payload" | base64 -d | jq -r '.expires_at') echo -ne " -Signature ${GREEN}$signature${NC} -Payload ${GREEN}$payload${NC} +Signature ${green}$signature${nc} +Payload ${green}$payload${nc} ---> The port is ${GREEN}$port${NC} and it will expire on ${RED}$expires_at${NC}. <-- +--> The port is ${green}$port${nc} and it will expire on ${red}$expires_at${nc}. <-- Trying to bind the port... " @@ -136,19 +136,19 @@ while true; do --data-urlencode "payload=${payload}" \ --data-urlencode "signature=${signature}" \ "https://${PF_HOSTNAME}:19999/bindPort")" - echo -e "${GREEN}OK!${NC}" + echo -e "${green}OK!${nc}" # If port did not bind, just exit the script. # This script will exit in 2 months, since the port will expire. export bind_port_response 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.${NC}" + echo -e "${red}The API did not return OK when trying to bind port... Exiting.${nc}" exit 1 fi - echo -e Forwarded port'\t'"${GREEN}$port${NC}" - echo -e Refreshed on'\t'"${GREEN}$(date)${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 Forwarded port'\t'"${green}$port${nc}" + echo -e Refreshed on'\t'"${green}$(date)${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" # sleep 15 minutes sleep 900 diff --git a/run_setup.sh b/run_setup.sh index cad8777..44f1729 100755 --- a/run_setup.sh +++ b/run_setup.sh @@ -23,13 +23,13 @@ if [[ -t 1 ]]; then ncolors=$(tput colors) if [[ -n $ncolors && $ncolors -ge 8 ]]; then - GREEN='\033[0;32m' - RED='\033[0;31m' - NC='\033[0m' # No Color + red=$(tput setaf 1) # ANSI red + green=$(tput setaf 2) # ANSI green + nc=$(tput sgr0) # No Color else - GREEN='' - RED='' - NC='' # No Color + red='' + green='' + nc='' # No Color fi fi @@ -39,7 +39,7 @@ floatCheck='^[0-9]+([.][0-9]+)?$' # Only allow script to run as root if (( EUID != 0 )); then - echo -e "${RED}This script needs to be run as root. Try again with 'sudo $0'${NC}" + echo -e "${red}This script needs to be run as root. Try again with 'sudo $0'${nc}" exit 1 fi @@ -59,15 +59,15 @@ while :; do unPrefix=${PIA_USER:0:1} unSuffix=${PIA_USER:1} if [[ -z $PIA_USER ]]; then - echo -e "\n${RED}You must provide input.${NC}" + echo -e "\n${red}You must provide input.${nc}" elif [[ ${#PIA_USER} != 8 ]]; then - echo -e "\n${RED}A PIA username is always 8 characters long.${NC}" + echo -e "\n${red}A PIA username is always 8 characters long.${nc}" elif [[ $unPrefix != "P" ]] && [[ $unPrefix != "p" ]]; then - echo -e "\n${RED}A PIA username must start with \"p\".${NC}" + echo -e "\n${red}A PIA username must start with \"p\".${nc}" elif ! [[ $unSuffix =~ $intCheck ]]; then - echo -e "\n${RED}Username formatting is always p#######!${NC}" + echo -e "\n${red}Username formatting is always p#######!${nc}" else - echo -e "\n${GREEN}PIA_USER=$PIA_USER${NC}" + echo -e "\n${green}PIA_USER=$PIA_USER${nc}" break fi PIA_USER="" @@ -85,11 +85,11 @@ while :; do # Confirm format of PIA_PASS input if [[ -z $PIA_PASS ]]; then - echo -e "\n${RED}You must provide input.${NC}" + echo -e "\n${red}You must provide input.${nc}" elif [[ ${#PIA_PASS} -lt 8 ]]; then - echo -e "\n${RED}A PIA password is always a minimum of 8 characters long.${NC}" + echo -e "\n${red}A PIA password is always a minimum of 8 characters long.${nc}" else - echo -e "\n${GREEN}PIA_PASS input received.${NC}" + echo -e "\n${green}PIA_PASS input received.${nc}" echo break fi @@ -130,7 +130,7 @@ if [[ $PIA_PF != "true" ]]; then PIA_PF="false" fi export PIA_PF -echo -e "${GREEN}PIA_PF=$PIA_PF${NC}" +echo -e "${green}PIA_PF=$PIA_PF${nc}" echo # Check for in-line definition of DISABLE_IPV6 and prompt for input @@ -143,19 +143,19 @@ if [[ -z $DISABLE_IPV6 ]]; then fi if echo "${DISABLE_IPV6:0:1}" | grep -iq n; then - echo -e "${RED}IPv6 settings have not been altered. - ${NC}" + echo -e "${red}IPv6 settings have not been altered. + ${nc}" else - echo -e "The variable ${GREEN}DISABLE_IPV6=$DISABLE_IPV6${NC}, does not start with 'n' for 'no'. -${GREEN}Defaulting to yes.${NC} + echo -e "The variable ${green}DISABLE_IPV6=$DISABLE_IPV6${nc}, does not start with 'n' for 'no'. +${green}Defaulting to yes.${nc} " sysctl -w net.ipv6.conf.all.disable_ipv6=1 sysctl -w net.ipv6.conf.default.disable_ipv6=1 echo - 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.default.disable_ipv6=0" - echo -e "${NC}" + echo -e "${nc}" fi # Input validation and check for conflicting declarations of AUTOCONNECT and PREFERRED_REGION @@ -166,26 +166,26 @@ if [[ -z $AUTOCONNECT ]]; then selectServer="ask" elif echo "${AUTOCONNECT:0:1}" | grep -iq f; then if [[ $AUTOCONNECT != "false" ]]; then - echo -e "The variable ${GREEN}AUTOCONNECT=$AUTOCONNECT${NC}, starts with 'f' for 'false'." + echo -e "The variable ${green}AUTOCONNECT=$AUTOCONNECT${nc}, starts with 'f' for 'false'." AUTOCONNECT="false" - echo -e "Updated ${GREEN}AUTOCONNECT=$AUTOCONNECT${NC}" + echo -e "Updated ${green}AUTOCONNECT=$AUTOCONNECT${nc}" echo fi selectServer="yes" else if [[ $AUTOCONNECT != "true" ]]; then - echo -e "The variable ${GREEN}AUTOCONNECT=$AUTOCONNECT${NC}, does not start with 'f' for 'false'." + echo -e "The variable ${green}AUTOCONNECT=$AUTOCONNECT${nc}, does not start with 'f' for 'false'." AUTOCONNECT="true" - echo -e "Updated ${GREEN}AUTOCONNECT=$AUTOCONNECT${NC}" + echo -e "Updated ${green}AUTOCONNECT=$AUTOCONNECT${nc}" echo fi if [[ -z $PREFERRED_REGION ]]; then - echo -e "${GREEN}AUTOCONNECT=true${NC}" + echo -e "${green}AUTOCONNECT=true${nc}" echo else echo 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="" fi @@ -233,9 +233,9 @@ For example, you can try 0.2 for 200ms allowed latency. if [[ -z $latencyInput ]]; then break elif [[ $latencyInput == 0 ]]; then - echo -e "${RED}Latency input must not be zero.${NC}\n" + echo -e "${red}Latency input must not be zero.${nc}\n" elif ! [[ $customLatency =~ $floatCheck ]]; then - echo -e "${RED}Latency input must be numeric.${NC}\n" + echo -e "${red}Latency input must be numeric.${nc}\n" elif [[ $latencyInput =~ $intCheck ]]; then MAX_LATENCY=$latencyInput break @@ -246,7 +246,7 @@ For example, you can try 0.2 for 200ms allowed latency. latencyInput="" done export MAX_LATENCY - echo -e "${GREEN}MAX_LATENCY=$MAX_LATENCY${NC}" + echo -e "${green}MAX_LATENCY=$MAX_LATENCY${nc}" PREFERRED_REGION="none" export PREFERRED_REGION @@ -256,7 +256,7 @@ For example, you can try 0.2 for 200ms allowed latency. if [[ -s /opt/piavpn-manual/latencyList ]]; then # Output the ordered list of servers that meet the latency specification $MAX_LATENCY - echo -e "Ordered list of servers with latency less than ${GREEN}$MAX_LATENCY${NC} seconds:" + echo -e "Ordered list of servers with latency less than ${green}$MAX_LATENCY${nc} seconds:" i=0 while read -r line; do i=$((i+1)) @@ -277,17 +277,17 @@ For example, you can try 0.2 for 200ms allowed latency. while :; do read -r -p "Input the number of the server you want to connect to ([1]-[$i]) : " serverSelection if [[ -z $serverSelection ]]; then - echo -e "\n${RED}You must provide input.${NC}\n" + echo -e "\n${red}You must provide input.${nc}\n" elif ! [[ $serverSelection =~ $intCheck ]]; then - echo -e "\n${RED}You must enter a number.${NC}\n" + echo -e "\n${red}You must enter a number.${nc}\n" elif [[ $serverSelection -lt 1 ]]; then - echo -e "\n${RED}You must enter a number greater than 1.${NC}\n" + echo -e "\n${red}You must enter a number greater than 1.${nc}\n" elif [[ $serverSelection -gt $i ]]; then - echo -e "\n${RED}You must enter a number between 1 and $i.${NC}\n" + echo -e "\n${red}You must enter a number between 1 and $i.${nc}\n" else PREFERRED_REGION=$( awk 'NR == '"$serverSelection"' {print $2}' /opt/piavpn-manual/latencyList ) echo - echo -e "${GREEN}PREFERRED_REGION=$PREFERRED_REGION${NC}" + echo -e "${green}PREFERRED_REGION=$PREFERRED_REGION${nc}" break fi done @@ -300,7 +300,7 @@ For example, you can try 0.2 for 200ms allowed latency. exit 1 fi 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 break fi @@ -357,15 +357,15 @@ case $VPN_PROTOCOL in ;; esac export VPN_PROTOCOL -echo -e "${GREEN}VPN_PROTOCOL=$VPN_PROTOCOL -${NC}" +echo -e "${green}VPN_PROTOCOL=$VPN_PROTOCOL +${nc}" # Check for the required presence of resolvconf for setting DNS on wireguard connections setDNS="yes" 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 -e "need to invoke DNS protection some other way.${NC}" + echo -e "need to invoke DNS protection some other way.${nc}" echo setDNS="no" fi @@ -386,7 +386,7 @@ elif [[ $PIA_DNS != "true" || $setDNS == "no" ]]; then PIA_DNS="false" fi export PIA_DNS -echo -e "${GREEN}PIA_DNS=$PIA_DNS${NC}" +echo -e "${green}PIA_DNS=$PIA_DNS${nc}" CONNECTION_READY="true" export CONNECTION_READY