Skip to content

Commit c5b7ab8

Browse files
committed
Add support for network manager and wpa-supplicant in network module #219 raspberrypi/bookworm-feedback#72
1 parent 4526f28 commit c5b7ab8

File tree

6 files changed

+82
-13
lines changed

6 files changed

+82
-13
lines changed

src/modules/network/config

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@
1010
# on reboots
1111
# udev - creates a udev rules that should affect all wifi devices.
1212

13-
[ -n "$NETWORK_PWRSAVE_TYPE" ] || NETWORK_PWRSAVE_TYPE=udev
13+
[ -n "$NETWORK_PWRSAVE_TYPE" ] || NETWORK_PWRSAVE_TYPE=udev
14+
15+
# Enable WPA-Supplicant boot folder support (pre rpios bookworm)
16+
[ -n "$NETWORK_WPA_SUPPLICANT" ] || NETWORK_WPA_SUPPLICANT=no
17+
18+
# Enable Network Manager boot folder support (bookworm)
19+
[ -n "$NETWORK_NETWORK_MANAGER" ] || NETWORK_NETWORK_MANAGER=yes
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Uncomment everything below this line and set your ssid and password
2+
# [connection]
3+
# id=wifi
4+
# uuid=593819b8-135a-4a3e-9611-c36cdeadbeef
5+
# type=wifi
6+
# interface-name=wlan0
7+
8+
# [wifi]
9+
# mode=infrastructure
10+
# ssid=set your wifi ssid here
11+
12+
# [wifi-security]
13+
# auth-alg=open
14+
# key-mgmt=wpa-psk
15+
# psk=set your password here
16+
17+
# [ipv4]
18+
# method=auto
19+
20+
# [ipv6]
21+
# addr-gen-mode=default
22+
# method=auto
23+
24+
# [proxy]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#### Enable network manager configuration from boot
2+
####
3+
#### Written by Guy Sheffer <guysoft at gmail dot com>
4+
#### Copyright 2024
5+
#### https://github.com/guysoft/CustomPiOS
6+
####
7+
#### This File is distributed under GPLv3
8+
9+
[Unit]
10+
Description=persistent setup on %I
11+
Wants=network-pre.target
12+
Before=network-pre.target
13+
BindsTo=sys-subsystem-net-devices-%i.device
14+
After=sys-subsystem-net-devices-%i.device
15+
16+
[Service]
17+
ExecStart=/opt/custompios/copy-network-manager-config %I
18+
Type=oneshot
19+
20+
[Install]
21+
WantedBy=multi-user.target
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
(
3+
echo "# DO NOT EDIT THIS FILE"
4+
echo "# Edit /boot/firmware/wifi.nmconnection and it will be copied here"
5+
cat /boot/firmware/wifi.nmconnection
6+
) > /etc/NetworkManager/system-connections/wifi.nmconnection
7+
chmod 600 /etc/NetworkManager/system-connections/wifi.nmconnection
8+
echo Done

src/modules/network/start_chroot_script

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,39 @@ export LC_ALL=C
1212
source /common.sh
1313
install_cleanup_trap
1414

15-
unpack /filesystem/boot /"${BASE_BOOT_MOUNT_PATH}"
15+
if [ "${NETWORK_WPA_SUPPLICANT}" == "yes" ]; then
16+
unpack /filesystem/wpa-supplicant/boot /"${BASE_BOOT_MOUNT_PATH}"
17+
DIST_NETWORK_FILE=/"${BASE_BOOT_MOUNT_PATH}"/${DIST_NAME,,}-wpa-supplicant.txt
1618

17-
DIST_NETWORK_FILE=/"${BASE_BOOT_MOUNT_PATH}"/${DIST_NAME,,}-wpa-supplicant.txt
19+
# allow configuring multiple wifi networks via /boot/DIST_NAME-wpa-supplicant.txt
20+
mv /"${BASE_BOOT_MOUNT_PATH}"/custompios-wpa-supplicant.txt ${DIST_NETWORK_FILE}
1821

19-
# allow configuring multiple wifi networks via /boot/DIST_NAME-wpa-supplicant.txt
20-
mv /"${BASE_BOOT_MOUNT_PATH}"/custompios-wpa-supplicant.txt ${DIST_NETWORK_FILE}
22+
if [ "${BASE_DISTRO}" == "ubuntu" ] || [ "${BASE_DISTRO}" == "armbian" ]; then
23+
echo "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev" > /etc/wpa_supplicant/wpa_supplicant.conf
24+
echo "update_config=1" >> /etc/wpa_supplicant/wpa_supplicant.conf
25+
fi
2126

22-
if [ "${BASE_DISTRO}" == "ubuntu" ] || [ "${BASE_DISTRO}" == "armbian" ]; then
23-
echo "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev" > /etc/wpa_supplicant/wpa_supplicant.conf
24-
echo "update_config=1" >> /etc/wpa_supplicant/wpa_supplicant.conf
27+
cat /etc/wpa_supplicant/wpa_supplicant.conf >> ${DIST_NETWORK_FILE} # append distributed conf to our own
28+
rm -f /etc/wpa_supplicant/wpa_supplicant.conf # remove distributed conf
29+
30+
# create symlink
31+
ln -s "${DIST_NETWORK_FILE}" /etc/wpa_supplicant/wpa_supplicant.conf
2532
fi
2633

27-
cat /etc/wpa_supplicant/wpa_supplicant.conf >> ${DIST_NETWORK_FILE} # append distributed conf to our own
28-
rm -f /etc/wpa_supplicant/wpa_supplicant.conf # remove distributed conf
34+
if [ "${NETWORK_NETWORK_MANAGER}" == "yes" ]; then
35+
unpack filesystem/network-manager/root / root
36+
unpack filesystem/network-manager/boot /"${BASE_BOOT_MOUNT_PATH}"
37+
38+
# mv /"${BASE_BOOT_MOUNT_PATH}"/wifi.nmconnection ${DIST_NETWORK_FILE}
39+
40+
systemctl_if_exists enable [email protected]
41+
fi
2942

3043
if [ "${BASE_DISTRO}" == "raspbian" ]; then
3144
# Workaround rfkill not unblocking on boot
3245
rm /var/lib/systemd/rfkill/*
3346
fi
3447

35-
# create symlink
36-
ln -s "${DIST_NETWORK_FILE}" /etc/wpa_supplicant/wpa_supplicant.conf
37-
3848
# copy /etc/wpa_supplicant/ifupdown.sh to /etc/ifplugd/action.d/ifupdown - for wlan auto reconnect
3949
[ -f /etc/ifplugd/action.d/ifupdown ] && mv /etc/ifplugd/action.d/ifupdown /etc/ifplugd/action.d/ifupdown.original
4050
[ -f /etc/wpa_supplicant/ifupdown.sh ] && ln -s /etc/wpa_supplicant/ifupdown.sh /etc/ifplugd/action.d/ifupdown

0 commit comments

Comments
 (0)