20-networking.sh
146 lines
| 5.4 KiB
| application/x-sh
|
BashLexer
/ bootstrap.d / 20-networking.sh
Filip Pytloun
|
r56 | # | ||
Jan Wagner
|
r67 | # Setup Networking | ||
Filip Pytloun
|
r56 | # | ||
Jan Wagner
|
r67 | # Load utility functions | ||
Filip Pytloun
|
r56 | . ./functions.sh | ||
Jan Wagner
|
r71 | # Install and setup hostname | ||
drtyhlpr
|
r94 | install_readonly files/network/hostname "${ETC_DIR}/hostname" | ||
Unknown
|
r384 | sed -i "s/^RaspberryPI/${HOSTNAME}/" "${ETC_DIR}/hostname" | ||
Jan Wagner
|
r67 | |||
Jan Wagner
|
r71 | # Install and setup hosts | ||
drtyhlpr
|
r94 | install_readonly files/network/hosts "${ETC_DIR}/hosts" | ||
Unknown
|
r384 | sed -i "s/RaspberryPI/${HOSTNAME}/" "${ETC_DIR}/hosts" | ||
Filip Pytloun
|
r56 | |||
Jan Wagner
|
r71 | # Setup hostname entry with static IP | ||
Filip Pytloun
|
r56 | if [ "$NET_ADDRESS" != "" ] ; then | ||
Jan Wagner
|
r75 | NET_IP=$(echo "${NET_ADDRESS}" | cut -f 1 -d'/') | ||
drtyhlpr
|
r94 | sed -i "s/^127.0.1.1/${NET_IP}/" "${ETC_DIR}/hosts" | ||
Filip Pytloun
|
r56 | fi | ||
Jan Wagner
|
r71 | # Remove IPv6 hosts | ||
if [ "$ENABLE_IPV6" = false ] ; then | ||||
drtyhlpr
|
r94 | sed -i -e "/::[1-9]/d" -e "/^$/d" "${ETC_DIR}/hosts" | ||
Filip Pytloun
|
r56 | fi | ||
Jan Wagner
|
r71 | # Install hint about network configuration | ||
drtyhlpr
|
r94 | install_readonly files/network/interfaces "${ETC_DIR}/network/interfaces" | ||
Filip Pytloun
|
r56 | |||
Jan Wagner
|
r71 | # Install configuration for interface eth0 | ||
drtyhlpr
|
r94 | install_readonly files/network/eth.network "${ETC_DIR}/systemd/network/eth.network" | ||
Jan Wagner
|
r71 | |||
Unknown
|
r250 | # Install configuration for interface wl* | ||
install_readonly files/network/wlan.network "${ETC_DIR}/systemd/network/wlan.network" | ||||
#always with dhcp since wpa_supplicant integration is missing | ||||
sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETC_DIR}/systemd/network/wlan.network" | ||||
Filip Pytloun
|
r56 | if [ "$ENABLE_DHCP" = true ] ; then | ||
Jan Wagner
|
r71 | # Enable DHCP configuration for interface eth0 | ||
drtyhlpr
|
r94 | sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETC_DIR}/systemd/network/eth.network" | ||
Unknown
|
r250 | |||
Jan Wagner
|
r70 | # Set DHCP configuration to IPv4 only | ||
Jan Wagner
|
r67 | if [ "$ENABLE_IPV6" = false ] ; then | ||
drtyhlpr
|
r94 | sed -i "s/DHCP=.*/DHCP=v4/" "${ETC_DIR}/systemd/network/eth.network" | ||
Jan Wagner
|
r67 | fi | ||
Jan Wagner
|
r70 | |||
Filip Pytloun
|
r56 | else # ENABLE_DHCP=false | ||
Jan Wagner
|
r71 | # Set static network configuration for interface eth0 | ||
sed -i\ | ||||
-e "s|DHCP=.*|DHCP=no|"\ | ||||
-e "s|Address=\$|Address=${NET_ADDRESS}|"\ | ||||
-e "s|Gateway=\$|Gateway=${NET_GATEWAY}|"\ | ||||
-e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_1}|"\ | ||||
-e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_2}|"\ | ||||
-e "s|Domains=\$|Domains=${NET_DNS_DOMAINS}|"\ | ||||
-e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_1}|"\ | ||||
-e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_2}|"\ | ||||
drtyhlpr
|
r94 | "${ETC_DIR}/systemd/network/eth.network" | ||
Unknown
|
r501 | |||
if [ "$CRYPTFS_DROPBEAR" = true ] ; then | ||||
# Get cdir from NET_ADDRESS e.g. 24 | ||||
cdir=$(${NET_ADDRESS} | cut -d '/' -f2) | ||||
# Convert cdir ro netmask e.g. 24 to 255.255.255.0 | ||||
NET_MASK=$(cdr2mask "$cdir") | ||||
# Write static ip settings to "${ETC_DIR}"/initramfs-tools/initramfs.conf | ||||
sed -i "\$aIP=${NET_ADDRESS}::${NET_GATEWAY}:${NET_MASK}:${HOSTNAME}:" "${ETC_DIR}"/initramfs-tools/initramfs.conf | ||||
# Regenerate initramfs | ||||
chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" | ||||
fi | ||||
Filip Pytloun
|
r56 | fi | ||
Jan Wagner
|
r71 | # Remove empty settings from network configuration | ||
drtyhlpr
|
r94 | sed -i "/.*=\$/d" "${ETC_DIR}/systemd/network/eth.network" | ||
Unknown
|
r250 | # Remove empty settings from wlan configuration | ||
sed -i "/.*=\$/d" "${ETC_DIR}/systemd/network/wlan.network" | ||||
Jan Wagner
|
r71 | |||
drtyhlpr
|
r92 | # Move systemd network configuration if required by Debian release | ||
Unknown
|
r384 | mv -v "${ETC_DIR}/systemd/network/eth.network" "${LIB_DIR}/systemd/network/10-eth.network" | ||
# If WLAN is enabled copy wlan configuration too | ||||
if [ "$ENABLE_WIRELESS" = true ] ; then | ||||
mv -v "${ETC_DIR}/systemd/network/wlan.network" "${LIB_DIR}/systemd/network/11-wlan.network" | ||||
drtyhlpr
|
r92 | fi | ||
Unknown
|
r384 | rm -fr "${ETC_DIR}/systemd/network" | ||
drtyhlpr
|
r92 | |||
Filip Pytloun
|
r56 | # Enable systemd-networkd service | ||
chroot_exec systemctl enable systemd-networkd | ||||
Jan Wagner
|
r71 | # Install host.conf resolver configuration | ||
drtyhlpr
|
r94 | install_readonly files/network/host.conf "${ETC_DIR}/host.conf" | ||
Jan Wagner
|
r71 | |||
Filip Pytloun
|
r56 | # Enable network stack hardening | ||
if [ "$ENABLE_HARDNET" = true ] ; then | ||||
Jan Wagner
|
r71 | # Install sysctl.d configuration files | ||
drtyhlpr
|
r94 | install_readonly files/sysctl.d/82-rpi-net-hardening.conf "${ETC_DIR}/sysctl.d/82-rpi-net-hardening.conf" | ||
Filip Pytloun
|
r56 | |||
Jan Wagner
|
r71 | # Setup resolver warnings about spoofed addresses | ||
drtyhlpr
|
r94 | sed -i "s/^# spoof warn/spoof warn/" "${ETC_DIR}/host.conf" | ||
Filip Pytloun
|
r56 | fi | ||
Stephen A. Brandli
|
r85 | |||
# Enable time sync | ||||
Unknown
|
r336 | if [ "$NET_NTP_1" != "" ] ; then | ||
Stephen A. Brandli
|
r85 | chroot_exec systemctl enable systemd-timesyncd.service | ||
fi | ||||
drtyhlpr
|
r94 | |||
# Download the firmware binary blob required to use the RPi3 wireless interface | ||||
if [ "$ENABLE_WIRELESS" = true ] ; then | ||||
Unknown
|
r336 | if [ ! -d "${WLAN_FIRMWARE_DIR}" ] ; then | ||
drtyhlpr
|
r398 | mkdir -p "${WLAN_FIRMWARE_DIR}" | ||
drtyhlpr
|
r94 | fi | ||
drtyhlpr
|
r142 | # Create temporary directory for firmware binary blob | ||
Petter Reinholdtsen
|
r174 | temp_dir=$(as_nobody mktemp -d) | ||
drtyhlpr
|
r142 | |||
Unknown
|
r250 | # Fetch firmware binary blob for RPI3B+ | ||
Unknown
|
r268 | if [ "$RPI_MODEL" = 3P ] ; then | ||
drtyhlpr
|
r398 | # Fetch firmware binary blob for RPi3P | ||
as_nobody wget -q -O "${temp_dir}/brcmfmac43455-sdio.bin" "${WLAN_FIRMWARE_URL}/brcmfmac43455-sdio.bin" | ||||
as_nobody wget -q -O "${temp_dir}/brcmfmac43455-sdio.txt" "${WLAN_FIRMWARE_URL}/brcmfmac43455-sdio.txt" | ||||
as_nobody wget -q -O "${temp_dir}/brcmfmac43455-sdio.clm_blob" "${WLAN_FIRMWARE_URL}/brcmfmac43455-sdio.clm_blob" | ||||
Unknown
|
r437 | |||
# Move downloaded firmware binary blob | ||||
mv "${temp_dir}/brcmfmac43455-sdio."* "${WLAN_FIRMWARE_DIR}/" | ||||
# Set permissions of the firmware binary blob | ||||
chown root:root "${WLAN_FIRMWARE_DIR}/brcmfmac43455-sdio."* | ||||
chmod 600 "${WLAN_FIRMWARE_DIR}/brcmfmac43455-sdio."* | ||||
Unknown
|
r289 | elif [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 0 ] ; then | ||
drtyhlpr
|
r398 | # Fetch firmware binary blob for RPi3 | ||
as_nobody wget -q -O "${temp_dir}/brcmfmac43430-sdio.bin" "${WLAN_FIRMWARE_URL}/brcmfmac43430-sdio.bin" | ||||
as_nobody wget -q -O "${temp_dir}/brcmfmac43430-sdio.txt" "${WLAN_FIRMWARE_URL}/brcmfmac43430-sdio.txt" | ||||
Unknown
|
r437 | |||
# Move downloaded firmware binary blob | ||||
mv "${temp_dir}/brcmfmac43430-sdio."* "${WLAN_FIRMWARE_DIR}/" | ||||
# Set permissions of the firmware binary blob | ||||
chown root:root "${WLAN_FIRMWARE_DIR}/brcmfmac43430-sdio."* | ||||
chmod 600 "${WLAN_FIRMWARE_DIR}/brcmfmac43430-sdio."* | ||||
Unknown
|
r250 | fi | ||
drtyhlpr
|
r142 | # Remove temporary directory for firmware binary blob | ||
rm -fr "${temp_dir}" | ||||
drtyhlpr
|
r94 | fi | ||