forked from finn/tinyboard
fix(setup-network): prompt user to choose netplan file when multiple configs exist
This commit is contained in:
@@ -198,10 +198,28 @@ case "$NET_OPT" in
|
|||||||
NETPLAN_BACKUP_DIR="/root/.config/tinyboard/netplan-backups"
|
NETPLAN_BACKUP_DIR="/root/.config/tinyboard/netplan-backups"
|
||||||
mkdir -p "$NETPLAN_BACKUP_DIR"
|
mkdir -p "$NETPLAN_BACKUP_DIR"
|
||||||
|
|
||||||
while IFS= read -r -d '' NETPLAN_FILE; do
|
mapfile -t NETPLAN_FILES < <(find /etc/netplan -maxdepth 1 -name '*.yaml' 2>/dev/null | sort)
|
||||||
if ! grep -q "access-points" "$NETPLAN_FILE" 2>/dev/null; then
|
|
||||||
continue
|
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
|
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)"
|
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"
|
||||||
info "Backed up: $NETPLAN_FILE → $BACKUP_FILE"
|
info "Backed up: $NETPLAN_FILE → $BACKUP_FILE"
|
||||||
@@ -219,9 +237,10 @@ txt = re.sub(
|
|||||||
open(path, "w").write(txt)
|
open(path, "w").write(txt)
|
||||||
PYEOF
|
PYEOF
|
||||||
info "Updated: $NETPLAN_FILE"
|
info "Updated: $NETPLAN_FILE"
|
||||||
done < <(find /etc/netplan -maxdepth 1 -name '*.yaml' -print0 2>/dev/null)
|
info "Changes will persist on next boot."
|
||||||
|
elif [ -n "$NETPLAN_FILE" ]; then
|
||||||
info "All netplan configs updated. Changes will persist on next boot."
|
warn "$NETPLAN_FILE has no access-points section — skipping."
|
||||||
|
fi
|
||||||
|
|
||||||
info "Connected to '${NEW_SSID}' successfully."
|
info "Connected to '${NEW_SSID}' successfully."
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Reference in New Issue
Block a user