This commit is contained in:
2026-08-24 16:40:48 +03:00
parent f7e99516bf
commit 32abb8bf0a
73 changed files with 12364 additions and 9292 deletions
@@ -8,6 +8,10 @@
#
# Intended to be invoked through sudo by the (unprivileged) web configurator.
# Do NOT use ip/ifconfig directly — NetworkManager will undo manual changes.
#
# Environment (optional):
# BUTTONTASK_NET_BOOT=1 boot path: succeed even if activation times out
# BUTTONTASK_NET_ACTIVATE_TIMEOUT=N seconds to wait for nmcli connection up (default 30)
set -euo pipefail
err() { echo "bt-netconfig: $*" >&2; exit 1; }
@@ -17,6 +21,8 @@ err() { echo "bt-netconfig: $*" >&2; exit 1; }
IFACE="$1"
MODE="$2"
PROFILE="buttontask-$IFACE"
BOOT="${BUTTONTASK_NET_BOOT:-0}"
ACTIVATE_TIMEOUT="${BUTTONTASK_NET_ACTIVATE_TIMEOUT:-30}"
[[ "$IFACE" =~ ^[A-Za-z0-9_.:-]{1,32}$ ]] || err "invalid interface name"
command -v nmcli >/dev/null 2>&1 || err "nmcli not found"
@@ -99,8 +105,25 @@ esac
nmcli device disconnect "$IFACE" 2>/dev/null || true
nmcli connection down "$CON" 2>/dev/null || true
if ! nmcli connection up "$CON" ifname "$IFACE" 2>/dev/null; then
nmcli connection up "$CON" >/dev/null
activate_connection() {
local con="$1" iface="$2"
if command -v timeout >/dev/null 2>&1; then
timeout "$ACTIVATE_TIMEOUT" nmcli connection up "$con" ifname "$iface" 2>/dev/null \
&& return 0
timeout "$ACTIVATE_TIMEOUT" nmcli connection up "$con" >/dev/null 2>&1 \
&& return 0
return 1
fi
nmcli connection up "$con" ifname "$iface" 2>/dev/null \
|| nmcli connection up "$con" >/dev/null
}
if ! activate_connection "$CON" "$IFACE"; then
if [ "$BOOT" = "1" ]; then
echo "bt-netconfig: activation timed out (boot); profile saved, NM will retry" >&2
exit 0
fi
err "connection activation failed or timed out after ${ACTIVATE_TIMEOUT}s"
fi
# Brief settle, then report what NM actually applied.