Lock TERM to linux for LXC noVNC console

Append a guarded snippet to /root/.bash_profile that forces TERM=linux on physical LXC consoles (e.g. noVNC) for login shells. This prevents readline (8.2+) from querying CPR (ESC[6n) which can produce stray R;80R garbage; the change runs only for non-SSH sessions and detects /dev/console or /dev/ttyN. The block is only added if a __cs_console_term marker is not already present.
This commit is contained in:
CanbiZ (MickLesk)
2026-04-28 15:47:30 +02:00
parent 669d0d847f
commit 8520c25ca4

View File

@@ -1181,6 +1181,26 @@ fi
EOF
fi
# For LXC login shells (bash_profile runs before readline initialises):
# lock TERM=linux on the physical console so readline never queries CPR.
# This must run in bash_profile, not bashrc, because login shells source
# bash_profile first — readline reads TERM before any profile.d script runs.
if ! grep -q '__cs_console_term' /root/.bash_profile 2>/dev/null; then
cat >>/root/.bash_profile <<'EOF'
# __cs_console_term: lock TERM=linux on LXC noVNC console to prevent R;80R garbage
# (readline 8.2+ sends ESC[6n if TERM supports CPR; linux terminfo has no CPR cap)
if [ -z "${SSH_CONNECTION:-}${SSH_TTY:-}" ]; then
_ct=$(tty 2>/dev/null)
case "$_ct" in
/dev/console|/dev/tty[0-9]*)
export TERM=linux ;;
esac
unset _ct
fi
EOF
fi
# Get OS information
local os_name="$OS_TYPE"
local os_version="$OS_VERSION"