lsgm/__main__.py

98 lines
2.1 KiB
Python
Raw Normal View History

2023-10-09 06:57:53 +00:00
#! /usr/bin/env python3
import os
import subprocess
import sys
import rwx
CHARSET = 'UTF-8'
PGP = 'git@marc.beninca.link'
MODULES = (
'regexp',
'memdisk', 'tar',
'search',
'part_gpt', 'part_msdos',
'btrfs', 'ext2', 'fat', 'iso9660', 'udf',
'exfat', 'hfs', 'hfspluscomp', 'ntfscomp',
'linux', 'loopback', 'squash4',
#
'at_keyboard', 'keylayouts', 'keystatus', 'read',
'halt', 'reboot',
'all_video', 'videoinfo',
'gfxterm_background', 'jpeg', 'png', 'tga',
#
'date', 'echo', 'eval', 'help', 'sleep', 'test', 'true',
'cpuid', 'lspci',
'cat', 'configfile', 'loadenv', 'progress', 'testspeed',
'hashsum', 'gcry_sha512', 'gcry_sha256',
'pgp', 'gcry_dsa', 'gcry_rsa',
)
BIOS_MODULES = (
'biosdisk',
'ntldr',
)
def run(*args):
return subprocess.run(args, capture_output=False)
def run_line(*args):
lines = run_lines(*args)
return lines[0]
def run_lines(*args):
process = subprocess.run(args, capture_output=True)
return process.stdout.decode(CHARSET).rstrip().split(os.linesep)
def get_mount_uuid(path: str):
return run_line('findmnt', '--noheadings', '--output', 'UUID', path)
def get_path_mount(path: str):
return run_line('stat', '--format', '%m', path)
def get_path_uuid(path: str):
return get_mount_uuid(get_path_mount(path))
def build(esp_root: str, data_uuid=None):
esp_uuid = get_path_uuid(esp_root)
grub_root = os.path.join(esp_root, 'grub')
print(f'''
esp_root: {esp_root}
data_uuid: {data_uuid}
esp_uuid: {esp_uuid}
grub_root: {grub_root}
''', end=str())
def main():
command, *args = sys.argv
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)
print(f'''
command: {command}
data: {data}
project_file: {project_file}
project_root: {project_root}
parent_root: {parent_root}
project_name: {project_name}
''', end=str())
build(parent_root, data_uuid=data)
if __name__ == '__main__':
main()