import shutil
import string
import subprocess
+import sys
import tempfile
import textwrap
import uuid
return creds
+def finalize_term() -> str:
+ if not (term := os.getenv("TERM")) or term == "unknown":
+ term = "vt220" if sys.stderr.isatty() else "dumb"
+
+ return term
+
+
def load_kernel_command_line_extra(args: argparse.Namespace) -> list[str]:
tty = args.architecture.default_serial_tty()
columns, lines = shutil.get_terminal_size()
+ term = finalize_term()
+
cmdline = [
# Make sure we set up networking in the VM/container.
"systemd.wants=network.target",
# Make sure we don't load vmw_vmci which messes with virtio vsock.
"module_blacklist=vmw_vmci",
- f"systemd.tty.term.{tty}={os.getenv('TERM', 'vt220')}",
+ f"systemd.tty.term.{tty}={term}",
f"systemd.tty.columns.{tty}={columns}",
f"systemd.tty.rows.{tty}={lines}",
]
cmdline += ["systemd.volatile=yes"]
if not args.qemu_gui:
- columns, lines = shutil.get_terminal_size()
cmdline += [
- f"systemd.tty.term.console={os.getenv('TERM', 'vt220')}",
+ f"systemd.tty.term.console={term}",
f"systemd.tty.columns.console={columns}",
f"systemd.tty.rows.console={lines}",
f"console={tty}",
+ f"TERM={term}",
]
for s in args.kernel_command_line_extra:
"SYSTEMD_TMPFILES_FORCE_SUBVOL": "0",
"KERNEL_INSTALL_BYPASS": "1",
"SYSTEMD_HWDB_UPDATE_BYPASS": "1",
+ "TERM": finalize_term(),
}
if args.image_id is not None:
env = {
"PATH": os.environ["PATH"],
- "TERM": os.getenv("TERM", "vt220"),
+ "TERM": env.get("TERM") or os.getenv("TERM", "vt220"),
"LANG": "C.UTF-8",
**env,
}
env = {
"PATH": os.environ["PATH"],
- "TERM": os.getenv("TERM", "vt220"),
+ "TERM": env.get("TERM") or os.getenv("TERM", "vt220"),
"LANG": "C.UTF-8",
**env,
}
import pytest
-from mkosi.config import Architecture
+from mkosi.config import Architecture, finalize_term
from mkosi.distributions import Distribution
from mkosi.run import run
from mkosi.types import _FILE, CompletedProcess, PathString
) -> CompletedProcess:
kcl = [
f"console={Architecture.native().default_serial_tty()}",
+ f"TERM={finalize_term()}",
"loglevel=6",
"systemd.crash_shell",
"systemd.log_level=debug",