diff --git a/misc/build.func b/misc/build.func index 4ed0f5850..e64fb896c 100644 --- a/misc/build.func +++ b/misc/build.func @@ -4391,12 +4391,16 @@ EOF' echo "" echo -en "${YW}Select option [1-${max_option}] (default: 1, auto-remove in 60s): ${CL}" - # Ensure terminal is sane before reading input (lxc-attach|tee may corrupt tty state) + # Restore terminal state after lxc-attach|tee pipeline stty sane 2>/dev/null || true + # Drain stale input from terminal buffer (lxc-attach|tee leaves residual data + # that causes read to return immediately with empty input) + dd iflag=nonblock if=/dev/tty of=/dev/null 2>/dev/null || true + sleep 0.3 - # Read directly from /dev/tty (fresh open = clean state, no inherited corruption) + # Read user choice local response="" - if read -t 60 -r response /dev/null; then + if read -t 60 -r response /dev/null || true + dd iflag=nonblock if=/dev/tty of=/dev/null 2>/dev/null || true + sleep 0.3 local response="" - if read -t 60 -r response /dev/null; then + if read -t 60 -r response /dev/null 2>&1; then diff --git a/misc/tools.func b/misc/tools.func index 0ebde4bd5..e9d08dc51 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -934,7 +934,11 @@ upgrade_package() { # ------------------------------------------------------------------------------ # Repository availability check with caching # ------------------------------------------------------------------------------ -declare -A _REPO_CACHE 2>/dev/null || true +# Note: Must use -gA (global) because tools.func is sourced inside update_os() +# function scope. Plain 'declare -A' would create a local variable that gets +# destroyed when update_os() returns, causing "unbound variable" errors later +# when setup_postgresql/verify_repo_available tries to access the cache key. +declare -gA _REPO_CACHE 2>/dev/null || declare -A _REPO_CACHE 2>/dev/null || true verify_repo_available() { local repo_url="$1"