From 51faf83696dec9de717f72534b2612ddfd752d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 13 Nov 2023 10:17:54 +0100 Subject: [PATCH 1/2] ukify: print a more readable synopsis in --help MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The details of formatting are copied from mkosi. This results in the following: usage: ukify build [--linux=LINUX] [--initrd=INITRD] [options…] ukify genkey [options…] ukify inspect FILE… [options…] Build and sign Unified Kernel Images options: --version show program's version number and exit ... I put "[options…]" at the end, because that's what one would generally do with long options like "--cmdline" and others. --- src/ukify/ukify.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py index b09fb4d5cc8..8006624f0a1 100755 --- a/src/ukify/ukify.py +++ b/src/ukify/ukify.py @@ -70,6 +70,14 @@ EFI_ARCHES: list[str] = sum(EFI_ARCH_MAP.values(), []) DEFAULT_CONFIG_DIRS = ['/run/systemd', '/etc/systemd', '/usr/local/lib/systemd', '/usr/lib/systemd'] DEFAULT_CONFIG_FILE = 'ukify.conf' +class Style: + bold = "\033[0;1;39m" if sys.stderr.isatty() else "" + gray = "\033[0;38;5;245m" if sys.stderr.isatty() else "" + red = "\033[31;1m" if sys.stderr.isatty() else "" + yellow = "\033[33;1m" if sys.stderr.isatty() else "" + reset = "\033[0m" if sys.stderr.isatty() else "" + + def guess_efi_arch(): arch = os.uname().machine @@ -1161,7 +1169,7 @@ CONFIG_ITEMS = [ 'positional', metavar = 'VERB', nargs = '*', - help = f"operation to perform ({','.join(VERBS)})", + help = argparse.SUPPRESS, ), ConfigItem( @@ -1499,11 +1507,13 @@ class PagerHelpAction(argparse._HelpAction): # pylint: disable=protected-access def create_parser(): p = argparse.ArgumentParser( description='Build and sign Unified Kernel Images', + usage='\n ' + textwrap.dedent('''\ + ukify {b}build{e} [--linux=LINUX] [--initrd=INITRD] [options…] + ukify {b}genkey{e} [options…] + ukify {b}inspect{e} FILE… [options…] + ''').format(b=Style.bold, e=Style.reset), allow_abbrev=False, add_help=False, - usage='''\ -ukify [options…] VERB -''', epilog='\n '.join(('config file:', *config_example())), formatter_class=argparse.RawDescriptionHelpFormatter, ) From e87dec82bec6eff015b368b3c746810d684fc6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 13 Nov 2023 10:41:52 +0100 Subject: [PATCH 2/2] ukify: show .sbom sections as text There are draft proposals to embed SBOM metadata in the .sbom section of PE binaries [1], in the coSWID XML format. Some details of how this is actually implemented might change, but it seems very likely that both section name and it being text will stay. Let's show the section as text to make such binaries easier to inspect. ([1] recommends using 'objcopy -j .sbom' which isn't particularly readable.) Once there's more standarization of the actual format, we can add pretty-printing and/or syntax highlighting. [1] https://uefi.org/blog/firmware-sbom-proposal [2] https://www.ietf.org/archive/id/draft-ietf-sacm-coswid-21.html --- src/ukify/ukify.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py index 8006624f0a1..2ab9c5894ce 100755 --- a/src/ukify/ukify.py +++ b/src/ukify/ukify.py @@ -265,6 +265,7 @@ DEFAULT_SECTIONS_TO_SHOW = { '.pcrpkey' : 'text', '.pcrsig' : 'text', '.sbat' : 'text', + '.sbom' : 'text', } @dataclasses.dataclass