Skip to content

Commit a53a8f4

Browse files
committed
Dont create two layers, fix cert location
1 parent 15ffd5c commit a53a8f4

File tree

3 files changed

+29
-34
lines changed

3 files changed

+29
-34
lines changed

Diff for: Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ FROM scratch
33
LABEL maintainer="GilbN"
44
LABEL app="wireguard-pia"
55
#copy local files.
6-
COPY root/ /
7-
COPY wireguard-pia/ /
6+
COPY root/ /

Diff for: root/etc/cont-init.d/39-wg-config

+28-32
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ if [[ -z "${PIA_USER}" || -z "${PIA_PASS}" ]]; then
4040
exit 1
4141
fi
4242

43-
tokenLocation=/opt/piavpn-manual/token
44-
4543
echo -n "Checking login credentials..."
4644

4745
generateTokenResponse=$(curl -s -u "${PIA_USER}:${PIA_PASS}" \
@@ -60,11 +58,11 @@ echo
6058
token=$(echo "$generateTokenResponse" | jq -r '.token')
6159
tokenExpiration=$(timeout_timestamp)
6260
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
6563
echo
6664
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".
6866
echo
6967

7068
# If the server list has less than 1000 characters, it means curl failed.
@@ -87,7 +85,7 @@ function check_all_region_data() {
8785
# Get all data for the selected region
8886
# Exit with code 1 if the REGION_ID provided is invalid
8987
function get_selected_region_data() {
90-
regionData="$( echo $all_region_data |
88+
regionData="$( echo "$all_region_data" |
9189
jq --arg REGION_ID "$selectedRegion" -r \
9290
'.regions[] | select(.id==$REGION_ID)')"
9391
if [[ ! $regionData ]]; then
@@ -117,18 +115,18 @@ serverlist_url='https://serverlist.piaservers.net/vpninfo/servers/v6'
117115
printServerLatency() {
118116
serverIP="$1"
119117
regionID="$2"
120-
regionName="$(echo ${@:3} |
118+
regionName="$(echo "${@:3}" |
121119
sed 's/ false//' | sed 's/true/(geo)/')"
122120
time=$(LC_NUMERIC=en_US.utf8 curl -o /dev/null -s \
123-
--connect-timeout $MAX_LATENCY \
121+
--connect-timeout "$MAX_LATENCY" \
124122
--write-out "%{time_connect}" \
125-
http://$serverIP:443)
123+
http://"$serverIP":443)
126124
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"
129127
# Write a list of servers with acceptable latancy
130128
# 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
132130
fi
133131
# Sort the latencyList, ordered by latency
134132
sort -no /opt/piavpn-manual/latencyList /opt/piavpn-manual/latencyList
@@ -164,23 +162,23 @@ if [[ $selectedRegion == "none" ]]; then
164162
if [[ $PIA_PF == "true" ]]; then
165163
echo Port Forwarding is enabled, non-PF servers excluded.
166164
echo
167-
summarized_region_data="$( echo $all_region_data |
165+
summarized_region_data="$( echo "$all_region_data" |
168166
jq -r '.regions[] | select(.port_forward==true) |
169167
.servers.meta[0].ip+" "+.id+" "+.name+" "+(.geo|tostring)' )"
170168
else
171-
summarized_region_data="$( echo $all_region_data |
169+
summarized_region_data="$( echo "$all_region_data" |
172170
jq -r '.regions[] |
173171
.servers.meta[0].ip+" "+.id+" "+.name+" "+(.geo|tostring)' )"
174172
fi
175173
echo -e Testing regions that respond \
176-
faster than $MAX_LATENCY seconds:
174+
faster than "$MAX_LATENCY" seconds:
177175
selectedRegion="$(echo "$summarized_region_data" |
178176
xargs -I{} bash -c 'printServerLatency {}' |
179177
sort | head -1 | awk '{ print $2 }')"
180178
echo
181179

182180
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.
184182
echo For example, to wait 1 second for each region, inject MAX_LATENCY=1 like this:
185183
exit 1
186184
else
@@ -195,19 +193,19 @@ fi
195193

196194
get_selected_region_data
197195

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')"
206204

207205

208206
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
211209
echo " (geolocated region)."
212210
else
213211
echo "."
@@ -224,7 +222,6 @@ WireGuard $bestServer_WG_IP\t- $bestServer_WG_hostname
224222
"
225223
fi
226224
# Display variables for troubleshooting
227-
PIA_PF=$PIA_PF
228225
WG_SERVER_IP=$bestServer_WG_IP
229226
WG_HOSTNAME=$bestServer_WG_hostname
230227

@@ -253,7 +250,7 @@ export pubKey
253250
# In case you didn't clone the entire repo, get the certificate from:
254251
# https://github.com/pia-foss/manual-connections/blob/master/ca.rsa.4096.crt
255252
# 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"...
257254
wireguard_json="$(curl -s -G \
258255
--connect-to "$WG_HOSTNAME::$WG_SERVER_IP:" \
259256
--cacert "/wireguard-pia/ca.rsa.4096.crt" \
@@ -276,7 +273,7 @@ fi
276273
# require it.
277274
if [ "$PIA_DNS" == true ]; then
278275
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,
280277
echo this operation will fail and you will not get a VPN. If you have issues,
281278
echo start this script without PIA_DNS.
282279
echo
@@ -285,7 +282,6 @@ else dnsSettingForVPN="DNS =$(echo "$wireguard_json" | jq -r '.dns_servers[0]')"
285282
fi
286283
echo -n "Trying to write /config/wg0.conf..."
287284

288-
LAN_NETWORK=${LAN_NETWORK}
289285
# split comma separated string into array from LAN_NETWORK env variable
290286
IFS=',' read -ra lan_network_array <<< "${LAN_NETWORK}"
291287
DROUTE=$(ip route | grep default | awk '{print $3}');
@@ -341,8 +337,8 @@ echo "
341337
Address = $(echo "$wireguard_json" | jq -r '.peer_ip')
342338
PrivateKey = $privKey
343339
DNS = $(echo "$wireguard_json" | jq -r '.dns_servers[0]')
344-
PostUp = "$PostUp"
345-
PreDown = "$PreDown"
340+
PostUp = $PostUp
341+
PreDown = $PreDown
346342

347343
[Peer]
348344
PersistentKeepalive = 25
File renamed without changes.

0 commit comments

Comments
 (0)