Address some shellcheck reported issues

This commit is contained in:
Valery Kalesnik 2021-08-03 17:26:29 -07:00 committed by goonix
parent 6d06b31af1
commit b04be889f0
8 changed files with 96 additions and 96 deletions

View File

@ -22,7 +22,7 @@
# This function allows you to check if the required tools have been installed.
function check_tool() {
cmd=$1
if ! command -v $cmd &>/dev/null
if ! command -v "$cmd" &>/dev/null
then
echo "$cmd could not be found"
echo "Please install $cmd"
@ -37,7 +37,7 @@ check_tool openvpn
# Check if terminal allows output, if yes, define colors for output
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
if test -n "$ncolors" && test "$ncolors" -ge 8; then
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
@ -62,19 +62,19 @@ if [[ "$adapter_check" != *"$should_read"* ]]; then
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): "
read close_connection
read -r close_connection
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.
exit 1
fi
echo
echo -e ${GREEN}Killing the existing OpenVPN process and waiting 5 seconds...${NC}
kill $old_pid
kill "$old_pid"
echo
for i in {5..1}; do
echo -n "$i..."
@ -129,8 +129,8 @@ fi
echo -n "Trying to write /opt/piavpn-manual/pia.ovpn..."
mkdir -p /opt/piavpn-manual
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
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}"
@ -162,7 +162,7 @@ fi
# Create the OpenVPN config based on the settings specified
cat $prefix_filepath > /opt/piavpn-manual/pia.ovpn || exit 1
echo remote $OVPN_SERVER_IP $port $protocol >> /opt/piavpn-manual/pia.ovpn
echo remote "$OVPN_SERVER_IP" $port "$protocol" >> /opt/piavpn-manual/pia.ovpn
# Copy the up/down scripts to /opt/piavpn-manual/
# based upon use of PIA DNS
@ -172,8 +172,8 @@ if [ "$PIA_DNS" != true ]; then
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\" \
PIA_TOKEN=\"$PIA_TOKEN\" CONNECTION_SETTINGS=\"$CONNECTION_SETTINGS\" \
echo $ OVPN_SERVER_IP=\""$OVPN_SERVER_IP"\" OVPN_HOSTNAME=\""$OVPN_HOSTNAME"\" \
PIA_TOKEN=\""$PIA_TOKEN"\" CONNECTION_SETTINGS=\""$CONNECTION_SETTINGS"\" \
PIA_PF=true PIA_DNS=true ./connect_to_openvpn_with_token.sh
else
cp openvpn_config/openvpn_up_dnsoverwrite.sh /opt/piavpn-manual/openvpn_up.sh
@ -201,7 +201,7 @@ Confirming OpenVPN connection state..."
# Manually adjust the connection_wait_time if needed
connection_wait_time=10
confirmation="Initialization Sequence Complete"
for (( timeout=0; timeout <=$connection_wait_time; timeout++ ))
for (( timeout=0; timeout <= connection_wait_time; timeout++ ))
do
sleep 1
if grep -q "$confirmation" /opt/piavpn-manual/debug_info; then
@ -216,7 +216,7 @@ 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}"
kill $ovpn_pid
kill "$ovpn_pid"
exit 1
fi
@ -236,9 +236,9 @@ To disconnect the VPN, run:
# 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 \
PF_GATEWAY=$gateway_ip \
PF_HOSTNAME=$OVPN_HOSTNAME \
echo -e $ ${GREEN}PIA_TOKEN="$PIA_TOKEN" \
PF_GATEWAY="$gateway_ip" \
PF_HOSTNAME="$OVPN_HOSTNAME" \
./port_forwarding.sh${NC}
echo
echo The location used must be port forwarding enabled, or this will fail.

View File

