From a01f4aa11c5c8acfb8f8b6bca3ead5dda6c8f4e0 Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Thu, 23 Apr 2026 11:54:03 -0700 Subject: [PATCH] fix(setup-network): prompt user to choose netplan file when multiple configs exist --- spoke/setup-network.sh | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/spoke/setup-network.sh b/spoke/setup-network.sh index d2c692b..a583537 100755 --- a/spoke/setup-network.sh +++ b/spoke/setup-network.sh @@ -198,10 +198,28 @@ case "$NET_OPT" in NETPLAN_BACKUP_DIR="/root/.config/tinyboard/netplan-backups" mkdir -p "$NETPLAN_BACKUP_DIR" - while IFS= read -r -d '' NETPLAN_FILE; do - if ! grep -q "access-points" "$NETPLAN_FILE" 2>/dev/null; then - continue - fi + 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" info "Backed up: $NETPLAN_FILE → $BACKUP_FILE" @@ -219,9 +237,10 @@ txt = re.sub( open(path, "w").write(txt) PYEOF info "Updated: $NETPLAN_FILE" - done < <(find /etc/netplan -maxdepth 1 -name '*.yaml' -print0 2>/dev/null) - - info "All netplan configs updated. Changes will persist on next boot." + info "Changes will persist on next boot." + elif [ -n "$NETPLAN_FILE" ]; then + warn "$NETPLAN_FILE has no access-points section — skipping." + fi info "Connected to '${NEW_SSID}' successfully." exit 0