-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrpi-networkconfig
executable file
·150 lines (131 loc) · 3.04 KB
/
rpi-networkconfig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
# Reconfigures Raspberry Pi networking control between systemd-networkd, dhcpcd, and Network Manager
function EnableAndStart() {
systemctl enable $1
systemctl start $1
}
function StopAndDisable() {
if systemctl is-enabled $1 > /dev/null 2>&1
then
systemctl stop $1
systemctl disable $1
fi
}
function DisableDHCPcd() {
systemctl daemon-reload
StopAndDisable dhcpcd
StopAndDisable wpa_supplicant
}
function DisableSystemdNetworkd() {
systemctl daemon-reload
StopAndDisable systemd-networkd
StopAndDisable systemd-resolved
echo "You may need to futz with /etc/resolv.conf, this has not been tested"
sed -i '1d' /etc/resolvconf.conf # For systemd-resolved
StopAndDisable wpa_supplicant@wlan0
}
function DisableNetworkManager() {
if dpkg-query -s network-manager > /dev/null 2>&1
then
StopAndDisable NetworkManager
StopAndDisable ModemManager
fi
}
function ReportStatus() {
local sts="disabled"
if systemctl is-enabled $1 > /dev/null 2>&1
then
sts="enabled"
fi
printf ">> %-16s %s\n" $1 $sts
}
if [[ ! $EUID -eq 0 ]];then
echo "? Please run as root: sudo $0 $1 $2"
exit 1
fi
if [ "$1" == "" ]
then
echo -n "Use [H]elp, [D]hcpcd, [S]ystemd-networkd, or [N]network Manager [S]? " ; read $2 ans
else
ans="$1"
fi
[ "$ans" == "" ] && ans="s"
case "$ans" in
d*|D*)
echo "Using dhcpcd..."
DisableSystemdNetworkd
DisableNetworkManager
EnableAndStart dhcpcd
;;
n*|N*)
echo "Using Network Manager..."
DisableDHCPcd
DisableSystemdNetworkd
if ! dpkg-query -s NetworkManager > /dev/null 2>&1
then
apt-get install network-manager
cp /root/nm/system-connections/* /etc/NetworkManager/system-connections
fi
systemctl stop NetworkManager
echo "** Make sure that wifi is connected as desired"
echo "** nmcli con up profilename"
EnableAndStart NetworkManager
# EnableAndStart ModemManager
;;
s*|S*)
echo "Using systemd-networkd..."
DisableDHCPcd
DisableNetworkManager
fn="/etc/systemd/network/10-eth0.network"
if [ ! -e $fn ]
then
echo "Creating $fn..."
cat > $fn <<EOF
[Match]
Name=eth0
[Network]
DHCP=Yes
LinkLocalAddressing=No
IPv4LL=false
[DHCP]
UseDomains=yes
EOF
fi
fn="/etc/systemd/network/11-wlan0.network"
if [ ! -e $fn ]
then
echo "Creating $fn..."
cat > $fn <<EOF
[Match]
Name=wlan0
[Network]
DHCP=ipv4
[DHCP]
RouteMetric=20
UseDomains=yes
EOF
fi
sed -i '1i resolvconf=NO' /etc/resolvconf.conf # For systemd-resolved
ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf # ...
EnableAndStart wpa_supplicant@wlan0
EnableAndStart systemd-networkd
EnableAndStart systemd-resolved
;;
h*|H*)
echo "Current Network Configuration status"
ReportStatus dhcpcd
ReportStatus systemd-networkd
ReportStatus NetworkManager
ReportStatus ModemManager
exit
;;
*)
echo "% Unrecognized network configuration selection"
echo "% Network configuration not changed"
exit
;;
esac
echo ""
echo ">> Network configuration updated"
echo ">> You must reboot the system now"
echo ""