rwx/rwx/grub/__init__.py
Marc Beninca 020aaa0b9a
All checks were successful
/ job (push) Successful in 1m12s
refactor(history): commit development branch
new development branch from root commit
2025-02-10 21:54:51 +01:00

54 lines
1.3 KiB
Python

"""Wrap GRUB commands."""
from __future__ import annotations
from rwx import cmd, ps
cmd.need("grub-mkimage")
COMPRESSION = "xz"
ENV_BYTES = 1024
ENV_COMMENT = "#"
ENV_HEADER = f"""{ENV_COMMENT} GRUB Environment Block
"""
MODULES = {
"i386-pc": [
("biosdisk",),
("ntldr",),
],
}
def make_image(
image_format: str,
image_path: str,
modules: list[str],
memdisk_path: str,
pubkey_path: str | None = None,
) -> None:
"""Make a binary bootable image.
:param image_format: output format (x86_64-efi, i386-pc, arm64-efi)
:type image_format: str
:param image_path: output file
:type image_path: str
:param modules: modules to embed
:type modules: list[str]
:param memdisk_path: archive to include
:type memdisk_path: str
:param pubkey_path: extra public key to add
:type pubkey_path: str | None
"""
args: list[str | tuple[str, ...]] = [
"grub-mkimage",
("--compress", COMPRESSION),
("--format", image_format),
("--output", image_path),
("--memdisk", memdisk_path),
]
if pubkey_path:
args.append(("--pubkey", pubkey_path))
args.extend(modules)
if extra_modules := MODULES.get(image_format):
args.extend(extra_modules)
ps.run(*args)