fix: implement NetworkManager (nmcli) hotspot support for modern Debian/Trixie systems
This commit is contained in:
@ -138,11 +138,30 @@ fi
|
|||||||
|
|
||||||
# 3. NETWORKING
|
# 3. NETWORKING
|
||||||
echo "Configuring Networking..."
|
echo "Configuring Networking..."
|
||||||
# Ensure radio is unblocked
|
|
||||||
rfkill unblock wlan || true
|
rfkill unblock wlan || true
|
||||||
|
|
||||||
# hostapd
|
if command -v nmcli > /dev/null; then
|
||||||
cat <<EOF > /etc/hostapd/hostapd.conf
|
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
|
interface=wlan0
|
||||||
driver=nl80211
|
driver=nl80211
|
||||||
ssid=$WIFI_SSID
|
ssid=$WIFI_SSID
|
||||||
@ -152,33 +171,27 @@ wpa=2
|
|||||||
wpa_passphrase=$WIFI_PASS
|
wpa_passphrase=$WIFI_PASS
|
||||||
wpa_key_mgmt=WPA-PSK
|
wpa_key_mgmt=WPA-PSK
|
||||||
EOF
|
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
|
# dnsmasq
|
||||||
[ -f /etc/dnsmasq.conf ] && mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak || true
|
[ -f /etc/dnsmasq.conf ] && mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak || true
|
||||||
cat <<EOF > /etc/dnsmasq.conf
|
cat <<EOF > /etc/dnsmasq.conf
|
||||||
interface=wlan0
|
interface=wlan0
|
||||||
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
|
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
|
||||||
|
|
||||||
|
systemctl unmask hostapd dnsmasq 2>/dev/null || true
|
||||||
|
systemctl enable hostapd dnsmasq
|
||||||
fi
|
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
|
systemctl enable avahi-daemon
|
||||||
|
|
||||||
# 4. DEPLOYMENT
|
# 4. DEPLOYMENT
|
||||||
|
|||||||
Reference in New Issue
Block a user