##// END OF EJS Templates
Add files via upload...
Bobberty -
r748:9bc2dc32b38f
parent child
Show More
@@ -1,186 +1,189
1 1 #
2 2 # Setup Networking
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Install and setup hostname
9 9 install_readonly files/network/hostname "${ETC_DIR}/hostname"
10 10 sed -i "s/^RaspberryPI/${HOSTNAME}/" "${ETC_DIR}/hostname"
11 11
12 12 # Install and setup hosts
13 13 install_readonly files/network/hosts "${ETC_DIR}/hosts"
14 14 sed -i "s/RaspberryPI/${HOSTNAME}/" "${ETC_DIR}/hosts"
15 15
16 # Ensure /etc/systemd/network directory is available
17 mkdir -p "${ETC_DIR}/systemd/network"
18
16 19 # Setup hostname entry with static IP
17 20 if [ "$NET_ETH_ADDRESS" != "" ] ; then
18 21 NET_IP=$(echo "${NET_ETH_ADDRESS}" | cut -f 1 -d'/')
19 22 sed -i "s/^127.0.1.1/${NET_IP}/" "${ETC_DIR}/hosts"
20 23 fi
21 24
22 25 # Remove IPv6 hosts
23 26 if [ "$ENABLE_IPV6" = false ] ; then
24 27 sed -i -e "/::[1-9]/d" -e "/^$/d" "${ETC_DIR}/hosts"
25 28 fi
26 29
27 30 # Install hint about network configuration
28 31 install_readonly files/network/interfaces "${ETC_DIR}/network/interfaces"
29 32
30 33 # Install configuration for interface eth0
31 34 install_readonly files/network/eth0.network "${ETC_DIR}/systemd/network/eth0.network"
32 35
33 36 if [ "$RPI_MODEL" = 3P ] ; then
34 37 printf "\n[Link]\nGenericReceiveOffload=off\nTCPSegmentationOffload=off\nGenericSegmentationOffload=off" >> "${ETC_DIR}/systemd/network/eth0.network"
35 38 fi
36 39
37 40 # Install configuration for interface wl*
38 41 install_readonly files/network/wlan0.network "${ETC_DIR}/systemd/network/wlan0.network"
39 42
40 43 #always with dhcp since wpa_supplicant integration is missing
41 44 sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETC_DIR}/systemd/network/wlan0.network"
42 45
43 46 if [ "$ENABLE_ETH_DHCP" = true ] ; then
44 47 # Enable DHCP configuration for interface eth0
45 48 sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETC_DIR}/systemd/network/eth0.network"
46 49
47 50 # Set DHCP configuration to IPv4 only
48 51 if [ "$ENABLE_IPV6" = false ] ; then
49 52 sed -i "s/DHCP=.*/DHCP=v4/" "${ETC_DIR}/systemd/network/eth0.network"
50 53 sed '/IPv6PrivacyExtensions=true/d' "${ETC_DIR}/systemd/network/eth0.network"
51 54 fi
52 55
53 56 else # ENABLE_ETH_DHCP=false
54 57 # Set static network configuration for interface eth0
55 58 if [ -n NET_ETH_ADDRESS ] && [ -n NET_ETH_GATEWAY ] && [ -n NET_ETH_DNS_1 ] ; then
56 59 sed -i\
57 60 -e "s|DHCP=.*|DHCP=no|"\
58 61 -e "s|Address=\$|Address=${NET_ETH_ADDRESS}|"\
59 62 -e "s|Gateway=\$|Gateway=${NET_ETH_GATEWAY}|"\
60 63 -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_ETH_DNS_1}|"\
61 64 -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_ETH_DNS_2}|"\
62 65 -e "s|Domains=\$|Domains=${NET_ETH_DNS_DOMAINS}|"\
63 66 -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_ETH_NTP_1}|"\
64 67 -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_ETH_NTP_2}|"\
65 68 "${ETC_DIR}/systemd/network/eth0.network"
66 69 fi
67 70 fi
68 71
69 72
70 73 if [ "$ENABLE_WIRELESS" = true ] ; then
74 mkdir -p "${ETC_DIR}/wpa_supplicant"
71 75 if [ "$ENABLE_WIFI_DHCP" = true ] ; then
72 76 # Enable DHCP configuration for interface eth0
73 77 sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETC_DIR}/systemd/network/wlan0.network"
74 78
75 79 # Set DHCP configuration to IPv4 only
76 80 if [ "$ENABLE_IPV6" = false ] ; then
77 81 sed -i "s/DHCP=.*/DHCP=v4/" "${ETC_DIR}/systemd/network/wlan0.network"
78 82 sed '/IPv6PrivacyExtensions=true/d' "${ETC_DIR}/systemd/network/wlan0.network"
79 83 fi
80 84
81 85 else # ENABLE_WIFI_DHCP=false
82 86 # Set static network configuration for interface eth0
83 87 if [ -n NET_WIFI_ADDRESS ] && [ -n NET_WIFI_GATEWAY ] && [ -n NET_WIFI_DNS_1 ] ; then
84 88 sed -i\
85 89 -e "s|DHCP=.*|DHCP=no|"\
86 90 -e "s|Address=\$|Address=${NET_WIFI_ADDRESS}|"\
87 91 -e "s|Gateway=\$|Gateway=${NET_WIFI_GATEWAY}|"\
88 92 -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_WIFI_DNS_1}|"\
89 93 -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_WIFI_DNS_2}|"\
90 94 -e "s|Domains=\$|Domains=${NET_WIFI_DNS_DOMAINS}|"\
91 95 -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_WIFI_NTP_1}|"\
92 96 -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_WIFI_NTP_2}|"\
93 97 "${ETC_DIR}/systemd/network/wlan0.network"
94 98 fi
95 99 fi
96 100
97 101 if [ ! -z "$NET_WIFI_SSID" ] && [ ! -z "$NET_WIFI_PSK" ] ; then
98 102 chroot_exec printf "
99 103 ctrl_interface=/run/wpa_supplicant
100 ctrl_interface_group=wheel
101 104 update_config=1
102 105 eapol_version=1
103 106 ap_scan=1
104 107 fast_reauth=1
105 108
106 " > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
109 " > "${ETC_DIR}/wpa_supplicant/wpa_supplicant-wlan0.conf"
107 110
108 111 #Configure WPA_supplicant
109 chroot_exec wpa_passphrase "$NET_SSID" "$NET_WPAPSK" >> /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
112 chroot_exec wpa_passphrase "$NET_WIFI_SSID" "$NET_WIFI_PSK" >> "${ETC_DIR}/wpa_supplicant/wpa_supplicant-wlan0.conf"
110 113
111 114 chroot_exec systemctl enable wpa_supplicant.service
112 115 chroot_exec systemctl enable wpa_supplicant@wlan0.service
113 116 fi
114 117 # Remove empty settings from wlan configuration
115 118 sed -i "/.*=\$/d" "${ETC_DIR}/systemd/network/wlan0.network"
116 119 # If WLAN is enabled copy wlan configuration too
117 120 mv -v "${ETC_DIR}/systemd/network/wlan0.network" "${LIB_DIR}/systemd/network/11-wlan0.network"
118 121 fi
119 122
120 123 # Remove empty settings from network configuration
121 124 sed -i "/.*=\$/d" "${ETC_DIR}/systemd/network/eth0.network"
122 125
123 126 # Move systemd network configuration if required by Debian release
124 127 mv -v "${ETC_DIR}/systemd/network/eth0.network" "${LIB_DIR}/systemd/network/10-eth0.network"
125 128
126 129 #Clean up
127 130 rm -fr "${ETC_DIR}/systemd/network"
128 131
129 132 # Enable systemd-networkd service
130 133 chroot_exec systemctl enable systemd-networkd
131 134
132 135 # Install host.conf resolver configuration
133 136 install_readonly files/network/host.conf "${ETC_DIR}/host.conf"
134 137
135 138 # Enable network stack hardening
136 139 if [ "$ENABLE_HARDNET" = true ] ; then
137 140 # Install sysctl.d configuration files
138 141 install_readonly files/sysctl.d/82-rpi-net-hardening.conf "${ETC_DIR}/sysctl.d/82-rpi-net-hardening.conf"
139 142
140 143 # Setup resolver warnings about spoofed addresses
141 144 sed -i "s/^# spoof warn/spoof warn/" "${ETC_DIR}/host.conf"
142 145 fi
143 146
144 147 # Enable time sync
145 148 if [ "$NET_NTP_1" != "" ] ; then
146 149 chroot_exec systemctl enable systemd-timesyncd.service
147 150 fi
148 151
149 152 # Download the firmware binary blob required to use the RPi3 wireless interface
150 153 if [ "$ENABLE_WIRELESS" = true ] ; then
151 154 if [ ! -d "${WLAN_FIRMWARE_DIR}" ] ; then
152 155 mkdir -p "${WLAN_FIRMWARE_DIR}"
153 156 fi
154 157
155 158 # Create temporary directory for firmware binary blob
156 159 temp_dir=$(as_nobody mktemp -d)
157 160
158 161 # Fetch firmware binary blob for RPI3B+
159 162 if [ "$RPI_MODEL" = 3P ] || [ "$RPI_MODEL" = 4 ] ; then
160 163 # Fetch firmware binary blob for RPi3P
161 164 as_nobody wget -q -O "${temp_dir}/brcmfmac43455-sdio.bin" "${WLAN_FIRMWARE_URL}/brcmfmac43455-sdio.bin"
162 165 as_nobody wget -q -O "${temp_dir}/brcmfmac43455-sdio.txt" "${WLAN_FIRMWARE_URL}/brcmfmac43455-sdio.txt"
163 166 as_nobody wget -q -O "${temp_dir}/brcmfmac43455-sdio.clm_blob" "${WLAN_FIRMWARE_URL}/brcmfmac43455-sdio.clm_blob"
164 167
165 168 # Move downloaded firmware binary blob
166 169 mv "${temp_dir}/brcmfmac43455-sdio."* "${WLAN_FIRMWARE_DIR}/"
167 170
168 171 # Set permissions of the firmware binary blob
169 172 chown root:root "${WLAN_FIRMWARE_DIR}/brcmfmac43455-sdio."*
170 173 chmod 600 "${WLAN_FIRMWARE_DIR}/brcmfmac43455-sdio."*
171 174 elif [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 0 ] ; then
172 175 # Fetch firmware binary blob for RPi3
173 176 as_nobody wget -q -O "${temp_dir}/brcmfmac43430-sdio.bin" "${WLAN_FIRMWARE_URL}/brcmfmac43430-sdio.bin"
174 177 as_nobody wget -q -O "${temp_dir}/brcmfmac43430-sdio.txt" "${WLAN_FIRMWARE_URL}/brcmfmac43430-sdio.txt"
175 178
176 179 # Move downloaded firmware binary blob
177 180 mv "${temp_dir}/brcmfmac43430-sdio."* "${WLAN_FIRMWARE_DIR}/"
178 181
179 182 # Set permissions of the firmware binary blob
180 183 chown root:root "${WLAN_FIRMWARE_DIR}/brcmfmac43430-sdio."*
181 184 chmod 600 "${WLAN_FIRMWARE_DIR}/brcmfmac43430-sdio."*
182 185 fi
183 186
184 187 # Remove temporary directory for firmware binary blob
185 188 rm -fr "${temp_dir}"
186 189 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant