From: Luca Boccassi Date: Fri, 11 Dec 2020 15:56:44 +0000 (+0000) Subject: nspawn: check if --console is available before using it X-Git-Tag: v9~52^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F569%2Fhead;p=thirdparty%2Fmkosi.git nspawn: check if --console is available before using it On Debian Buster nspawn doesn't support this parameter (v241) --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 8a2843878..6b687f804 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -5240,6 +5240,9 @@ def one_zero(b: bool) -> str: return "1" if b else "0" +def nspawn_knows_arg(arg: str) -> bool: + return bytes("unrecognized option", "UTF-8") not in run(["systemd-nspawn", arg], stderr=PIPE, check=False).stderr + def run_build_script(args: CommandLineArguments, root: str, raw: Optional[BinaryIO]) -> None: if args.build_script is None: return @@ -5251,8 +5254,6 @@ def run_build_script(args: CommandLineArguments, root: str, raw: Optional[Binary target = "--directory=" + root if raw is None else "--image=" + raw.name cmdline = ["systemd-nspawn", - # TODO: Use --autopipe once systemd v247 is widely available. - f"--console={'interactive' if sys.stdout.isatty() else 'pipe'}", '--quiet', target, "--uuid=" + args.machine_id, @@ -5266,6 +5267,11 @@ def run_build_script(args: CommandLineArguments, root: str, raw: Optional[Binary "--setenv=WITH_NETWORK=" + one_zero(args.with_network), "--setenv=DESTDIR=/root/dest"] + # TODO: Use --autopipe once systemd v247 is widely available. + console_arg = f"--console={'interactive' if sys.stdout.isatty() else 'pipe'}" + if nspawn_knows_arg(console_arg): + cmdline.append(console_arg) + if args.default_path is not None: cmdline.append("--setenv=MKOSI_DEFAULT=" + args.default_path)