@@ -40,8 +40,6 @@ if [[ -z "${PIA_USER}" || -z "${PIA_PASS}" ]]; then
40
40
exit 1
41
41
fi
42
42
43
- tokenLocation=/opt/piavpn-manual/token
44
-
45
43
echo -n "Checking login credentials..."
46
44
47
45
generateTokenResponse=$(curl -s -u "${PIA_USER}:${PIA_PASS}" \
60
58
token=$(echo "$generateTokenResponse" | jq -r '.token')
61
59
tokenExpiration=$(timeout_timestamp)
62
60
PIA_TOKEN=$token
63
- echo $token > /opt/piavpn-manual/token || exit 1
64
- echo $tokenExpiration >> /opt/piavpn-manual/token
61
+ echo " $token" > /opt/piavpn-manual/token || exit 1
62
+ echo " $tokenExpiration" >> /opt/piavpn-manual/token
65
63
echo
66
64
echo "PIA_TOKEN=$PIA_TOKEN"
67
- echo This token will expire in 24 hours, on $tokenExpiration.
65
+ echo This token will expire in 24 hours, on " $tokenExpiration" .
68
66
echo
69
67
70
68
# If the server list has less than 1000 characters, it means curl failed.
@@ -87,7 +85,7 @@ function check_all_region_data() {
87
85
# Get all data for the selected region
88
86
# Exit with code 1 if the REGION_ID provided is invalid
89
87
function get_selected_region_data() {
90
- regionData="$( echo $all_region_data |
88
+ regionData="$( echo " $all_region_data" |
91
89
jq --arg REGION_ID "$selectedRegion" -r \
92
90
'.regions[] | select(.id==$REGION_ID)')"
93
91
if [[ ! $regionData ]]; then
@@ -117,18 +115,18 @@ serverlist_url='https://serverlist.piaservers.net/vpninfo/servers/v6'
117
115
printServerLatency() {
118
116
serverIP="$1"
119
117
regionID="$2"
120
- regionName="$(echo ${@:3} |
118
+ regionName="$(echo " ${@:3}" |
121
119
sed 's/ false//' | sed 's/true/(geo)/')"
122
120
time=$(LC_NUMERIC=en_US.utf8 curl -o /dev/null -s \
123
- --connect-timeout $MAX_LATENCY \
121
+ --connect-timeout " $MAX_LATENCY" \
124
122
--write-out "%{time_connect}" \
125
- http://$serverIP:443)
123
+ http://" $serverIP" :443)
126
124
if [ $? -eq 0 ]; then
127
- >&2 echo Got latency ${time}s for region: $regionName id: $regionID
128
- echo $time $regionID $serverIP
125
+ >&2 echo Got latency " ${time}" s for region: " $regionName" id: " $regionID"
126
+ echo " $time" " $regionID" " $serverIP"
129
127
# Write a list of servers with acceptable latancy
130
128
# to /opt/piavpn-manual/latencyList
131
- echo -e $time $regionID'\t'$serverIP'\t'$regionName >> /opt/piavpn-manual/latencyList
129
+ echo -e " $time" " $regionID" '\t'" $serverIP" '\t'" $regionName" >> /opt/piavpn-manual/latencyList
132
130
fi
133
131
# Sort the latencyList, ordered by latency
134
132
sort -no /opt/piavpn-manual/latencyList /opt/piavpn-manual/latencyList
@@ -164,23 +162,23 @@ if [[ $selectedRegion == "none" ]]; then
164
162
if [[ $PIA_PF == "true" ]]; then
165
163
echo Port Forwarding is enabled, non-PF servers excluded.
166
164
echo
167
- summarized_region_data="$( echo $all_region_data |
165
+ summarized_region_data="$( echo " $all_region_data" |
168
166
jq -r '.regions[] | select(.port_forward==true) |
169
167
.servers.meta[0].ip+" "+.id+" "+.name+" "+(.geo|tostring)' )"
170
168
else
171
- summarized_region_data="$( echo $all_region_data |
169
+ summarized_region_data="$( echo " $all_region_data" |
172
170
jq -r '.regions[] |
173
171
.servers.meta[0].ip+" "+.id+" "+.name+" "+(.geo|tostring)' )"
174
172
fi
175
173
echo -e Testing regions that respond \
176
- faster than $MAX_LATENCY seconds:
174
+ faster than " $MAX_LATENCY" seconds:
177
175
selectedRegion="$(echo "$summarized_region_data" |
178
176
xargs -I{} bash -c 'printServerLatency {}' |
179
177
sort | head -1 | awk '{ print $2 }')"
180
178
echo
181
179
182
180
if [ -z "$selectedRegion" ]; then
183
- echo -e No region responded within ${MAX_LATENCY}s, consider using a higher timeout.
181
+ echo -e No region responded within " ${MAX_LATENCY}" s, consider using a higher timeout.
184
182
echo For example, to wait 1 second for each region, inject MAX_LATENCY=1 like this:
185
183
exit 1
186
184
else
195
193
196
194
get_selected_region_data
197
195
198
- bestServer_meta_IP="$(echo $regionData | jq -r '.servers.meta[0].ip')"
199
- bestServer_meta_hostname="$(echo $regionData | jq -r '.servers.meta[0].cn')"
200
- bestServer_WG_IP="$(echo $regionData | jq -r '.servers.wg[0].ip')"
201
- bestServer_WG_hostname="$(echo $regionData | jq -r '.servers.wg[0].cn')"
202
- bestServer_OT_IP="$(echo $regionData | jq -r '.servers.ovpntcp[0].ip')"
203
- bestServer_OT_hostname="$(echo $regionData | jq -r '.servers.ovpntcp[0].cn')"
204
- bestServer_OU_IP="$(echo $regionData | jq -r '.servers.ovpnudp[0].ip')"
205
- bestServer_OU_hostname="$(echo $regionData | jq -r '.servers.ovpnudp[0].cn')"
196
+ bestServer_meta_IP="$(echo " $regionData" | jq -r '.servers.meta[0].ip')"
197
+ bestServer_meta_hostname="$(echo " $regionData" | jq -r '.servers.meta[0].cn')"
198
+ bestServer_WG_IP="$(echo " $regionData" | jq -r '.servers.wg[0].ip')"
199
+ bestServer_WG_hostname="$(echo " $regionData" | jq -r '.servers.wg[0].cn')"
200
+ bestServer_OT_IP="$(echo " $regionData" | jq -r '.servers.ovpntcp[0].ip')"
201
+ bestServer_OT_hostname="$(echo " $regionData" | jq -r '.servers.ovpntcp[0].cn')"
202
+ bestServer_OU_IP="$(echo " $regionData" | jq -r '.servers.ovpnudp[0].ip')"
203
+ bestServer_OU_hostname="$(echo " $regionData" | jq -r '.servers.ovpnudp[0].cn')"
206
204
207
205
208
206
if [[ $VPN_PROTOCOL == "no" ]]; then
209
- echo -ne The $selectedOrLowestLatency region is "$(echo $regionData | jq -r '.name')"
210
- if echo $regionData | jq -r '.geo' | grep true > /dev/null; then
207
+ echo -ne The $selectedOrLowestLatency region is "$(echo " $regionData" | jq -r '.name')"
208
+ if echo " $regionData" | jq -r '.geo' | grep true > /dev/null; then
211
209
echo " (geolocated region)."
212
210
else
213
211
echo "."
@@ -224,7 +222,6 @@ WireGuard $bestServer_WG_IP\t- $bestServer_WG_hostname
224
222
"
225
223
fi
226
224
# Display variables for troubleshooting
227
- PIA_PF=$PIA_PF
228
225
WG_SERVER_IP=$bestServer_WG_IP
229
226
WG_HOSTNAME=$bestServer_WG_hostname
230
227
@@ -253,7 +250,7 @@ export pubKey
253
250
# In case you didn't clone the entire repo, get the certificate from:
254
251
# https://github.com/pia-foss/manual-connections/blob/master/ca.rsa.4096.crt
255
252
# In case you want to troubleshoot the script, replace -s with -v.
256
- echo Trying to connect to the PIA WireGuard API on $WG_SERVER_IP...
253
+ echo Trying to connect to the PIA WireGuard API on " $WG_SERVER_IP" ...
257
254
wireguard_json="$(curl -s -G \
258
255
--connect-to "$WG_HOSTNAME::$WG_SERVER_IP:" \
259
256
--cacert "/wireguard-pia/ca.rsa.4096.crt" \
276
273
# require it.
277
274
if [ "$PIA_DNS" == true ]; then
278
275
dnsServer="$(echo "$wireguard_json" | jq -r '.dns_servers[0]')"
279
- echo Trying to set up DNS to $dnsServer. In case you do not have resolvconf,
276
+ echo Trying to set up DNS to " $dnsServer" . In case you do not have resolvconf,
280
277
echo this operation will fail and you will not get a VPN. If you have issues,
281
278
echo start this script without PIA_DNS.
282
279
echo
@@ -285,7 +282,6 @@ else dnsSettingForVPN="DNS =$(echo "$wireguard_json" | jq -r '.dns_servers[0]')"
285
282
fi
286
283
echo -n "Trying to write /config/wg0.conf..."
287
284
288
- LAN_NETWORK=${LAN_NETWORK}
289
285
# split comma separated string into array from LAN_NETWORK env variable
290
286
IFS=',' read -ra lan_network_array <<< "${LAN_NETWORK}"
291
287
DROUTE=$(ip route | grep default | awk '{print $3}');
@@ -341,8 +337,8 @@ echo "
341
337
Address = $(echo "$wireguard_json" | jq -r '.peer_ip')
342
338
PrivateKey = $privKey
343
339
DNS = $(echo "$wireguard_json" | jq -r '.dns_servers[0]')
344
- PostUp = " $PostUp"
345
- PreDown = " $PreDown"
340
+ PostUp = $PostUp
341
+ PreDown = $PreDown
346
342
347
343
[Peer]
348
344
PersistentKeepalive = 25
0 commit comments