Skip to content

Commit

Permalink
Add support for network manager and wpa-supplicant in network module #…
Browse files Browse the repository at this point in the history
  • Loading branch information
guysoft committed Aug 9, 2024
1 parent 615598b commit d9830ce
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
8 changes: 7 additions & 1 deletion src/modules/network/config
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
# on reboots
# udev - creates a udev rules that should affect all wifi devices.

[ -n "$NETWORK_PWRSAVE_TYPE" ] || NETWORK_PWRSAVE_TYPE=udev
[ -n "$NETWORK_PWRSAVE_TYPE" ] || NETWORK_PWRSAVE_TYPE=udev

# Enable WPA-Supplicant boot folder support (pre rpios bookworm)
[ -n "$NETWORK_WPA_SUPPLICANT" ] || NETWORK_WPA_SUPPLICANT=no

# Enable Network Manager boot folder support (bookworm)
[ -n "$NETWORK_NETWORK_MANAGER" ] || NETWORK_NETWORK_MANAGER=yes
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# [connection]
# id=wifi
# uuid=95b17351-297c-4d9c-90f9-69d3deadbeef
# type=wifi

# [wifi]
# mode=infrastructure
# ssid=put password here

# [wifi-security]
# key-mgmt=wpa-psk
# psk=put password here
# [ipv4]
# method=auto
# [ipv6]
# addr-gen-mode=default
# method=auto
# [proxy]
35 changes: 23 additions & 12 deletions src/modules/network/start_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,40 @@ export LC_ALL=C
source /common.sh
install_cleanup_trap

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

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

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

if [ "${BASE_DISTRO}" == "ubuntu" ] || [ "${BASE_DISTRO}" == "armbian" ]; then
echo "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev" > /etc/wpa_supplicant/wpa_supplicant.conf
echo "update_config=1" >> /etc/wpa_supplicant/wpa_supplicant.conf
cat /etc/wpa_supplicant/wpa_supplicant.conf >> ${DIST_NETWORK_FILE} # append distributed conf to our own
rm -f /etc/wpa_supplicant/wpa_supplicant.conf # remove distributed conf

# create symlink
ln -s "${DIST_NETWORK_FILE}" /etc/wpa_supplicant/wpa_supplicant.conf
fi

cat /etc/wpa_supplicant/wpa_supplicant.conf >> ${DIST_NETWORK_FILE} # append distributed conf to our own
rm -f /etc/wpa_supplicant/wpa_supplicant.conf # remove distributed conf
if [ "${NETWORK_NETWORK_MANAGER}" == "yes" ]; then
DIST_NETWORK_FILE=/"${BASE_BOOT_MOUNT_PATH}"/${DIST_NAME,,}-wifi.nmconnection
unpack /filesystem/network-manager/boot /"${BASE_BOOT_MOUNT_PATH}"

mv /"${BASE_BOOT_MOUNT_PATH}"/wifi.nmconnection ${DIST_NETWORK_FILE}

ln -s "${DIST_NETWORK_FILE}" /etc/NetworkManager/system-connections/wifi.nmconnection
chmod 600 /etc/NetworkManager/system-connections/wifi.nmconnection
fi

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

# create symlink
ln -s "${DIST_NETWORK_FILE}" /etc/wpa_supplicant/wpa_supplicant.conf

# copy /etc/wpa_supplicant/ifupdown.sh to /etc/ifplugd/action.d/ifupdown - for wlan auto reconnect
[ -f /etc/ifplugd/action.d/ifupdown ] && mv /etc/ifplugd/action.d/ifupdown /etc/ifplugd/action.d/ifupdown.original
[ -f /etc/wpa_supplicant/ifupdown.sh ] && ln -s /etc/wpa_supplicant/ifupdown.sh /etc/ifplugd/action.d/ifupdown
Expand Down

0 comments on commit d9830ce

Please sign in to comment.