mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-05-13 12:15:03 +00:00
Read prompts from a fresh /dev/tty to avoid tty corruption
Replace pre-opened _RECOVERY_TTY handling with direct reads from /dev/tty in misc/build.func and misc/error_handler.func. The change opens /dev/tty at prompt time (with stty sane) so the prompt reads aren't affected by tty state corruption from lxc-attach|tee, simplifies the read logic by using a local response variable with a timeout, and removes the pre-open/close bookkeeping for _RECOVERY_TTY.
This commit is contained in:
+3
-13
@@ -4101,10 +4101,7 @@ EOF'
|
|||||||
# - $STD/silent() not used for some commands
|
# - $STD/silent() not used for some commands
|
||||||
# PIPESTATUS[0] gets the real exit code from lxc-attach (not from tee).
|
# PIPESTATUS[0] gets the real exit code from lxc-attach (not from tee).
|
||||||
# stdin comes from /dev/tty so install scripts can use interactive `read`.
|
# stdin comes from /dev/tty so install scripts can use interactive `read`.
|
||||||
# We pre-open a separate fd to /dev/tty BEFORE the pipeline so the recovery
|
|
||||||
# menu can still read even if lxc-attach|tee corrupts the tty state.
|
|
||||||
local _LXC_CAPTURE_LOG="/tmp/.install-capture-${SESSION_ID}.log"
|
local _LXC_CAPTURE_LOG="/tmp/.install-capture-${SESSION_ID}.log"
|
||||||
exec {_RECOVERY_TTY}</dev/tty 2>/dev/null || _RECOVERY_TTY=""
|
|
||||||
lxc-attach -n "$CTID" -- bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/install/${var_install}.sh)" </dev/tty 2>&1 | tee "$_LXC_CAPTURE_LOG"
|
lxc-attach -n "$CTID" -- bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/install/${var_install}.sh)" </dev/tty 2>&1 | tee "$_LXC_CAPTURE_LOG"
|
||||||
local lxc_exit=${PIPESTATUS[0]}
|
local lxc_exit=${PIPESTATUS[0]}
|
||||||
|
|
||||||
@@ -4397,14 +4394,9 @@ EOF'
|
|||||||
# Ensure terminal is sane before reading input (lxc-attach|tee may corrupt tty state)
|
# Ensure terminal is sane before reading input (lxc-attach|tee may corrupt tty state)
|
||||||
stty sane 2>/dev/null || true
|
stty sane 2>/dev/null || true
|
||||||
|
|
||||||
# Use the pre-opened tty fd (survives tty corruption from lxc-attach|tee)
|
# Read directly from /dev/tty (fresh open = clean state, no inherited corruption)
|
||||||
local _read_fd="${_RECOVERY_TTY:-}"
|
local response=""
|
||||||
local _read_src="</dev/tty"
|
if read -t 60 -r response </dev/tty 2>/dev/null; then
|
||||||
if [[ -n "$_read_fd" ]] && { true <&"$_read_fd"; } 2>/dev/null; then
|
|
||||||
_read_src="<&$_read_fd"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if eval "read -t 60 -r response $_read_src"; then
|
|
||||||
case "${response:-1}" in
|
case "${response:-1}" in
|
||||||
1)
|
1)
|
||||||
# Remove container
|
# Remove container
|
||||||
@@ -4601,8 +4593,6 @@ EOF'
|
|||||||
|
|
||||||
# Restore default job-control signal handling before exit
|
# Restore default job-control signal handling before exit
|
||||||
trap - TSTP TTIN TTOU
|
trap - TSTP TTIN TTOU
|
||||||
# Close pre-opened tty fd
|
|
||||||
[[ -n "${_RECOVERY_TTY:-}" ]] && exec {_RECOVERY_TTY}<&- 2>/dev/null || true
|
|
||||||
exit $install_exit_code
|
exit $install_exit_code
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -286,15 +286,10 @@ error_handler() {
|
|||||||
echo -en "${YW}Remove broken container ${CTID}? (Y/n) [auto-remove in 60s]: ${CL}"
|
echo -en "${YW}Remove broken container ${CTID}? (Y/n) [auto-remove in 60s]: ${CL}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use the pre-opened tty fd if available (survives tty corruption from lxc-attach|tee)
|
# Reset terminal state and read directly from /dev/tty (fresh open = clean state)
|
||||||
stty sane 2>/dev/null || true
|
stty sane 2>/dev/null || true
|
||||||
local _read_fd="${_RECOVERY_TTY:-}"
|
local response=""
|
||||||
local _read_src="</dev/tty"
|
if read -t 60 -r response </dev/tty 2>/dev/null; then
|
||||||
if [[ -n "$_read_fd" ]] && { true <&"$_read_fd"; } 2>/dev/null; then
|
|
||||||
_read_src="<&$_read_fd"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if eval "read -t 60 -r response $_read_src"; then
|
|
||||||
if [[ -z "$response" || "$response" =~ ^[Yy]$ ]]; then
|
if [[ -z "$response" || "$response" =~ ^[Yy]$ ]]; then
|
||||||
echo ""
|
echo ""
|
||||||
if declare -f msg_info >/dev/null 2>&1; then
|
if declare -f msg_info >/dev/null 2>&1; then
|
||||||
|
|||||||
Reference in New Issue
Block a user