Skip to content

Commit cc8f34b

Browse files
committed
support executing script from any path instead of requiring a cd first
1 parent 71ff88e commit cc8f34b

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
lines changed

connect_to_openvpn_with_token.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
# SOFTWARE.
2121

22+
DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
23+
2224
# This function allows you to check if the required tools have been installed.
2325
check_tool() {
2426
cmd=$1
@@ -173,7 +175,7 @@ if [[ $PIA_DNS != "true" ]]; then
173175
echo "with the env var PIA_DNS=true. Example:"
174176
echo $ OVPN_SERVER_IP=\""$OVPN_SERVER_IP"\" OVPN_HOSTNAME=\""$OVPN_HOSTNAME"\" \
175177
PIA_TOKEN=\""$PIA_TOKEN"\" CONNECTION_SETTINGS=\""$CONNECTION_SETTINGS"\" \
176-
PIA_PF=true PIA_DNS=true ./connect_to_openvpn_with_token.sh
178+
PIA_PF=true PIA_DNS=true $DIR/connect_to_openvpn_with_token.sh
177179
else
178180
cp openvpn_config/openvpn_up_dnsoverwrite.sh /opt/piavpn-manual/openvpn_up.sh
179181
cp openvpn_config/openvpn_down_dnsoverwrite.sh /opt/piavpn-manual/openvpn_down.sh
@@ -237,10 +239,10 @@ if [[ $PIA_PF != "true" ]]; then
237239
echo -e "$ ${green}PIA_TOKEN=$PIA_TOKEN" \
238240
"PF_GATEWAY=$gateway_ip" \
239241
"PF_HOSTNAME=$OVPN_HOSTNAME" \
240-
"./port_forwarding.sh${nc}"
242+
"$DIR/port_forwarding.sh${nc}"
241243
echo
242244
echo "The location used must be port forwarding enabled, or this will fail."
243-
echo "Calling the ./get_region script with PIA_PF=true will provide a filtered list."
245+
echo "Calling the $DIR/get_region script with PIA_PF=true will provide a filtered list."
244246
exit 1
245247
fi
246248

@@ -258,9 +260,9 @@ echo -e "Starting procedure to enable port forwarding by running the following c
258260
$ ${green}PIA_TOKEN=$PIA_TOKEN \\
259261
PF_GATEWAY=$gateway_ip \\
260262
PF_HOSTNAME=$OVPN_HOSTNAME \\
261-
./port_forwarding.sh${nc}"
263+
$DIR/port_forwarding.sh${nc}"
262264

263265
PIA_TOKEN=$PIA_TOKEN \
264266
PF_GATEWAY=$gateway_ip \
265267
PF_HOSTNAME=$OVPN_HOSTNAME \
266-
./port_forwarding.sh
268+
$DIR/port_forwarding.sh

connect_to_wireguard_with_token.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
# SOFTWARE.
2121

22+
DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
23+
2224
# This function allows you to check if the required tools have been installed.
2325
check_tool() {
2426
cmd=$1
@@ -172,10 +174,10 @@ if [[ $PIA_PF != "true" ]]; then
172174
echo -e "$ ${green}PIA_TOKEN=$PIA_TOKEN" \
173175
"PF_GATEWAY=$WG_SERVER_IP" \
174176
"PF_HOSTNAME=$WG_HOSTNAME" \
175-
"./port_forwarding.sh${nc}"
177+
"$DIR/port_forwarding.sh${nc}"
176178
echo
177179
echo "The location used must be port forwarding enabled, or this will fail."
178-
echo "Calling the ./get_region script with PIA_PF=true will provide a filtered list."
180+
echo "Calling the $DIR/get_region script with PIA_PF=true will provide a filtered list."
179181
exit 1
180182
fi
181183

@@ -193,9 +195,9 @@ echo -e "Starting procedure to enable port forwarding by running the following c
193195
$ ${green}PIA_TOKEN=$PIA_TOKEN \\
194196
PF_GATEWAY=$WG_SERVER_IP \\
195197
PF_HOSTNAME=$WG_HOSTNAME \\
196-
./port_forwarding.sh${nc}"
198+
$DIR/port_forwarding.sh${nc}"
197199

198200
PIA_TOKEN=$PIA_TOKEN \
199201
PF_GATEWAY=$WG_SERVER_IP \
200202
PF_HOSTNAME=$WG_HOSTNAME \
201-
./port_forwarding.sh
203+
$DIR/port_forwarding.sh

get_region.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
# SOFTWARE.
2121

22+
DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
23+
2224
# This function allows you to check if the required tools have been installed.
2325
check_tool() {
2426
cmd=$1
@@ -167,7 +169,7 @@ if [[ $selectedRegion == "none" ]]; then
167169
if [[ -z $selectedRegion ]]; then
168170
echo -e "${red}No region responded within ${MAX_LATENCY}s, consider using a higher timeout."
169171
echo "For example, to wait 1 second for each region, inject MAX_LATENCY=1 like this:"
170-
echo -e "$ MAX_LATENCY=1 ./get_region.sh${nc}"
172+
echo -e "$ MAX_LATENCY=1 $DIR/get_region.sh${nc}"
171173
exit 1
172174
else
173175
echo -e "A list of servers and connection details, ordered by latency can be
@@ -218,10 +220,10 @@ if [[ -z $PIA_TOKEN ]]; then
218220
if [[ -z $PIA_USER || -z $PIA_PASS ]]; then
219221
echo -e "${red}If you want this script to automatically get an authentication"
220222
echo "token, please add the variables PIA_USER and PIA_PASS. Example:"
221-
echo -e "$ PIA_USER=p0123456 PIA_PASS=xxx ./get_region.sh${nc}"
223+
echo -e "$ PIA_USER=p0123456 PIA_PASS=xxx $DIR/get_region.sh${nc}"
222224
exit 0
223225
fi
224-
./get_token.sh
226+
$DIR/get_token.sh
225227
PIA_TOKEN=$( awk 'NR == 1' /opt/piavpn-manual/token )
226228
export PIA_TOKEN
227229
rm -f /opt/piavpn-manual/token
@@ -232,15 +234,15 @@ fi
232234

233235
# Connect with WireGuard and clear authentication token file and latencyList
234236
if [[ $VPN_PROTOCOL == "wireguard" ]]; then
235-
echo "The ./get_region.sh script got started with"
237+
echo "The $DIR/get_region.sh script got started with"
236238
echo -e "${green}VPN_PROTOCOL=wireguard${nc}, so we will automatically connect to WireGuard,"
237239
echo "by running this command:"
238240
echo -e "$ ${green}PIA_TOKEN=$PIA_TOKEN \\"
239241
echo "WG_SERVER_IP=$bestServer_WG_IP WG_HOSTNAME=$bestServer_WG_hostname \\"
240-
echo -e "PIA_PF=$PIA_PF ./connect_to_wireguard_with_token.sh${nc}"
242+
echo -e "PIA_PF=$PIA_PF $DIR/connect_to_wireguard_with_token.sh${nc}"
241243
echo
242244
PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN WG_SERVER_IP=$bestServer_WG_IP \
243-
WG_HOSTNAME=$bestServer_WG_hostname ./connect_to_wireguard_with_token.sh
245+
WG_HOSTNAME=$bestServer_WG_hostname $DIR/connect_to_wireguard_with_token.sh
244246
rm -f /opt/piavpn-manual/latencyList
245247
exit 0
246248
fi
@@ -253,20 +255,20 @@ if [[ $VPN_PROTOCOL == openvpn* ]]; then
253255
serverIP=$bestServer_OT_IP
254256
serverHostname=$bestServer_OT_hostname
255257
fi
256-
echo "The ./get_region.sh script got started with"
258+
echo "The $DIR/get_region.sh script got started with"
257259
echo -e "${green}VPN_PROTOCOL=$VPN_PROTOCOL${nc}, so we will automatically"
258260
echo "connect to OpenVPN, by running this command:"
259261
echo -e "$ ${green}PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN \\"
260262
echo " OVPN_SERVER_IP=$serverIP \\"
261263
echo " OVPN_HOSTNAME=$serverHostname \\"
262264
echo " CONNECTION_SETTINGS=$VPN_PROTOCOL \\"
263-
echo -e " ./connect_to_openvpn_with_token.sh${nc}"
265+
echo -e " $DIR/connect_to_openvpn_with_token.sh${nc}"
264266
echo
265267
PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN \
266268
OVPN_SERVER_IP=$serverIP \
267269
OVPN_HOSTNAME=$serverHostname \
268270
CONNECTION_SETTINGS=$VPN_PROTOCOL \
269-
./connect_to_openvpn_with_token.sh
271+
$DIR/connect_to_openvpn_with_token.sh
270272
rm -f /opt/piavpn-manual/latencyList
271273
exit 0
272274
fi

get_token.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
# SOFTWARE.
2121

22+
DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
23+
2224
# This function allows you to check if the required tools have been installed.
2325
check_tool() {
2426
cmd=$1
@@ -62,7 +64,7 @@ mkdir -p /opt/piavpn-manual
6264
if [[ -z $PIA_USER || -z $PIA_PASS ]]; then
6365
echo "If you want this script to automatically get a token from the Meta"
6466
echo "service, please add the variables PIA_USER and PIA_PASS. Example:"
65-
echo "$ PIA_USER=p0123456 PIA_PASS=xxx ./get_token.sh"
67+
echo "$ PIA_USER=p0123456 PIA_PASS=xxx $DIR/get_token.sh"
6668
exit 1
6769
fi
6870

run_setup.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1919
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
# SOFTWARE.
21+
set -o xtrace
22+
23+
DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
2124

2225
# Check if terminal allows output, if yes, define colors for output
2326
if [[ -t 1 ]]; then
@@ -98,7 +101,7 @@ while :; do
98101
export PIA_PASS
99102

100103
# Confirm credentials and generate token
101-
./get_token.sh
104+
$DIR/get_token.sh
102105

103106
tokenLocation="/opt/piavpn-manual/token"
104107
# If the script failed to generate an authentication token, the script will exit early.
@@ -252,7 +255,7 @@ For example, you can try 0.2 for 200ms allowed latency.
252255
export PREFERRED_REGION
253256
VPN_PROTOCOL="no"
254257
export VPN_PROTOCOL
255-
VPN_PROTOCOL=no ./get_region.sh
258+
VPN_PROTOCOL=no $DIR/get_region.sh
256259

257260
if [[ -s /opt/piavpn-manual/latencyList ]]; then
258261
# Output the ordered list of servers that meet the latency specification $MAX_LATENCY
@@ -308,7 +311,7 @@ For example, you can try 0.2 for 200ms allowed latency.
308311
# Validate in-line declaration of PREFERRED_REGION; if invalid remove input to initiate prompts
309312
echo "Region input is : $PREFERRED_REGION"
310313
export PREFERRED_REGION
311-
VPN_PROTOCOL=no ./get_region.sh
314+
VPN_PROTOCOL=no $DIR/get_region.sh
312315
if [[ $? != 1 ]]; then
313316
break
314317
fi
@@ -391,4 +394,4 @@ echo -e "${green}PIA_DNS=$PIA_DNS${nc}"
391394
CONNECTION_READY="true"
392395
export CONNECTION_READY
393396

394-
./get_region.sh
397+
$DIR/get_region.sh

0 commit comments

Comments
 (0)