fix(setup-network): update all netplan files containing access-points, not just the first one

This commit is contained in:
Justin Oros
2026-04-23 11:49:01 -07:00
parent 337d238d7f
commit d61f7e4512

View File

@@ -195,14 +195,16 @@ 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_FILE=$(ls /etc/netplan/*.yaml 2>/dev/null | head -1)
if [ -n "$NETPLAN_FILE" ] && grep -q "access-points" "$NETPLAN_FILE" 2>/dev/null; then
warn "Updating netplan config with new WiFi credentials..."
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
if ! grep -q "access-points" "$NETPLAN_FILE" 2>/dev/null; then
continue
fi
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 "Netplan config backed up to $BACKUP_FILE" info "Backed up: $NETPLAN_FILE $BACKUP_FILE"
python3 - "$NETPLAN_FILE" "$NEW_SSID" "$NEW_PASS" <<'PYEOF' python3 - "$NETPLAN_FILE" "$NEW_SSID" "$NEW_PASS" <<'PYEOF'
import sys, re import sys, re
@@ -216,8 +218,10 @@ txt = re.sub(
) )
open(path, "w").write(txt) open(path, "w").write(txt)
PYEOF PYEOF
info "Netplan config updated. Changes will persist on next boot." info "Updated: $NETPLAN_FILE"
fi done < <(find /etc/netplan -maxdepth 1 -name '*.yaml' -print0 2>/dev/null)
info "All netplan configs updated. Changes will persist on next boot."
info "Connected to '${NEW_SSID}' successfully." info "Connected to '${NEW_SSID}' successfully."
exit 0 exit 0