fix(setup-network): prompt user to choose netplan file when multiple configs exist

This commit is contained in:
Justin Oros
2026-04-23 11:54:03 -07:00
parent d61f7e4512
commit a01f4aa11c

View File

@@ -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
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