rwx/grub/__init__.py

34 lines
758 B
Python
Raw Normal View History

2024-02-16 20:31:38 +00:00
import cmd
import ps
cmd.need('grub-mkimage')
2023-10-10 20:11:57 +00:00
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],
2024-02-16 18:49:37 +00:00
memdisk_path: str, pubkey_path: str = None) -> None:
2023-10-10 20:11:57 +00:00
args = [
('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 modules := MODULES.get(image_format, None):
args.extend(modules)
ps.run(*args)