fix(setup-network): move netplan file selection before Proceed prompt so it isn't missed on SSH drop

This commit is contained in:
Justin Oros
2026-04-23 11:57:04 -07:00
parent a01f4aa11c
commit 436906582c

View File

@@ -123,6 +123,32 @@ case "$NET_OPT" in
WPA_CONF=$(wpa_passphrase "$NEW_SSID" "$NEW_PASS") \ WPA_CONF=$(wpa_passphrase "$NEW_SSID" "$NEW_PASS") \
|| die "Failed to generate WPA config — check SSID and password." || 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 "Currently connected to: ${CURRENT_SSID:-none}"
info "Switching to: ${NEW_SSID}" info "Switching to: ${NEW_SSID}"
warn "Your SSH session will drop. Reconnect once the device joins '${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." warn "No IP assigned yet — DHCP may still be in progress."
fi 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 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)" BACKUP_FILE="$NETPLAN_BACKUP_DIR/$(basename "${NETPLAN_FILE}").$(date +%Y%m%d%H%M%S)"
cp "$NETPLAN_FILE" "$BACKUP_FILE" cp "$NETPLAN_FILE" "$BACKUP_FILE"