From 436906582c4d557ad17ac0e4e7c18d90423ab7e4 Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Thu, 23 Apr 2026 11:57:04 -0700 Subject: [PATCH] fix(setup-network): move netplan file selection before Proceed prompt so it isn't missed on SSH drop --- spoke/setup-network.sh | 50 ++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/spoke/setup-network.sh b/spoke/setup-network.sh index a583537..79e31f8 100755 --- a/spoke/setup-network.sh +++ b/spoke/setup-network.sh @@ -123,6 +123,32 @@ case "$NET_OPT" in WPA_CONF=$(wpa_passphrase "$NEW_SSID" "$NEW_PASS") \ || die "Failed to generate WPA config — check SSID and password." + NETPLAN_BACKUP_DIR="/root/.config/tinyboard/netplan-backups" + mkdir -p "$NETPLAN_BACKUP_DIR" + + mapfile -t NETPLAN_FILES < <(find /etc/netplan -maxdepth 1 -name '*.yaml' 2>/dev/null | sort) + + if [ ${#NETPLAN_FILES[@]} -eq 0 ]; then + warn "No netplan config files found — WiFi credentials will not persist across reboots." + NETPLAN_FILE="" + elif [ ${#NETPLAN_FILES[@]} -eq 1 ]; then + NETPLAN_FILE="${NETPLAN_FILES[0]}" + else + echo "" + warn "Multiple netplan config files found:" + for i in "${!NETPLAN_FILES[@]}"; do + echo -e " $((i+1))) ${NETPLAN_FILES[$i]}" + done + echo "" + read -rp "Which file should be updated with the new WiFi credentials? [1]: " NP_CHOICE + NP_CHOICE="${NP_CHOICE:-1}" + [[ "$NP_CHOICE" =~ ^[0-9]+$ ]] || die "Invalid selection." + NP_IDX=$((NP_CHOICE - 1)) + [ "$NP_IDX" -ge 0 ] && [ "$NP_IDX" -lt "${#NETPLAN_FILES[@]}" ] || die "Selection out of range." + NETPLAN_FILE="${NETPLAN_FILES[$NP_IDX]}" + fi + + echo "" info "Currently connected to: ${CURRENT_SSID:-none}" info "Switching to: ${NEW_SSID}" warn "Your SSH session will drop. Reconnect once the device joins '${NEW_SSID}'." @@ -195,30 +221,6 @@ case "$NET_OPT" in warn "No IP assigned yet — DHCP may still be in progress." fi - NETPLAN_BACKUP_DIR="/root/.config/tinyboard/netplan-backups" - mkdir -p "$NETPLAN_BACKUP_DIR" - - mapfile -t NETPLAN_FILES < <(find /etc/netplan -maxdepth 1 -name '*.yaml' 2>/dev/null | sort) - - if [ ${#NETPLAN_FILES[@]} -eq 0 ]; then - warn "No netplan config files found — skipping persistent config update." - NETPLAN_FILE="" - elif [ ${#NETPLAN_FILES[@]} -eq 1 ]; then - NETPLAN_FILE="${NETPLAN_FILES[0]}" - else - warn "Multiple netplan config files found:" - for i in "${!NETPLAN_FILES[@]}"; do - echo -e " $((i+1))) ${NETPLAN_FILES[$i]}" - done - echo "" - read -rp "Which file should be updated with the new WiFi credentials? [1]: " NP_CHOICE - NP_CHOICE="${NP_CHOICE:-1}" - [[ "$NP_CHOICE" =~ ^[0-9]+$ ]] || die "Invalid selection." - NP_IDX=$((NP_CHOICE - 1)) - [ "$NP_IDX" -ge 0 ] && [ "$NP_IDX" -lt "${#NETPLAN_FILES[@]}" ] || die "Selection out of range." - NETPLAN_FILE="${NETPLAN_FILES[$NP_IDX]}" - fi - if [ -n "$NETPLAN_FILE" ] && grep -q "access-points" "$NETPLAN_FILE" 2>/dev/null; then BACKUP_FILE="$NETPLAN_BACKUP_DIR/$(basename "${NETPLAN_FILE}").$(date +%Y%m%d%H%M%S)" cp "$NETPLAN_FILE" "$BACKUP_FILE"