fix: implement NetworkManager (nmcli) hotspot support for modern Debian/Trixie systems

This commit is contained in:
Timothy Hofland
2026-03-15 23:49:10 +01:00
parent 1aa5717891
commit 237ff76670

View File

@ -138,9 +138,28 @@ fi
# 3. NETWORKING # 3. NETWORKING
echo "Configuring Networking..." echo "Configuring Networking..."
# Ensure radio is unblocked
rfkill unblock wlan || true rfkill unblock wlan || true
if command -v nmcli > /dev/null; then
echo "NetworkManager detected. Using nmcli for hotspot..."
# Clean up any existing MPVJ connection
nmcli con delete MPVJ-AP 2>/dev/null || true
# Create the Access Point
nmcli con add type wifi ifname wlan0 mode ap con-name MPVJ-AP autoconnect yes ssid "$WIFI_SSID"
nmcli con modify MPVJ-AP 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
nmcli con modify MPVJ-AP wifi-sec.key-mgmt wpa-psk
nmcli con modify MPVJ-AP wifi-sec.psk "$WIFI_PASS"
nmcli con modify MPVJ-AP ipv4.addresses 192.168.4.1/24
# Ensure hostapd/dnsmasq are disabled to prevent conflict
systemctl stop hostapd dnsmasq 2>/dev/null || true
systemctl disable hostapd dnsmasq 2>/dev/null || true
systemctl mask hostapd dnsmasq 2>/dev/null || true
echo "NetworkManager Hotspot 'MPVJ-AP' configured."
else
echo "Using legacy hostapd/dnsmasq logic..."
# hostapd # hostapd
cat <<EOF > /etc/hostapd/hostapd.conf cat <<EOF > /etc/hostapd/hostapd.conf
interface=wlan0 interface=wlan0
@ -162,23 +181,17 @@ dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
address=/$HOSTNAME.local/192.168.4.1 address=/$HOSTNAME.local/192.168.4.1
EOF EOF
# dhcpcd / network manager # dhcpcd
if [ -f /etc/dhcpcd.conf ]; then if [ -f /etc/dhcpcd.conf ]; then
if ! grep -q "interface wlan0" /etc/dhcpcd.conf; then if ! grep -q "interface wlan0" /etc/dhcpcd.conf; then
echo -e "\ninterface wlan0\n static ip_address=192.168.4.1/24\n nohook wpa_supplicant" >> /etc/dhcpcd.conf echo -e "\ninterface wlan0\n static ip_address=192.168.4.1/24\n nohook wpa_supplicant" >> /etc/dhcpcd.conf
fi fi
fi fi
# Disable standard wpa_supplicant so it doesn't fight with hostapd systemctl unmask hostapd dnsmasq 2>/dev/null || true
if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ] && [ ! -f /etc/wpa_supplicant/wpa_supplicant.conf.bak ]; then systemctl enable hostapd dnsmasq
mv /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.bak
fi fi
# Unmask and enable services
systemctl unmask hostapd 2>/dev/null || true
systemctl unmask dnsmasq 2>/dev/null || true
systemctl enable hostapd
systemctl enable dnsmasq
systemctl enable avahi-daemon systemctl enable avahi-daemon
# 4. DEPLOYMENT # 4. DEPLOYMENT