lsgm/__main__.py

117 lines
2.8 KiB
Python
Raw Normal View History

2023-10-09 06:57:53 +00:00
#! /usr/bin/env python3
import os
import subprocess
import sys
2023-10-10 20:09:54 +00:00
import rwx.arg
import rwx.fs
import rwx.grub
import rwx.ps
2023-10-09 06:57:53 +00:00
CHARSET = 'UTF-8'
PGP = 'git@marc.beninca.link'
MODULES = (
2023-10-10 20:09:54 +00:00
('regexp'),
('memdisk', 'tar'),
('search'),
('part_gpt', 'part_msdos'),
('btrfs', 'ext2', 'fat', 'iso9660', 'udf'),
('exfat', 'hfs', 'hfspluscomp', 'ntfscomp'),
('linux', 'loopback', 'squash4'),
2023-10-09 06:57:53 +00:00
#
2023-10-10 20:09:54 +00:00
('at_keyboard', 'keylayouts', 'keystatus', 'read'),
('halt', 'reboot'),
('all_video', 'videoinfo'),
('gfxterm_background', 'jpeg', 'png', 'tga'),
2023-10-09 06:57:53 +00:00
#
2023-10-10 20:09:54 +00:00
('date', 'echo', 'eval', 'help', 'sleep', 'test', 'true'),
('cpuid', 'lspci'),
('cat', 'configfile', 'loadenv', 'progress', 'testspeed'),
('hashsum', 'gcry_sha512', 'gcry_sha256'),
('pgp', 'gcry_dsa', 'gcry_rsa'),
2023-10-09 06:57:53 +00:00
)
2023-10-10 20:09:54 +00:00
def build(esp_root: str, data_uuid: str=None) -> None:
esp_uuid = rwx.fs.get_path_uuid(esp_root)
#
memdisk_root = os.path.join(esp_root, 'memdisk')
efi_root = os.path.join(esp_root, 'efi')
efi_directory = os.path.join(efi_root, 'boot')
bios_root = os.path.join(esp_root, 'bios')
2023-10-09 06:57:53 +00:00
grub_root = os.path.join(esp_root, 'grub')
2023-10-10 20:09:54 +00:00
grub_env = os.path.join(esp_root, 'grub.env')
#
2023-10-09 06:57:53 +00:00
print(f'''
esp_root: {esp_root}
data_uuid: {data_uuid}
2023-10-10 20:09:54 +00:00
2023-10-09 06:57:53 +00:00
esp_uuid: {esp_uuid}
2023-10-10 20:09:54 +00:00
memdisk_root: {memdisk_root}
efi_root: {efi_root}
efi_directory: {efi_directory}
bios_root: {bios_root}
2023-10-09 06:57:53 +00:00
grub_root: {grub_root}
2023-10-10 20:09:54 +00:00
grub_env: {grub_env}
2023-10-09 06:57:53 +00:00
''', end=str())
2023-10-10 20:09:54 +00:00
#
memdisk_directory = os.path.join(memdisk_root, 'boot', 'grub')
memdisk_file = os.path.join(memdisk_directory, 'grub.cfg')
memdisk_archive = os.path.join(memdisk_root, 'boot.tar')
#
print(f'''
memdisk_directory: {memdisk_directory}
memdisk_file: {memdisk_file}
memdisk_archive: {memdisk_archive}
''', end=str())
#
rwx.fs.wipe(memdisk_root)
rwx.fs.make_directory(memdisk_directory)
rwx.fs.empty_file(memdisk_file)
# EFI
rwx.fs.wipe(efi_root)
rwx.fs.make_directory(efi_directory)
# BIOS
rwx.fs.wipe(bios_root)
rwx.fs.make_directory(bios_root)
#
rwx.fs.wipe(memdisk_root)
# GRUB
rwx.fs.wipe(grub_root)
# GRUB / environment
rwx.fs.write(grub_env,
rwx.grub.ENV_HEADER.ljust(rwx.grub.ENV_BYTES, rwx.grub.ENV_COMMENT))
def main() -> None:
command, args = rwx.arg.split()
2023-10-09 06:57:53 +00:00
if args:
data, *args = args
else:
data = None
project_file = os.path.realpath(__file__)
project_root = os.path.dirname(project_file)
parent_root, project_name = os.path.split(project_root)
2023-10-10 20:09:54 +00:00
#
2023-10-09 06:57:53 +00:00
print(f'''
command: {command}
data: {data}
2023-10-10 20:09:54 +00:00
args: {args}
2023-10-09 06:57:53 +00:00
project_file: {project_file}
project_root: {project_root}
parent_root: {parent_root}
project_name: {project_name}
''', end=str())
2023-10-10 20:09:54 +00:00
#
if project_name:
build(parent_root, data_uuid=data)
2023-10-09 06:57:53 +00:00
if __name__ == '__main__':
main()