From 30b2bff11ca6b2e339d2b49465f13eaaded52ddb Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 9 Oct 2023 08:57:53 +0200 Subject: [PATCH] rescue,main --- __main__.py | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++ rescue.sh | 41 ++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 __main__.py create mode 100644 rescue.sh diff --git a/__main__.py b/__main__.py new file mode 100644 index 0000000..6adcae2 --- /dev/null +++ b/__main__.py @@ -0,0 +1,97 @@ +#! /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() diff --git a/rescue.sh b/rescue.sh new file mode 100644 index 0000000..ec0031b --- /dev/null +++ b/rescue.sh @@ -0,0 +1,41 @@ +function set_uuid { + ESP_UUID='' + DATA_UUID='' + if [ ! "${DATA_UUID}" ] ; then + DATA_UUID="${ESP_UUID}" + fi +} + +function set_init { + set_uuid + # + search --no-floppy --set data \\ + --fs-uuid '${DATA_UUID}' + # + search --no-floppy --set esp \\ + --fs-uuid '${ESP_UUID}' + if [ "${esp}" ] ; then + env="(${esp})/grub.env" + live="(${esp})/${PROJECT}/live" + # + for file in ${live}/source/*.sh ; do + source "${file}" + done + unset file + fi +} + +function normal_init { + check_signatures='no' + pager=1 + # + set_init + if [ "${esp}" ] ; then + prefix="(${esp})/grub" + root="${esp}" + # + normal "${live}/normal.sh" + fi +} + +normal_init