Skip to content

Commit 29fc5c3

Browse files
authored
Update install.sh
Network Interface Update for Latest Ubuntu & `Need Restart` Disabled
1 parent 8a73ba5 commit 29fc5c3

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

install.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
#!/bin/bash
2-
wan=$(ip -f inet -o addr show eth0|cut -d\ -f 7 | cut -d/ -f 1)
3-
wlan=$(ip -f inet -o addr show wlan0|cut -d\ -f 7 | cut -d/ -f 1)
2+
3+
if dpkg-query -W needrestart >/dev/null 2>&1; then
4+
sudo sed -i 's/#$nrconf{restart} = '"'"'i'"'"';/$nrconf{restart} = '"'"'a'"'"';/g' /etc/needrestart/needrestart.conf
5+
fi
6+
7+
# Get the interface name for the WAN connection using ip a command
8+
INTERFACE_NAME=$(ip a | awk '/state UP/ {print $2}' | tr -d ':')
9+
if [[ $INTERFACE_NAME == *"w"* ]]
10+
then
11+
# WLAN connection detected
12+
wan=$(ip -f inet -o addr show $INTERFACE_NAME|cut -d\ -f 7 | cut -d/ -f 1)
13+
else
14+
# Ethernet connection detected
15+
wan=$(ip -f inet -o addr show $INTERFACE_NAME|cut -d\ -f 7 | cut -d/ -f 1)
16+
fi
17+
418
ppp1=$(/sbin/ip route | awk '/default/ { print $3 }')
519
ip=$(dig +short myip.opendns.com @resolver1.opendns.com)
620

@@ -34,10 +48,10 @@ if [ -z "$wan" ]
3448
$("sudo iptables -I INPUT -s $ip/8 -i ppp0 -j ACCEPT")
3549
sudo iptables --append FORWARD --in-interface wlan0 -j ACCEPT
3650
else
37-
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE && iptables-save
51+
sudo iptables -t nat -A POSTROUTING -o $INTERFACE_NAME -j MASQUERADE && iptables-save
3852
sudo iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE
3953
$("sudo iptables -I INPUT -s $ip/8 -i ppp0 -j ACCEPT")
40-
sudo iptables --append FORWARD --in-interface eth0 -j ACCEPT
54+
sudo iptables --append FORWARD --in-interface $INTERFACE_NAME -j ACCEPT
4155
fi
4256

4357
clear

0 commit comments

Comments
 (0)