Working config: RTL8723DC disabled, stable system, AP mode operational, WiFi quiet-state by default

This commit is contained in:
Andrei Smaliak 2026-03-22 19:18:53 +04:00
parent 172f9787eb
commit 69aa5931ae
2 changed files with 67 additions and 64 deletions

View File

@ -397,6 +397,7 @@ ensure_user() {
if ! id "$u" >/dev/null 2>&1; then
useradd $home_flag -s "$shell" "$u"
log "Created user: $u"
ENSURE_USER_CREATED=1
return 0
else
log "User exists: $u"
@ -405,12 +406,14 @@ ensure_user() {
usermod -s "$shell" "$u"
log "Corrected shell for user ${u}: ${current_shell:-<unknown>} -> ${shell}"
fi
return 1
ENSURE_USER_CREATED=0
return 0
fi
}
IOM_USER_CREATED=0
if ensure_user "$IOM_USER" "/bin/bash" "-m"; then
ENSURE_USER_CREATED=0
if ensure_user "$IOM_USER" "/bin/bash" "-m" && [ "$ENSURE_USER_CREATED" -eq 1 ]; then
IOM_USER_CREATED=1
echo "$IOM_USER:$IOM_PASS" | chpasswd
log "Initialized default password for newly created user: $IOM_USER"
@ -730,60 +733,57 @@ log "Wi-Fi hardening applied (Region=${REG_NOW:-unknown}, P2P ignored, NM-only m
log "Wi-Fi persistence fix applied (SYSTEM profiles enforced + autoconnect-priority=100)"
# -------------------------
# Step 10.7: Wi-Fi bring-up (connect by UUID, late trigger, print status) - Debian 11 safe
# Step 10.7: Wi-Fi quiet-state (disable radio + block rfkill + keep wlan0/p2p0 down)
# -------------------------
step "Wi-Fi bring-up (connect by UUID, late trigger, print status) (Debian 11-safe)"
step "Wi-Fi quiet-state: radio off + rfkill block + wlan0/p2p0 down"
WIFI_IFACE="wlan0"
write_if_changed /usr/local/sbin/iomatex-wifi-quiet 0755 <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
sleep 6
WIFI_IFACE="${1:-wlan0}"
P2P_IFACE="${2:-p2p0}"
log "--- WIFI STATUS BEFORE ---"
if command -v nmcli >/dev/null 2>&1; then
nmcli device disconnect "$WIFI_IFACE" >/dev/null 2>&1 || true
nmcli radio wifi off >/dev/null 2>&1 || true
fi
rfkill block wifi >/dev/null 2>&1 || true
ip link set "$WIFI_IFACE" down >/dev/null 2>&1 || true
ip link set "$P2P_IFACE" down >/dev/null 2>&1 || true
EOF
WIFI_QUIET_UNIT_CHANGED=0
write_if_changed /etc/systemd/system/iomatex-wifi-quiet.service 0644 <<'EOF'
[Unit]
Description=IOMATEX Wi-Fi quiet-state enforcement
After=NetworkManager.service
Wants=NetworkManager.service
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/iomatex-wifi-quiet
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
if [ "$WRITE_CHANGED" -eq 1 ]; then
WIFI_QUIET_UNIT_CHANGED=1
fi
if [ "$WIFI_QUIET_UNIT_CHANGED" -eq 1 ]; then
soft_run "systemd daemon-reload (wifi quiet unit changed)" 20 /bin/systemctl daemon-reload
fi
soft_run "Enable iomatex-wifi-quiet.service" 20 /bin/systemctl enable iomatex-wifi-quiet.service
soft_run "Apply Wi-Fi quiet-state now" 20 /usr/local/sbin/iomatex-wifi-quiet
log "--- WIFI QUIET-STATE AFTER ---"
nmcli -f DEVICE,TYPE,STATE,CONNECTION dev >>"$LOG" 2>&1 || true
nmcli -f GENERAL.STATE,GENERAL.REASON,GENERAL.CONNECTION dev show "$WIFI_IFACE" >>"$LOG" 2>&1 || true
STATE_NOW="$(nmcli -g GENERAL.STATE dev show "$WIFI_IFACE" 2>/dev/null || true)"
log "wifi_state_before=${STATE_NOW:-<none>}"
if echo "${STATE_NOW:-}" | grep -q "100"; then
log "Wi-Fi already connected -> skip bring-up"
else
WIFI_UUID=""
# Pick Wi-Fi UUID deterministically by max AUTOCONNECT-PRIORITY (among autoconnect=yes)
WIFI_UUID="$(nmcli -t -f UUID,TYPE,AUTOCONNECT,AUTOCONNECT-PRIORITY con show \
| awk -F: '($2=="wifi" || $2=="802-11-wireless") && $3=="yes" {
p=$4; if(p=="") p=0;
if(best=="" || p>bestp){best=$1; bestp=p}
}
END{print best}')"
# Fallback: any Wi-Fi profile
if [ -z "${WIFI_UUID:-}" ]; then
WIFI_UUID="$(nmcli -t -f UUID,TYPE con show \
| awk -F: '($2=="wifi" || $2=="802-11-wireless") {print $1; exit}')"
fi
WIFI_NAME="$(nmcli -g NAME con show uuid "$WIFI_UUID" 2>/dev/null || true)"
log "wifi_uuid_selected=${WIFI_UUID:-<none>}"
log "wifi_name_selected=${WIFI_NAME:-<none>}"
if [ -n "${WIFI_UUID:-}" ] && [ -e "/sys/class/net/$WIFI_IFACE" ]; then
soft_run "Wi-Fi connect by UUID (best-effort)" 60 /bin/bash -lc "
nmcli networking on || true
nmcli radio wifi on || true
nmcli dev set '$WIFI_IFACE' managed yes || true
nmcli con up uuid '$WIFI_UUID' ifname '$WIFI_IFACE' || true
"
sleep 3
else
log "WIFI_CONNECT_SKIP=YES (no uuid or iface missing)"
fi
fi
log "--- WIFI STATUS AFTER ---"
nmcli -f DEVICE,TYPE,STATE,CONNECTION dev >>"$LOG" 2>&1 || true
nmcli -f GENERAL.STATE,GENERAL.REASON,GENERAL.CONNECTION dev show "$WIFI_IFACE" >>"$LOG" 2>&1 || true
nmcli radio all >>"$LOG" 2>&1 || true
rfkill list >>"$LOG" 2>&1 || true
# -------------------------
# Step 11: /userdata usage (SAFE cold-boot)
# - NO bind-mount /var/log

