Fix prompt() silently truncating multi-line pasted input

`prompt()` used a single `read -r`, which stops at the first newline.
If a pasted value (most notably join-data copied from the panel UI)
arrives with an embedded newline, everything after it was silently
dropped, and the leftover fragment would be consumed by the *next*
prompt instead. The truncated-but-still-valid-looking base64 could
still decode successfully, just missing trailing fields like `remote`,
producing a config.yml that fails at startup with "invalid remote
configuration, cannot connect to panel".

prompt() now drains any additional lines already buffered on the TTY
after the first read, so a multi-line paste is captured in full
without blocking on further keystrokes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Sebastian Cabrera 2026-09-09 20:59:01 -04:00
parent 37b8bbce96
commit 90f9c9d954
Signed by: okseby
GPG key ID: 2DDBFDEE356CF3DE

View file

@ -34,9 +34,19 @@ need_tty() {
prompt() { prompt() {
local msg="$1" local msg="$1"
local out local out line
printf "${BOLD}%s${RESET}" "$msg" >"$TTY" printf "${BOLD}%s${RESET}" "$msg" >"$TTY"
IFS= read -r out <"$TTY" IFS= read -r out <"$TTY"
# A pasted value (e.g. join-data copied from the panel UI) can arrive with an
# embedded newline. `read` stops at the first one, which would otherwise
# silently truncate the rest onto a "phantom" line consumed by a later
# prompt. Drain any additional lines that are already buffered so nothing
# gets lost; this never blocks waiting on new keystrokes.
while IFS= read -r -t 0.1 line <"$TTY" 2>/dev/null; do
out+="$line"
done
printf "%s" "$out" printf "%s" "$out"
} }