@ -22,7 +22,7 @@
# This function allows you to check if the required tools have been installed.
function check_tool() {
cmd=$1
if ! command -v $cmd &>/dev/null
if ! command -v "$cmd" &>/dev/null
then
echo "$cmd could not be found"
echo "Please install $cmd"
@ -37,7 +37,7 @@ check_tool jq
# Check if terminal allows output, if yes, define colors for output
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
if test -n "$ncolors" && test "$ncolors" -ge 8; then
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
@ -91,7 +91,7 @@ export pubKey
# 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
# 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 \
--connect-to "$WG_HOSTNAME::$WG_SERVER_IP:" \
--cacert "ca.rsa.4096.crt" \
@ -122,9 +122,9 @@ echo
# require it.
if [ "$PIA_DNS" == true ]; then
dnsServer="$(echo "$wireguard_json" | jq -r '.dns_servers[0]')"
echo Trying to set up DNS to $dnsServer. In case you do not have resolvconf,
echo this operation will fail and you will not get a VPN. If you have issues,
echo start this script without PIA_DNS.
echo "Trying to set up DNS to $dnsServer. In case you do not have resolvconf,"
echo "this operation will fail and you will not get a VPN. If you have issues,"
echo "start this script without PIA_DNS."
echo
dnsSettingForVPN="DNS = $dnsServer"
fi
@ -163,9 +163,9 @@ To disconnect the VPN, run:
# 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 \
PF_GATEWAY=$WG_SERVER_IP \
PF_HOSTNAME=$WG_HOSTNAME \
echo -e $ ${GREEN}PIA_TOKEN="$PIA_TOKEN" \
PF_GATEWAY="$WG_SERVER_IP" \
PF_HOSTNAME="$WG_HOSTNAME" \
./port_forwarding.sh${NC}
echo
echo The location used must be port forwarding enabled, or this will fail.

View File

@ -22,7 +22,7 @@
# This function allows you to check if the required tools have been installed.
function check_tool() {
cmd=$1
if ! command -v $cmd &>/dev/null
if ! command -v "$cmd" &>/dev/null
then
echo "$cmd could not be found"
echo "Please install $cmd"
@ -53,7 +53,7 @@ function check_all_region_data() {
# Get all data for the selected region
# Exit with code 1 if the REGION_ID provided is invalid
function get_selected_region_data() {
regionData="$( echo $all_region_data |
regionData="$( echo "$all_region_data" |
jq --arg REGION_ID "$selectedRegion" -r \
'.regions[] | select(.id==$REGION_ID)')"
if [[ ! $regionData ]]; then
@ -66,7 +66,7 @@ function get_selected_region_data() {
# Check if terminal allows output, if yes, define colors for output
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
if test -n "$ncolors" && test "$ncolors" -ge 8; then
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
@ -103,18 +103,18 @@ serverlist_url='https://serverlist.piaservers.net/vpninfo/servers/v6'
printServerLatency() {
serverIP="$1"
regionID="$2"
regionName="$(echo ${@:3} |
regionName="$(echo "${@:3}" |
sed 's/ false//' | sed 's/true/(geo)/')"
time=$(LC_NUMERIC=en_US.utf8 curl -o /dev/null -s \
--connect-timeout $MAX_LATENCY \
--connect-timeout "$MAX_LATENCY" \
--write-out "%{time_connect}" \
http://$serverIP:443)
http://"$serverIP":443)
if [ $? -eq 0 ]; then
>&2 echo Got latency ${time}s for region: $regionName
echo $time $regionID $serverIP
>&2 echo Got latency "${time}"s for region: "$regionName"
echo "$time $regionID $serverIP"
# Write a list of servers with acceptable latancy
# to /opt/piavpn-manual/latencyList
echo -e $time $regionID'\t'$serverIP'\t'$regionName >> /opt/piavpn-manual/latencyList
echo -e "$time" "$regionID"'\t'"$serverIP"'\t'"$regionName" >> /opt/piavpn-manual/latencyList
fi
# Sort the latencyList, ordered by latency
sort -no /opt/piavpn-manual/latencyList /opt/piavpn-manual/latencyList
@ -150,23 +150,23 @@ if [[ $selectedRegion == "none" ]]; then
if [[ $PIA_PF == "true" ]]; then
echo Port Forwarding is enabled, non-PF servers excluded.
echo
summarized_region_data="$( echo $all_region_data |
summarized_region_data="$( echo "$all_region_data" |
jq -r '.regions[] | select(.port_forward==true) |
.servers.meta[0].ip+" "+.id+" "+.name+" "+(.geo|tostring)' )"
else
summarized_region_data="$( echo $all_region_data |
summarized_region_data="$( echo "$all_region_data" |
jq -r '.regions[] |
.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}
exit 1
@ -182,19 +182,19 @@ fi
get_selected_region_data
bestServer_meta_IP="$(echo $regionData | jq -r '.servers.meta[0].ip')"
bestServer_meta_hostname="$(echo $regionData | jq -r '.servers.meta[0].cn')"
bestServer_WG_IP="$(echo $regionData | jq -r '.servers.wg[0].ip')"
bestServer_WG_hostname="$(echo $regionData | jq -r '.servers.wg[0].cn')"
bestServer_OT_IP="$(echo $regionData | jq -r '.servers.ovpntcp[0].ip')"
bestServer_OT_hostname="$(echo $regionData | jq -r '.servers.ovpntcp[0].cn')"
bestServer_OU_IP="$(echo $regionData | jq -r '.servers.ovpnudp[0].ip')"
bestServer_OU_hostname="$(echo $regionData | jq -r '.servers.ovpnudp[0].cn')"
bestServer_meta_IP="$(echo "$regionData" | jq -r '.servers.meta[0].ip')"
bestServer_meta_hostname="$(echo "$regionData" | jq -r '.servers.meta[0].cn')"
bestServer_WG_IP="$(echo "$regionData" | jq -r '.servers.wg[0].ip')"
bestServer_WG_hostname="$(echo "$regionData" | jq -r '.servers.wg[0].cn')"
bestServer_OT_IP="$(echo "$regionData" | jq -r '.servers.ovpntcp[0].ip')"
bestServer_OT_hostname="$(echo "$regionData" | jq -r '.servers.ovpntcp[0].cn')"
bestServer_OU_IP="$(echo "$regionData" | jq -r '.servers.ovpnudp[0].ip')"
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}
if echo $regionData | jq -r '.geo' | grep true > /dev/null; then
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
echo "."
@ -236,8 +236,8 @@ 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 by running this command:
echo -e $ ${GREEN}PIA_TOKEN=$PIA_TOKEN \\
echo WG_SERVER_IP=$bestServer_WG_IP WG_HOSTNAME=$bestServer_WG_hostname \\
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
PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN WG_SERVER_IP=$bestServer_WG_IP \
@ -257,9 +257,9 @@ if [[ $VPN_PROTOCOL == openvpn* ]]; then
echo The ./get_region.sh script got started with
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 OVPN_SERVER_IP=$serverIP \\
echo OVPN_HOSTNAME=$serverHostname \\
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

View File

@ -22,7 +22,7 @@
# This function allows you to check if the required tools have been installed.
function check_tool() {
cmd=$1
if ! command -v $cmd &>/dev/null
if ! command -v "$cmd" &>/dev/null
then
echo "$cmd could not be found"
echo "Please install $cmd"
@ -42,7 +42,7 @@ check_tool jq
# Check if terminal allows output, if yes, define colors for output
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
if test -n "$ncolors" && test "$ncolors" -ge 8; then
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
@ -87,9 +87,9 @@ echo -e ${GREEN}OK!
echo
token=$(echo "$generateTokenResponse" | jq -r '.token')
tokenExpiration=$(timeout_timestamp)
echo -e PIA_TOKEN=$token${NC}
echo $token > /opt/piavpn-manual/token || exit 1
echo $tokenExpiration >> /opt/piavpn-manual/token
echo -e PIA_TOKEN="$token"${NC}
echo "$token" > /opt/piavpn-manual/token || exit 1
echo "$tokenExpiration" >> /opt/piavpn-manual/token
echo
echo This token will expire in 24 hours, on $tokenExpiration.
echo This token will expire in 24 hours, on "$tokenExpiration".
echo

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
# Write gateway IP for reference
echo $route_vpn_gateway > /opt/piavpn-manual/route_info
echo "$route_vpn_gateway" > /opt/piavpn-manual/route_info

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Write gateway IP for reference
echo $route_vpn_gateway > /opt/piavpn-manual/route_info
echo "$route_vpn_gateway" > /opt/piavpn-manual/route_info
# Back up resolv.conf and create new on with PIA DNS
cat /etc/resolv.conf > /opt/piavpn-manual/resolv_conf_backup

View File

@ -22,7 +22,7 @@
# This function allows you to check if the required tools have been installed.
function check_tool() {
cmd=$1
if ! command -v $cmd &>/dev/null
if ! command -v "$cmd" &>/dev/null
then
echo "$cmd could not be found"
echo "Please install $cmd"
@ -50,7 +50,7 @@ fi
# Check if terminal allows output, if yes, define colors for output
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
if test -n "$ncolors" && test "$ncolors" -ge 8; then
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
@ -146,9 +146,9 @@ while true; do
echo -e "${RED}The API did not return OK when trying to bind port... Exiting."
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 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

View File

@ -22,7 +22,7 @@
# Check if terminal allows output, if yes, define colors for output
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
if test -n "$ncolors" && test "$ncolors" -ge 8; then
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
@ -52,12 +52,12 @@ while :; do
# Check for in-line definition of $PIA_USER
if [[ ! $PIA_USER || $PIA_USER = "" ]]; then
echo
read -p "PIA username (p#######): " PIA_USER
read -rp "PIA username (p#######): " PIA_USER
fi
# Confirm format of PIA_USER input
unPrefix=$( echo ${PIA_USER:0:1} )
unSuffix=$( echo ${PIA_USER:1} )
unPrefix="${PIA_USER:0:1}"
unSuffix="${PIA_USER:1}"
if [[ -z "$PIA_USER" ]]; then
echo -e "\n${RED}You must provide input.${NC}"
elif [[ ${#PIA_USER} != 8 ]]; then
@ -103,8 +103,8 @@ while :; do
tokenLocation="/opt/piavpn-manual/token"
# If the script failed to generate an authentication token, the script will exit early.
if [ ! -f "$tokenLocation" ]; then
read -p "Do you want to try again ([N]o/[y]es): " tryAgain
if ! echo ${tryAgain:0:1} | grep -iq y; then
read -pr "Do you want to try again ([N]o/[y]es): " tryAgain
if ! echo "${tryAgain:0:1}" | grep -iq y; then
exit 1
fi
PIA_USER=""
@ -120,9 +120,9 @@ done
# Check for in-line definition of PIA_PF and prompt for input
if [[ ! $PIA_PF || $PIA_PF = "" ]]; then
echo -n "Do you want a forwarding port assigned ([N]o/[y]es): "
read portForwarding
read -r portForwarding
echo
if echo ${portForwarding:0:1} | grep -iq y; then
if echo "${portForwarding:0:1}" | grep -iq y; then
PIA_PF="true"
fi
fi
@ -138,11 +138,11 @@ if [[ ! $DISABLE_IPV6 || $DISABLE_IPV6 = "" ]]; then
echo "Having active IPv6 connections might compromise security by allowing"
echo "split tunnel connections that run outside the VPN tunnel."
echo -n "Do you want to disable IPv6? (Y/n): "
read DISABLE_IPV6
read -r DISABLE_IPV6
echo
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.
"${NC}
else
@ -164,7 +164,7 @@ if [[ ! $AUTOCONNECT ]]; then
echo AUTOCONNECT was not declared.
echo
selectServer="ask"
elif echo ${AUTOCONNECT:0:1} | grep -iq f; then
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'."
AUTOCONNECT="false"
@ -199,7 +199,7 @@ while :; do
if [[ $selectServer = "ask" ]]; then
echo -n "Do you want to manually select a server, instead of auto-connecting to the
server with the lowest latency ([N]o/[y]es): "
read selectServer
read -r selectServer
echo
fi
@ -208,7 +208,7 @@ server with the lowest latency ([N]o/[y]es): "
# that meet the latency requirements speciied by $MAX_LATENCY.
# When $VPN_PROTOCOL is set to no, get_region.sh will sort that list of servers
# to allow for numeric selection, or an easy manual review of options.
if echo ${selectServer:0:1} | grep -iq y; then
if echo "${selectServer:0:1}" | grep -iq y; then
# This sets the maximum allowed latency in seconds.
# All servers that respond slower than this will be ignored.
if [[ ! $MAX_LATENCY || $MAX_LATENCY = "" ]]; then
@ -224,7 +224,7 @@ For example, you can try 0.2 for 200ms allowed latency.
MAX_LATENCY=0.05 # default
while :; do
if [[ ! $latencyInput || $latencyInput = "" ]]; then
read -p "Custom latency (no input required for 50ms): " latencyInput
read -pr "Custom latency (no input required for 50ms): " latencyInput
echo
fi
customLatency=0
@ -258,7 +258,7 @@ For example, you can try 0.2 for 200ms allowed latency.
# Output the ordered list of servers that meet the latency specification $MAX_LATENCY
echo -e "Orderd list of servers with latency less than ${GREEN}$MAX_LATENCY${NC} seconds:"
i=0
while read line; do
while read -r line; do
i=$((i+1))
time=$( awk 'NR == '$i' {print $1}' /opt/piavpn-manual/latencyList )
id=$( awk 'NR == '$i' {print $2}' /opt/piavpn-manual/latencyList )
@ -267,15 +267,15 @@ For example, you can try 0.2 for 200ms allowed latency.
location2=$( awk 'NR == '$i' {print $5}' /opt/piavpn-manual/latencyList )
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
echo " - "$location
location="$location1 $location2 $location3 $location4"
printf "%3s : %-8s %-15s %17s" $i "$time" "$ip" "$id"
echo " - $location"
done < /opt/piavpn-manual/latencyList
echo
# Receive input to specify the server to connect to manually
while :; do
read -p "Input the number of the server you want to connect to ([1]-[$i]) : " serverSelection
read -pr "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"
elif ! [[ $serverSelection =~ $intCheck ]]; then
@ -285,9 +285,9 @@ For example, you can try 0.2 for 200ms allowed latency.
elif [[ $serverSelection -gt $i ]]; then
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 )
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
@ -306,7 +306,7 @@ For example, you can try 0.2 for 200ms allowed latency.
fi
else
# 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
VPN_PROTOCOL=no ./get_region.sh
if [[ $? != 1 ]]; then
@ -328,27 +328,27 @@ case $VPN_PROTOCOL in
;;
none | *)
echo -n "Connection method ([W]ireguard/[o]penvpn): "
read connection_method
read -r connection_method
echo
VPN_PROTOCOL="wireguard"
if echo ${connection_method:0:1} | grep -iq o; then
if echo "${connection_method:0:1}" | grep -iq o; then
echo -n "Connection method ([U]dp/[t]cp): "
read protocolInput
read -r protocolInput
echo
protocol="udp"
if echo ${protocolInput:0:1} | grep -iq t; then
if echo "${protocolInput:0:1}" | grep -iq t; then
protocol="tcp"
fi
echo "Higher levels of encryption trade performance for security. "
echo -n "Do you want to use strong encryption ([N]o/[y]es): "
read strongEncryption
read -r strongEncryption
echo
encryption="standard"
if echo ${strongEncryption:0:1} | grep -iq y; then
if echo "${strongEncryption:0:1}" | grep -iq y; then
encryption="strong"
fi
@ -375,10 +375,10 @@ if [[ $setDNS = "yes" ]]; then
if [[ ! $PIA_DNS || $PIA_DNS = "" ]]; then
echo Using third party DNS could allow DNS monitoring.
echo -n "Do you want to force PIA DNS ([Y]es/[n]o): "
read setDNS
read -r setDNS
echo
PIA_DNS="true"
if echo ${setDNS:0:1} | grep -iq n; then
if echo "${setDNS:0:1}" | grep -iq n; then
PIA_DNS="false"
fi
fi