rescue,main

This commit is contained in:
Marc Beninca 2023-10-09 08:57:53 +02:00
parent b4724623f7
commit 30b2bff11c
2 changed files with 138 additions and 0 deletions

97
__main__.py Normal file
View file

@ -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()

41
rescue.sh Normal file
View file

@ -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