summaryrefslogtreecommitdiffstats
path: root/src/ukify
diff options
context:
space:
mode:
authorJörg Behrmann <behrmann@physik.fu-berlin.de>2024-10-05 12:07:49 +0200
committerJörg Behrmann <behrmann@physik.fu-berlin.de>2024-10-09 12:11:57 +0200
commit206fa93c854e3d5c94e56da9b53e107245f31503 (patch)
treed9ad5874d1e5cb8463c8acb01c6736a15bfe2ec9 /src/ukify
parentukify: Move summary option handling out of finalize_options (diff)
downloadsystemd-206fa93c854e3d5c94e56da9b53e107245f31503.tar.xz
systemd-206fa93c854e3d5c94e56da9b53e107245f31503.zip
ukify: Ensure that find_tool always returns a tool or throws an error
This also makes the error message configurable, so that find_sbsign and find_pesign can be inlined again.
Diffstat (limited to 'src/ukify')
-rwxr-xr-xsrc/ukify/ukify.py24
1 files changed, 5 insertions, 19 deletions
diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py
index a2df3e83e3..d3cb41398e 100755
--- a/src/ukify/ukify.py
+++ b/src/ukify/ukify.py
@@ -265,8 +265,6 @@ class Uname:
@classmethod
def scrape_elf(cls, filename: Path, opts: Optional[argparse.Namespace] = None) -> str:
readelf = find_tool('readelf', opts=opts)
- if not readelf:
- raise ValueError('FIXME')
cmd = [
readelf,
@@ -479,7 +477,8 @@ def find_tool(
name: str,
fallback: Optional[str] = None,
opts: Optional[argparse.Namespace] = None,
-) -> Union[str, Path, None]:
+ msg: str = 'Tool {name} not installed!',
+) -> Union[str, Path]:
if opts and opts.tools:
for d in opts.tools:
tool = d / name
@@ -490,7 +489,7 @@ def find_tool(
return name
if fallback is None:
- print(f'Tool {name} not installed!')
+ raise ValueError(msg.format(name=name))
return fallback
@@ -530,8 +529,6 @@ def call_systemd_measure(uki: UKI, opts: argparse.Namespace, profile_start: int
'/usr/lib/systemd/systemd-measure',
opts=opts,
)
- if not measure_tool:
- raise ValueError('FIXME')
banks = opts.pcr_banks or ()
@@ -806,10 +803,6 @@ def signer_sign(cmd: list[Union[str, Path]]) -> None:
subprocess.check_call(cmd)
-def find_sbsign(opts: Optional[argparse.Namespace] = None) -> Union[str, Path, None]:
- return find_tool('sbsign', opts=opts)
-
-
def sbsign_sign(
sbsign_tool: Union[str, Path],
input_f: str,
@@ -830,10 +823,6 @@ def sbsign_sign(
signer_sign(sign_invocation)
-def find_pesign(opts: Optional[argparse.Namespace] = None) -> Union[str, Path, None]:
- return find_tool('pesign', opts=opts)
-
-
def pesign_sign(
pesign_tool: Union[str, Path],
input_f: str,
@@ -893,17 +882,14 @@ def make_uki(opts: argparse.Namespace) -> None:
if sign_args_present:
if opts.signtool == 'sbsign':
- sign_tool = find_sbsign(opts=opts)
+ sign_tool = find_tool('sbsign', opts=opts, msg='sbsign, required for signing, is not installed')
sign = sbsign_sign
verify_tool = SBVERIFY
else:
- sign_tool = find_pesign(opts=opts)
+ sign_tool = find_tool('pesign', opts=opts, msg='pesign, required for signing, is not installed')
sign = pesign_sign
verify_tool = PESIGCHECK
- if sign_tool is None:
- raise ValueError(f'{opts.signtool}, required for signing, is not installed')
-
if sign_kernel is None and opts.linux is not None:
# figure out if we should sign the kernel
sign_kernel = verify(verify_tool, opts)