View File

@ -6,9 +6,9 @@ set -euo pipefail
# Debian 11 / NetworkManager
# Single Wi-Fi card: wlan0
#
# Working policy intentionally preserved:
# - Uplink OK via eth0 carrier OR wlan0 STA (NM connected + IPv4) => AP OFF
# - Else => AP ON (wlan0 AP), captive HTTP(80) -> console when healthy, legacy Wi-Fi UI as fallback
# Working policy:
# - eth0 carrier present => AP OFF and Wi-Fi kept quiet
# - eth0 carrier absent => Wi-Fi is raised and wlan0 runs AP mode
# - UI "Connect" => AP down -> try STA connect -> if fail -> AP back
#
# Defaults:
@ -768,10 +768,11 @@ set -euo pipefail
/usr/local/sbin/iomatex-ap-sync-config >/dev/null 2>&1 || true
. /etc/iomatex/ap.env
rfkill unblock all >/dev/null 2>&1 || true
rfkill unblock wifi >/dev/null 2>&1 || true
if command -v nmcli >/dev/null 2>&1; then
nmcli dev disconnect "$IFACE" >/dev/null 2>&1 || true
nmcli radio wifi on >/dev/null 2>&1 || true
nmcli dev set "$IFACE" managed no >/dev/null 2>&1 || true
fi
@ -801,7 +802,11 @@ ip addr flush dev "$IFACE" 2>/dev/null || true
if command -v nmcli >/dev/null 2>&1; then
nmcli dev set "$IFACE" managed yes >/dev/null 2>&1 || true
nmcli radio wifi off >/dev/null 2>&1 || true
fi
ip link set "$IFACE" down >/dev/null 2>&1 || true
rfkill block wifi >/dev/null 2>&1 || true
EOF
write_managed_file /usr/local/sbin/iomatex-wifi-status 0755 <<'EOF'
@ -942,6 +947,11 @@ wait_for_nm_device_ready() {
/usr/local/sbin/iomatex-ap-down >/dev/null 2>&1 || true
rfkill unblock wifi >/dev/null 2>&1 || true
if command -v nmcli >/dev/null 2>&1; then
nmcli radio wifi on >/dev/null 2>&1 || true
fi
nmcli dev set "$IFACE" managed yes >/dev/null 2>&1 || true
ip addr flush dev "$IFACE" >/dev/null 2>&1 || true
ip link set "$IFACE" up >/dev/null 2>&1 || true
@ -1007,24 +1017,17 @@ eth_ok() {
return 0
}
sta_ok() {
command -v nmcli >/dev/null 2>&1 || return 1
nmcli -t -f DEVICE,STATE dev | grep -q "^${IFACE}:connected$" || return 1
ip -4 -o addr show dev "$IFACE" 2>/dev/null | grep -q "inet " || return 1
return 0
}
ap_is_up() { systemctl is-active --quiet iomatex-hostapd.service; }
if eth_ok || sta_ok; then
if eth_ok; then
ap_is_up && /usr/local/sbin/iomatex-ap-down || true
echo "uplink_ok" > "$STATE"
echo "eth_uplink_ok" > "$STATE"
exit 0
fi
ap_is_up || /usr/local/sbin/iomatex-ap-up
/usr/local/sbin/iomatex-ap-refresh-landing >/dev/null 2>&1 || true
echo "ap_on_no_uplink" > "$STATE"
echo "ap_on_no_eth" > "$STATE"
EOF
if [[ "$LAST_WRITE_CHANGED" -eq 1 ]]; then
WATCH_SERVICE_CHANGED=1
@ -1290,7 +1293,7 @@ echo "PRIMARY UI : http://${AP_IP}/ (console when healthy)"
echo "FALLBACK UI: http://${AP_IP}:${UI_PORT}/ (legacy Wi-Fi rescue UI)"
echo
echo "TEST:"
echo " - No uplink (unplug eth / no STA): connect to WiFi SSID=${SSID}"
echo " - No eth0 link: connect to WiFi SSID=${SSID}"
echo " - Open: http://10.10.10.1 (NOT https)"
echo " - If console is down, landing should fall back to: http://${AP_IP}:${UI_PORT}/"
echo