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,11 +138,30 @@ fi
# 3. NETWORKING
echo "Configuring Networking..."
# Ensure radio is unblocked
rfkill unblock wlan || true
# hostapd
cat <<EOF > /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 <<EOF > /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 <<EOF > /etc/dnsmasq.conf
# dnsmasq
[ -f /etc/dnsmasq.conf ] && mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak || true
cat <<EOF > /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
# 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