This commit is contained in:
Joakim
2026-11-01 17:22:20 +01:00
parent 2c7653bc4c
commit 9e12762be4

View File

@@ -150,33 +150,73 @@ log "Konfigurerar Wi-Fi"
systemctl enable --now NetworkManager.service
# Remove an old profile with the same name, then create a clean one.
nmcli connection delete "$WIFI_CONNECTION" >/dev/null 2>&1 || true
# Configure Wi-Fi without requiring the hotspot to be visible right now.
# The phone may be switched off during installation; NetworkManager will
# reconnect automatically when the SSID becomes available later.
nmcli radio wifi on
nmcli device wifi connect "$WIFI_SSID" \
password "$WIFI_PASSWORD" \
name "$WIFI_CONNECTION"
WIFI_IF="$(nmcli -t -f DEVICE,TYPE device status | awk -F: '$2 == "wifi" {print $1; exit}')"
[[ -n "$WIFI_IF" ]] || die "Hittade inget Wi-Fi-interface."
# Remove an old profile with the same name, then create a persistent profile.
nmcli connection delete "$WIFI_CONNECTION" >/dev/null 2>&1 || true
nmcli connection add type wifi \
ifname "$WIFI_IF" \
con-name "$WIFI_CONNECTION" \
ssid "$WIFI_SSID" \
wifi-sec.key-mgmt wpa-psk \
wifi-sec.psk "$WIFI_PASSWORD" \
ipv4.method auto \
ipv4.never-default yes \
ipv4.route-metric 600 \
ipv6.method disabled
nmcli connection modify "$WIFI_CONNECTION" \
connection.autoconnect yes \
connection.autoconnect-retries 0 \
connection.autoconnect-priority 100 \
connection.mdns 0 \
ipv4.never-default yes \
ipv4.route-metric 600 \
ipv6.method disabled \
ipv6.never-default yes
# Give the hotspot connection high priority if several Wi-Fi networks are known.
nmcli connection modify "$WIFI_CONNECTION" connection.autoconnect-priority 100
# Try immediately, but do not abort the installation if the A50 hotspot is
# currently off or temporarily not visible.
if nmcli connection up "$WIFI_CONNECTION"; then
log "Wi-Fi anslutet till $WIFI_SSID"
else
warn "Wi-Fi-hotspotten '$WIFI_SSID' är inte tillgänglig just nu. Profilen är skapad och kommer att återansluta automatiskt när hotspotten startas."
fi
nmcli connection up "$WIFI_CONNECTION" || true
# Wired Ethernet is the maintenance/Internet path. Ensure every currently
# known Ethernet profile prefers a normal DHCP default route with a low metric.
while IFS=: read -r CON_NAME CON_TYPE; do
[[ "$CON_TYPE" == "802-3-ethernet" ]] || continue
nmcli connection modify "$CON_NAME" \
ipv4.never-default no \
ipv4.route-metric 100 \
ipv6.never-default no \
connection.autoconnect yes || true
done < <(nmcli -t -f NAME,TYPE connection show)
# Wired Ethernet is the maintenance/Internet path. Do not create a special
# Ethernet profile: NetworkManager's normal DHCP profile should be allowed to
# obtain a default route whenever a cable is connected. The Wi-Fi profile has
# never-default enabled above, so Ethernet wins the default route naturally.
# Existing Ethernet profiles are left untouched.
# Create a DHCP Ethernet profile for each physical Ethernet interface that
# currently has no suitable profile. This makes plugging in a cable later
# reliably provide the maintenance/Internet path.
while read -r ETH_IF; do
[[ -n "$ETH_IF" ]] || continue
PROFILE="Fikakassa-Ethernet-$ETH_IF"
if ! nmcli -t -f NAME connection show | grep -Fxq "$PROFILE"; then
nmcli connection add type ethernet \
ifname "$ETH_IF" \
con-name "$PROFILE" \
ipv4.method auto \
ipv4.never-default no \
ipv4.route-metric 100 \
ipv6.method auto \
ipv6.never-default no \
connection.autoconnect yes >/dev/null
fi
done < <(nmcli -t -f DEVICE,TYPE device status | awk -F: '$2 == "ethernet" {print $1}')
log "Konfigurerar lokal brandvägg"
@@ -295,6 +335,14 @@ EOF
chown "$KIOSK_USER:$KIOSK_USER" "$KIOSK_HOME/.xinitrc"
chmod 755 "$KIOSK_HOME/.xinitrc"
# A small explicit launcher makes the kiosk session independent of shell
# startup quirks.
cat > /usr/local/bin/fikakassa-startx <<EOF
#!/bin/sh
exec /usr/bin/startx
EOF
chmod 755 /usr/local/bin/fikakassa-startx
cat > "$KIOSK_HOME/.config/openbox/autostart" <<EOF
#!/bin/sh
@@ -342,9 +390,9 @@ EOF
# Start X only on tty1 for the kiosk account.
cat > "$KIOSK_HOME/.bash_profile" <<'EOF'
# Start graphical kiosk session automatically.
# Start graphical kiosk session automatically on tty1.
if [ -z "$DISPLAY" ] && [ "$(tty 2>/dev/null)" = "/dev/tty1" ]; then
exec startx
exec /usr/local/bin/fikakassa-startx
fi
EOF
chown "$KIOSK_USER:$KIOSK_USER" "$KIOSK_HOME/.bash_profile"
@@ -352,8 +400,16 @@ chmod 644 "$KIOSK_HOME/.bash_profile"
systemctl daemon-reload
systemctl enable getty@tty1.service
systemctl restart getty@tty1.service || true
# Validate the files before restarting tty1. This is intentionally fatal: a
# kiosk without its graphical startup should not silently fall back to tty.
test -x "$KIOSK_HOME/.xinitrc"
test -x "$KIOSK_HOME/.config/openbox/autostart"
test -f "$KIOSK_HOME/.bash_profile"
test -x /usr/local/bin/fikakassa-startx
# Restarting getty will log the current terminal user out. This is expected
# when the script is run interactively on tty1.
log "Sätter systemtid/NTP"
# systemd-timesyncd is enough; no Internet browsing is required.
@@ -363,8 +419,7 @@ systemctl enable --now systemd-timesyncd.service || true
log "Aktiverar automatisk omstart av Chromium om X-sessionen kraschar"
# Xorg/startx returns to tty1 if Chromium/Openbox dies. systemd getty will
# respawn the session. This keeps the kiosk self-healing after crashes.
systemctl restart getty@tty1.service || true
# respawn the login shell, which starts X again through .bash_profile.
cat <<EOF