1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-22 06:50:18 +03:00

ukify: print debug/progress messages to stderr

Otherwise json will be interleaved with plain text messages

(cherry picked from commit 7d64e2f368ec7c683fee95d21f527c406b8eb5e6)
This commit is contained in:
Luca Boccassi 2025-01-19 15:42:47 +00:00
parent 528d7d616f
commit 47be0e801e

View File

@ -324,7 +324,7 @@ class Uname:
filename,
]
print('+', shell_join(cmd))
print('+', shell_join(cmd), file=sys.stderr)
try:
notes = subprocess.check_output(cmd, stderr=subprocess.PIPE, text=True)
except subprocess.CalledProcessError as e:
@ -355,7 +355,7 @@ class Uname:
for func in (cls.scrape_x86, cls.scrape_elf, cls.scrape_generic):
try:
version = func(filename, opts=opts)
print(f'Found uname version: {version}')
print(f'Found uname version: {version}', file=sys.stderr)
return version
except ValueError as e:
print(str(e))
@ -495,7 +495,7 @@ class PeSign(SignTool):
'-o', output_f,
] # fmt: skip
print('+', shell_join(cmd))
print('+', shell_join(cmd), file=sys.stderr)
subprocess.check_call(cmd)
@staticmethod
@ -505,7 +505,7 @@ class PeSign(SignTool):
tool = find_tool('pesign', opts=opts)
cmd = [tool, '-i', opts.linux, '-S']
print('+', shell_join(cmd))
print('+', shell_join(cmd), file=sys.stderr)
info = subprocess.check_output(cmd, text=True)
return 'No signatures found.' in info
@ -527,7 +527,7 @@ class SbSign(SignTool):
'--output', output_f,
] # fmt: skip
print('+', shell_join(cmd))
print('+', shell_join(cmd), file=sys.stderr)
subprocess.check_call(cmd)
@staticmethod
@ -537,7 +537,7 @@ class SbSign(SignTool):
tool = find_tool('sbverify', opts=opts)
cmd = [tool, '--list', opts.linux]
print('+', shell_join(cmd))
print('+', shell_join(cmd), file=sys.stderr)
info = subprocess.check_output(cmd, text=True)
return 'No signature table present' in info
@ -579,7 +579,7 @@ class SystemdSbSign(SignTool):
'--output', output_f,
] # fmt: skip
print('+', shell_join(cmd))
print('+', shell_join(cmd), file=sys.stderr)
subprocess.check_call(cmd)
@staticmethod
@ -626,7 +626,7 @@ def check_splash(filename: Optional[Path]) -> None:
return
img = Image.open(filename, formats=['BMP'])
print(f'Splash image {filename} is {img.width}×{img.height} pixels')
print(f'Splash image {filename} is {img.width}×{img.height} pixels', file=sys.stderr)
def check_inputs(opts: UkifyConfig) -> None:
@ -769,7 +769,7 @@ def call_systemd_measure(uki: UKI, opts: UkifyConfig, profile_start: int = 0) ->
*(f'--phase={phase_path}' for phase_path in itertools.chain.from_iterable(pp_groups)),
]
print('+', shell_join(cmd))
print('+', shell_join(cmd), file=sys.stderr)
subprocess.check_call(cmd)
# PCR signing
@ -807,7 +807,7 @@ def call_systemd_measure(uki: UKI, opts: UkifyConfig, profile_start: int = 0) ->
extra += [f'--phase={phase_path}' for phase_path in group or ()]
print('+', shell_join(cmd + extra)) # type: ignore
print('+', shell_join(cmd + extra), file=sys.stderr) # type: ignore
pcrsig = subprocess.check_output(cmd + extra, text=True) # type: ignore
pcrsig = json.loads(pcrsig)
pcrsigs += [pcrsig]
@ -1120,7 +1120,7 @@ def make_uki(opts: UkifyConfig) -> None:
signtool.sign(os.fspath(opts.linux), os.fspath(linux), opts=opts)
if opts.uname is None and opts.linux is not None:
print('Kernel version not specified, starting autodetection 😖.')
print('Kernel version not specified, starting autodetection 😖.', file=sys.stderr)
opts.uname = Uname.scrape(opts.linux, opts=opts)
uki = UKI(opts.stub)
@ -1138,7 +1138,7 @@ def make_uki(opts: UkifyConfig) -> None:
if opts.certificate_provider:
cmd += ['--certificate-source', f'provider:{opts.certificate_provider}']
print('+', shell_join(cmd))
print('+', shell_join(cmd), file=sys.stderr)
pcrpkey = subprocess.check_output(cmd)
else:
pcrpkey = Path(opts.pcr_public_keys[0])
@ -1150,7 +1150,7 @@ def make_uki(opts: UkifyConfig) -> None:
if opts.signing_provider:
cmd += ['--private-key-source', f'provider:{opts.signing_provider}']
print('+', shell_join(cmd))
print('+', shell_join(cmd), file=sys.stderr)
pcrpkey = subprocess.check_output(cmd)
hwids = None
@ -1249,7 +1249,10 @@ def make_uki(opts: UkifyConfig) -> None:
if n not in to_import:
continue
print(f"Copying section '{n}' from '{profile}': {pesection.Misc_VirtualSize} bytes")
print(
f"Copying section '{n}' from '{profile}': {pesection.Misc_VirtualSize} bytes",
file=sys.stderr,
)
uki.add_section(
Section.create(n, pesection.get_data(length=pesection.Misc_VirtualSize), measure=True)
)
@ -1278,7 +1281,7 @@ def make_uki(opts: UkifyConfig) -> None:
os.umask(umask := os.umask(0))
os.chmod(opts.output, 0o777 & ~umask)
print(f'Wrote {"signed" if sign_args_present else "unsigned"} {opts.output}')
print(f'Wrote {"signed" if sign_args_present else "unsigned"} {opts.output}', file=sys.stderr)
@contextlib.contextmanager
@ -1930,14 +1933,14 @@ def apply_config(namespace: argparse.Namespace, filename: Union[str, Path, None]
if namespace.config:
# Config set by the user, use that.
filename = namespace.config
print(f'Using config file: {filename}')
print(f'Using config file: {filename}', file=sys.stderr)
else:
# Try to look for a config file then use the first one found.
for config_dir in DEFAULT_CONFIG_DIRS:
filename = Path(config_dir) / DEFAULT_CONFIG_FILE
if filename.is_file():
# Found a config file, use it.
print(f'Using found config file: {filename}')
print(f'Using found config file: {filename}', file=sys.stderr)
break
else:
# No config file specified or found, nothing to do.
@ -2061,7 +2064,7 @@ def finalize_options(opts: argparse.Namespace) -> None:
elif opts.linux or opts.initrd:
raise ValueError('--linux=/--initrd= options cannot be used with positional arguments')
else:
print("Assuming obsolete command line syntax with no verb. Please use 'build'.")
print("Assuming obsolete command line syntax with no verb. Please use 'build'.", file=sys.stderr)
if opts.positional:
opts.linux = Path(opts.positional[0])
# If we have initrds from parsing config files, append our positional args at the end