From 985c6b4ca788b6b3d31617a5017f3c29e589235d Mon Sep 17 00:00:00 2001 From: Zakary Timson Date: Sat, 12 Sep 2026 19:30:45 -0400 Subject: [PATCH] Update fallback-ap.sh --- fallback-ap.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/fallback-ap.sh b/fallback-ap.sh index 45021bd..f531b34 100644 --- a/fallback-ap.sh +++ b/fallback-ap.sh @@ -3,16 +3,41 @@ set -e # Configuration ======================================================================================================= +# +# Connection settings (SSID, passphrase, subnet, DHCP range, interface) can +# be supplied three ways, highest priority first: +# 1. Environment variables (FALLBACK_AP_*) - used for headless installs. +# 2. The persisted config file below, written by `install`. +# 3. The hard-coded defaults in this block. +# +# Everything else (timers, paths) is not meant to be reconfigured per-install +# and stays as plain constants. -WLAN0_IFACE="wlan0" +CONFIG_FILE="/etc/fallback-ap.conf" -AP_NAME="${HOSTNAME}" -AP_PASSWORD='guesswhatitis' -AP_ENCRYPTION="wpa-psk" # none | wpa-psk | sae +# Load persisted settings from a previous install, if any. These are stored +# under SAVED_* names (not FALLBACK_AP_*) specifically so that sourcing this +# file can never clobber an explicit environment-variable override below. +if [ -f "$CONFIG_FILE" ]; then + # shellcheck disable=SC1090 + source "$CONFIG_FILE" +fi -AP_CIDR="10.10.10.1/24" -DHCP_START="10.10.10.100" -DHCP_END="10.10.10.250" +WLAN0_IFACE="${FALLBACK_AP_IFACE:-${SAVED_IFACE:-wlan0}}" + +AP_NAME="${FALLBACK_AP_SSID:-${SAVED_SSID:-$HOSTNAME}}" +AP_PASSWORD="${FALLBACK_AP_PASSWORD:-${SAVED_PASSWORD:-guesswhatitis}}" +AP_ENCRYPTION="${FALLBACK_AP_ENCRYPTION:-${SAVED_ENCRYPTION:-wpa-psk}}" # none | wpa-psk | sae + +FALLBACK_AP_CIDR="${FALLBACK_AP_CIDR:-${SAVED_CIDR:-10.10.10.1/24}}" +FALLBACK_AP_DHCP_START_OCTET="${FALLBACK_AP_DHCP_START_OCTET:-${SAVED_DHCP_START_OCTET:-100}}" +FALLBACK_AP_DHCP_END_OCTET="${FALLBACK_AP_DHCP_END_OCTET:-${SAVED_DHCP_END_OCTET:-250}}" + +AP_CIDR="$FALLBACK_AP_CIDR" +AP_NETWORK_BASE="${AP_CIDR%%/*}" # e.g. "10.10.10.1" out of "10.10.10.1/24" +AP_NETWORK_BASE="${AP_NETWORK_BASE%.*}" # e.g. "10.10.10" +DHCP_START="${AP_NETWORK_BASE}.${FALLBACK_AP_DHCP_START_OCTET}" +DHCP_END="${AP_NETWORK_BASE}.${FALLBACK_AP_DHCP_END_OCTET}" # How often, while the AP has no clients, to stop the AP and give # NetworkManager a chance to reconnect to a known Wi-Fi network. @@ -276,6 +301,24 @@ attempt_recovery() { } +save_config() { + mkdir -p "$(dirname "$CONFIG_FILE")" + + cat > "$CONFIG_FILE" </dev/null 2>&1 || true rm -f "$SERVICE_FILE" + rm -f "$CONFIG_FILE" rm -rf "$STATE_DIR" systemctl daemon-reload @@ -460,6 +506,13 @@ status() { echo "=== Fallback AP ===" nmcli connection show "$CONNECTION_NAME" 2>/dev/null || echo "Not installed" + echo + echo "=== Config ($CONFIG_FILE) ===" + echo "SSID: $AP_NAME" + echo "Interface: $WLAN0_IFACE" + echo "Network: $AP_CIDR" + echo "DHCP: $DHCP_START - $DHCP_END" + echo echo "=== Last Known Wi-Fi ===" get_last_wifi || echo "None"