diff --git a/src/kernel-install/60-ukify.install.in b/src/kernel-install/60-ukify.install.in index 0927bd7a2e8..96ca2482b06 100755 --- a/src/kernel-install/60-ukify.install.in +++ b/src/kernel-install/60-ukify.install.in @@ -186,7 +186,7 @@ def call_ukify(opts): # Create "empty" namespace. We want to override just a few settings, so it # doesn't make sense to configure everything. We pretend to parse an empty # argument set to prepopulate the namespace with the defaults. - opts2 = ukify['create_parser']().parse_args(()) + opts2 = ukify['create_parser']().parse_args(['build']) opts2.config = config_file_location() opts2.uname = opts.kernel_version diff --git a/src/ukify/test/test_ukify.py b/src/ukify/test/test_ukify.py index 5829bae6985..3ca9b531c24 100755 --- a/src/ukify/test/test_ukify.py +++ b/src/ukify/test/test_ukify.py @@ -87,7 +87,7 @@ def test_apply_config(tmp_path): Phases = {':'.join(ukify.KNOWN_PHASES)} ''')) - ns = ukify.create_parser().parse_args(()) + ns = ukify.create_parser().parse_args(['build']) ns.linux = None ns.initrd = [] ukify.apply_config(ns, config) diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py index ee8a9029bc3..9abaefec9ae 100755 --- a/src/ukify/ukify.py +++ b/src/ukify/ukify.py @@ -1187,6 +1187,31 @@ ukify [options…] VERB def finalize_options(opts): + # Figure out which syntax is being used, one of: + # ukify verb --arg --arg --arg + # ukify linux initrd… + if len(opts.positional) == 1 and opts.positional[0] in VERBS: + opts.verb = opts.positional[0] + elif opts.linux or opts.initrd: + raise ValueError('--linux/--initrd options cannot be used with positional arguments') + else: + print("Assuming obsolete commandline syntax with no verb. Please use 'build'.") + if opts.positional: + opts.linux = pathlib.Path(opts.positional[0]) + # If we have initrds from parsing config files, append our positional args at the end + opts.initrd = (opts.initrd or []) + [pathlib.Path(arg) for arg in opts.positional[1:]] + opts.verb = 'build' + + # Check that --pcr-public-key=, --pcr-private-key=, and --phases= + # have either the same number of arguments are are not specified at all. + n_pcr_pub = None if opts.pcr_public_keys is None else len(opts.pcr_public_keys) + n_pcr_priv = None if opts.pcr_private_keys is None else len(opts.pcr_private_keys) + n_phase_path_groups = None if opts.phase_path_groups is None else len(opts.phase_path_groups) + if n_pcr_pub is not None and n_pcr_pub != n_pcr_priv: + raise ValueError('--pcr-public-key= specifications must match --pcr-private-key=') + if n_phase_path_groups is not None and n_phase_path_groups != n_pcr_priv: + raise ValueError('--phases= specifications must match --pcr-private-key=') + if opts.cmdline and opts.cmdline.startswith('@'): opts.cmdline = pathlib.Path(opts.cmdline[1:]) elif opts.cmdline: @@ -1244,37 +1269,9 @@ def finalize_options(opts): def parse_args(args=None): - p = create_parser() - opts = p.parse_args(args) - - # Figure out which syntax is being used, one of: - # ukify verb --arg --arg --arg - # ukify linux initrd… - if len(opts.positional) == 1 and opts.positional[0] in VERBS: - opts.verb = opts.positional[0] - elif opts.linux or opts.initrd: - raise ValueError('--linux/--initrd options cannot be used with positional arguments') - else: - print("Assuming obsolete commandline syntax with no verb. Please use 'build'.") - if opts.positional: - opts.linux = pathlib.Path(opts.positional[0]) - opts.initrd = [pathlib.Path(arg) for arg in opts.positional[1:]] - opts.verb = 'build' - - # Check that --pcr-public-key=, --pcr-private-key=, and --phases= - # have either the same number of arguments are are not specified at all. - n_pcr_pub = None if opts.pcr_public_keys is None else len(opts.pcr_public_keys) - n_pcr_priv = None if opts.pcr_private_keys is None else len(opts.pcr_private_keys) - n_phase_path_groups = None if opts.phase_path_groups is None else len(opts.phase_path_groups) - if n_pcr_pub is not None and n_pcr_pub != n_pcr_priv: - raise ValueError('--pcr-public-key= specifications must match --pcr-private-key=') - if n_phase_path_groups is not None and n_phase_path_groups != n_pcr_priv: - raise ValueError('--phases= specifications must match --pcr-private-key=') - + opts = create_parser().parse_args(args) apply_config(opts) - finalize_options(opts) - return opts