40 lines
879 B
Python
40 lines
879 B
Python
"""Wrap GRUB commands."""
|
|
|
|
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."""
|
|
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)
|