fix: improve error handling in NetworkManager hotspot configuration
This commit is contained in:
@ -102,12 +102,31 @@ EOF
|
||||
nmcli device set wlan0 autoconnect yes || true
|
||||
nmcli device disconnect wlan0 2>/dev/null || true
|
||||
|
||||
nmcli --wait 30 device wifi hotspot ifname wlan0 con-name "$AP_CONNECTION_NAME" ssid "$WIFI_SSID" band bg password "$WIFI_PASS"
|
||||
nmcli connection modify "$AP_CONNECTION_NAME" connection.interface-name wlan0
|
||||
nmcli connection modify "$AP_CONNECTION_NAME" connection.autoconnect yes connection.autoconnect-priority 100 connection.wait-device-timeout 30000
|
||||
nmcli connection modify "$AP_CONNECTION_NAME" 802-11-wireless.mode ap 802-11-wireless.band bg 802-11-wireless.channel 7 802-11-wireless.powersave 2 802-11-wireless.cloned-mac-address permanent
|
||||
nmcli connection modify "$AP_CONNECTION_NAME" ipv4.method shared ipv4.addresses "$AP_ADDRESS" ipv4.shared-dhcp-range "$AP_DHCP_RANGE_START,$AP_DHCP_RANGE_END" ipv6.method disabled
|
||||
nmcli connection modify "$AP_CONNECTION_NAME" 802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk "$WIFI_PASS" 802-11-wireless-security.proto rsn 802-11-wireless-security.pairwise ccmp 802-11-wireless-security.group ccmp 802-11-wireless-security.pmf 1
|
||||
if ! nmcli --wait 30 device wifi hotspot ifname wlan0 con-name "$AP_CONNECTION_NAME" ssid "$WIFI_SSID" band bg password "$WIFI_PASS"; then
|
||||
echo "NetworkManager hotspot creation failed."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! nmcli connection modify "$AP_CONNECTION_NAME" connection.interface-name wlan0; then
|
||||
echo "NetworkManager hotspot tuning failed (interface-name)."
|
||||
return 1
|
||||
fi
|
||||
if ! nmcli connection modify "$AP_CONNECTION_NAME" connection.autoconnect yes connection.autoconnect-priority 100 connection.wait-device-timeout 30000; then
|
||||
echo "NetworkManager hotspot tuning failed (autoconnect)."
|
||||
return 1
|
||||
fi
|
||||
if ! nmcli connection modify "$AP_CONNECTION_NAME" 802-11-wireless.mode ap 802-11-wireless.band bg 802-11-wireless.channel 7 802-11-wireless.powersave 2 802-11-wireless.cloned-mac-address permanent; then
|
||||
echo "NetworkManager hotspot tuning failed (wireless)."
|
||||
return 1
|
||||
fi
|
||||
if ! nmcli connection modify "$AP_CONNECTION_NAME" ipv4.method shared ipv4.addresses "$AP_ADDRESS" ipv4.shared-dhcp-range "$AP_DHCP_RANGE_START,$AP_DHCP_RANGE_END" ipv6.method disabled; then
|
||||
echo "NetworkManager hotspot tuning failed (IP settings)."
|
||||
return 1
|
||||
fi
|
||||
if ! nmcli connection modify "$AP_CONNECTION_NAME" 802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk "$WIFI_PASS" 802-11-wireless-security.proto rsn 802-11-wireless-security.pairwise ccmp 802-11-wireless-security.group ccmp 802-11-wireless-security.pmf 1; then
|
||||
echo "NetworkManager hotspot tuning failed (security)."
|
||||
return 1
|
||||
fi
|
||||
nmcli connection modify "$AP_CONNECTION_NAME" remove 802-1x || true
|
||||
nmcli connection down "$AP_CONNECTION_NAME" 2>/dev/null || true
|
||||
|
||||
@ -130,13 +149,13 @@ EOF
|
||||
systemctl daemon-reload
|
||||
systemctl enable mpvj-nm-ap.service avahi-daemon.service
|
||||
|
||||
if systemctl restart mpvj-nm-ap.service; then
|
||||
echo "NetworkManager hotspot configured successfully."
|
||||
else
|
||||
echo "NetworkManager hotspot activation failed. Falling back to hostapd/dnsmasq."
|
||||
cleanup_networkmanager_access_point_stack
|
||||
configure_legacy_access_point_stack
|
||||
if ! systemctl restart mpvj-nm-ap.service; then
|
||||
echo "NetworkManager hotspot activation failed."
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "NetworkManager hotspot configured successfully."
|
||||
return 0
|
||||
}
|
||||
|
||||
configure_legacy_access_point_stack() {
|
||||
@ -217,7 +236,11 @@ EOF
|
||||
configure_access_point_stack() {
|
||||
if command -v nmcli > /dev/null 2>&1 && systemctl list-unit-files NetworkManager.service --no-legend 2>/dev/null | grep -q '^NetworkManager\.service'; then
|
||||
echo "Using NetworkManager hotspot configuration for wlan0..."
|
||||
configure_networkmanager_access_point
|
||||
if ! configure_networkmanager_access_point; then
|
||||
echo "Falling back to hostapd/dnsmasq hotspot configuration for wlan0..."
|
||||
cleanup_networkmanager_access_point_stack
|
||||
configure_legacy_access_point_stack
|
||||
fi
|
||||
else
|
||||
echo "Using hostapd/dnsmasq hotspot configuration for wlan0..."
|
||||
configure_legacy_access_point_stack
|
||||
|
||||
Reference in New Issue
Block a user