fix(core): stop prompts looping forever when no input is available (#5042)
* fix(core): stop prompts looping forever when no input is available
fn_prompt_yn read the answer in an endless loop. When stdin is not a
terminal (cron, piped input, a container started without -it), read hits
EOF, the answer stays empty and "Please answer yes or no." is printed
forever at full CPU. Running ./vhserver install with stdin from /dev/null
wrote over 3 million lines (83 MB) in 60 seconds at the server directory
prompt.
Without a terminal bash also ignores read -e, -i and -p, so the prefilled
default is never applied and taking the default is not an option. Several
prompts default to Y on actions that must not happen unattended (accept
EULA, enable stats, delete all modules, overwrite the fastdl directory,
remove a mod), and treating no input as "no" would exit 0 on an aborted
install.
Prompts now check the read return code. If read fails with no answer,
the command prints an error and exits with code 2. Scripted answers such
as "yes |" or "printf 'y\n' |" keep working, including an answer with no
trailing newline. The same check is added to:
- fn_prompt_message, which returns 1, and command_send, which exits with
an error because core_exit.sh inside $() only ends the subshell.
- the mods-install and mods-remove selection loops, which looped forever
on "is not a valid addon/mod" in the same way.
* fix(core): document shared prompt exit codes for ShellCheck