From 237ff76670ffccbe545eb79f2c57047ead339617 Mon Sep 17 00:00:00 2001 From: Timothy Hofland Date: Sun, 15 Mar 2026 23:49:10 +0100 Subject: [PATCH] fix: implement NetworkManager (nmcli) hotspot support for modern Debian/Trixie systems --- scripts/setup.sh | 55 ++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index d170bc9..e9e66b1 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -138,11 +138,30 @@ fi # 3. NETWORKING echo "Configuring Networking..." -# Ensure radio is unblocked rfkill unblock wlan || true -# hostapd -cat < /etc/hostapd/hostapd.conf +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 + cat < /etc/hostapd/hostapd.conf interface=wlan0 driver=nl80211 ssid=$WIFI_SSID @@ -152,33 +171,27 @@ wpa=2 wpa_passphrase=$WIFI_PASS wpa_key_mgmt=WPA-PSK EOF -[ -f /etc/default/hostapd ] && sed -i 's/#DAEMON_CONF=""/DAEMON_CONF="\/etc\/hostapd\/hostapd.conf"/g' /etc/default/hostapd + [ -f /etc/default/hostapd ] && sed -i 's/#DAEMON_CONF=""/DAEMON_CONF="\/etc\/hostapd\/hostapd.conf"/g' /etc/default/hostapd -# dnsmasq -[ -f /etc/dnsmasq.conf ] && mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak || true -cat < /etc/dnsmasq.conf + # dnsmasq + [ -f /etc/dnsmasq.conf ] && mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak || true + cat < /etc/dnsmasq.conf interface=wlan0 dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h address=/$HOSTNAME.local/192.168.4.1 EOF -# dhcpcd / network manager -if [ -f /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 + # dhcpcd + if [ -f /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 + fi fi + + systemctl unmask hostapd dnsmasq 2>/dev/null || true + systemctl enable hostapd dnsmasq fi -# Disable standard wpa_supplicant so it doesn't fight with hostapd -if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ] && [ ! -f /etc/wpa_supplicant/wpa_supplicant.conf.bak ]; then - mv /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.bak -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 # 4. DEPLOYMENT