Skip to content

Commit af777ae

Browse files
committed
Use the most recent tun device (only one).
1 parent fdeaf0f commit af777ae

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

ipfw.rules

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ ipfw -q -f flush add
1111
${cmd} 00193 deny all from any to any uid ${user}
1212

1313
# Get the tunnel id dynamically
14-
vpn="$(ifconfig | grep -v "groups" | grep "tun" | cut -d ":" -f1 | head -n 1)"
14+
vpn="$(ifconfig | grep -v "groups" | grep "tun" | cut -d ":" -f1 | tail -n 1)"
1515
while [ -z "${vpn}" ] && [ "${try:="0"}" -le "20" ]; do
16-
vpn="$(ifconfig | grep -v "groups" | grep "tun" | cut -d ":" -f1 | head -n 1)"
16+
vpn="$(ifconfig | grep -v "groups" | grep "tun" | cut -d ":" -f1 | tail -n 1)"
1717
try="$(( try + 1 ))"
1818
sleep 3
1919
done

pia-port-forward.sh

+9-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ vpnUser="transmission"
2525
vpnDir="/usr/local/etc/openvpn"
2626
tempDir="/tmp/piaPort"
2727
curlMaxTime="15"
28+
firewallScript="/mnt/scripts/trans/ipfw.rules"
2829
payloadFile="${tempDir}/payload.sig"
2930
passFile="${vpnDir}/pass.txt"
3031

@@ -62,15 +63,21 @@ function VPN_Status() {
6263
# set adaptorName
6364
# Config
6465
local tunnelAdapter
66+
local tunnelAdapters
6567
local try
6668

67-
tunnelAdapter="$(ifconfig | grep -v "groups" | grep "tun" | cut -d ":" -f1)"
69+
tunnelAdapter="$(ifconfig | grep -v "groups" | grep "tun" | cut -d ":" -f1 | tail -n 1)"
6870
while [ -z "${tunnelAdapter}" ] && [ "${try:=0}" -le "20" ]; do
69-
tunnelAdapter="$(ifconfig | grep -v "groups" | grep "tun" | cut -d ":" -f1)"
71+
tunnelAdapter="$(ifconfig | grep -v "groups" | grep "tun" | cut -d ":" -f1 | tail -n 1)"
7072
try="$(( try + 1 ))"
7173
sleep 3
7274
done
7375

76+
readarray -t tunnelAdapters <<< "$(ifconfig | grep -v "groups" | grep "tun" | cut -d ":" -f1)"
77+
if [ "${#tunnelAdapters[@]}" -gt "1" ]; then
78+
${firewallScript}
79+
fi
80+
7481
if [ -z "${tunnelAdapter}" ]; then
7582
return 1
7683
else

0 commit comments

Comments
 (0)