This commit is contained in:
Marc Beninca 2023-10-10 22:09:54 +02:00
parent 30b2bff11c
commit 204ef539fc
2 changed files with 90 additions and 67 deletions

View file

@ -4,77 +4,91 @@ import os
import subprocess import subprocess
import sys import sys
import rwx import rwx.arg
import rwx.fs
import rwx.grub
import rwx.ps
CHARSET = 'UTF-8' CHARSET = 'UTF-8'
PGP = 'git@marc.beninca.link' PGP = 'git@marc.beninca.link'
MODULES = ( MODULES = (
'regexp', ('regexp'),
'memdisk', 'tar', ('memdisk', 'tar'),
'search', ('search'),
'part_gpt', 'part_msdos', ('part_gpt', 'part_msdos'),
'btrfs', 'ext2', 'fat', 'iso9660', 'udf', ('btrfs', 'ext2', 'fat', 'iso9660', 'udf'),
'exfat', 'hfs', 'hfspluscomp', 'ntfscomp', ('exfat', 'hfs', 'hfspluscomp', 'ntfscomp'),
'linux', 'loopback', 'squash4', ('linux', 'loopback', 'squash4'),
# #
'at_keyboard', 'keylayouts', 'keystatus', 'read', ('at_keyboard', 'keylayouts', 'keystatus', 'read'),
'halt', 'reboot', ('halt', 'reboot'),
'all_video', 'videoinfo', ('all_video', 'videoinfo'),
'gfxterm_background', 'jpeg', 'png', 'tga', ('gfxterm_background', 'jpeg', 'png', 'tga'),
# #
'date', 'echo', 'eval', 'help', 'sleep', 'test', 'true', ('date', 'echo', 'eval', 'help', 'sleep', 'test', 'true'),
'cpuid', 'lspci', ('cpuid', 'lspci'),
'cat', 'configfile', 'loadenv', 'progress', 'testspeed', ('cat', 'configfile', 'loadenv', 'progress', 'testspeed'),
'hashsum', 'gcry_sha512', 'gcry_sha256', ('hashsum', 'gcry_sha512', 'gcry_sha256'),
'pgp', 'gcry_dsa', 'gcry_rsa', ('pgp', 'gcry_dsa', 'gcry_rsa'),
)
BIOS_MODULES = (
'biosdisk',
'ntldr',
) )
def run(*args): def build(esp_root: str, data_uuid: str=None) -> None:
return subprocess.run(args, capture_output=False) esp_uuid = rwx.fs.get_path_uuid(esp_root)
#
memdisk_root = os.path.join(esp_root, 'memdisk')
def run_line(*args): efi_root = os.path.join(esp_root, 'efi')
lines = run_lines(*args) efi_directory = os.path.join(efi_root, 'boot')
return lines[0] bios_root = os.path.join(esp_root, 'bios')
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') grub_root = os.path.join(esp_root, 'grub')
grub_env = os.path.join(esp_root, 'grub.env')
#
print(f''' print(f'''
esp_root: {esp_root} esp_root: {esp_root}
data_uuid: {data_uuid} data_uuid: {data_uuid}
esp_uuid: {esp_uuid} esp_uuid: {esp_uuid}
memdisk_root: {memdisk_root}
efi_root: {efi_root}
efi_directory: {efi_directory}
bios_root: {bios_root}
grub_root: {grub_root} grub_root: {grub_root}
grub_env: {grub_env}
''', end=str()) ''', end=str())
#
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(): def main() -> None:
command, *args = sys.argv command, args = rwx.arg.split()
if args: if args:
data, *args = args data, *args = args
else: else:
@ -82,14 +96,19 @@ def main():
project_file = os.path.realpath(__file__) project_file = os.path.realpath(__file__)
project_root = os.path.dirname(project_file) project_root = os.path.dirname(project_file)
parent_root, project_name = os.path.split(project_root) parent_root, project_name = os.path.split(project_root)
#
print(f''' print(f'''
command: {command} command: {command}
data: {data} data: {data}
args: {args}
project_file: {project_file} project_file: {project_file}
project_root: {project_root} project_root: {project_root}
parent_root: {parent_root} parent_root: {parent_root}
project_name: {project_name} project_name: {project_name}
''', end=str()) ''', end=str())
#
if project_name:
build(parent_root, data_uuid=data) build(parent_root, data_uuid=data)

View file

@ -1,23 +1,23 @@
function set_uuid {
ESP_UUID=''
DATA_UUID=''
if [ ! "${DATA_UUID}" ] ; then
DATA_UUID="${ESP_UUID}"
fi
}
function set_init { function set_init {
set_uuid
# #
search --no-floppy --set data \\ unset esp
--fs-uuid '${DATA_UUID}' search --no-floppy \
--set esp --fs-uuid '{}'
#
unset data
search --no-floppy \
--set data --fs-uuid '{}'
if [ ! "${data}" ] ; then
data="${esp}"
fi
# #
search --no-floppy --set esp \\
--fs-uuid '${ESP_UUID}'
if [ "${esp}" ] ; then if [ "${esp}" ] ; then
# TODO {}
env="(${esp})/grub.env" env="(${esp})/grub.env"
live="(${esp})/${PROJECT}/live" # TODO {}
live="(${esp})/lsgm/live"
# #
# TODO {}
for file in ${live}/source/*.sh ; do for file in ${live}/source/*.sh ; do
source "${file}" source "${file}"
done done
@ -26,14 +26,18 @@ function set_init {
} }
function normal_init { function normal_init {
# TODO {}
check_signatures='no' check_signatures='no'
pager=1 # TODO {}
pager=0
# #
set_init set_init
if [ "${esp}" ] ; then if [ "${esp}" ] ; then
# TODO {}
prefix="(${esp})/grub" prefix="(${esp})/grub"
root="${esp}" root="${esp}"
# #
# TODO {}
normal "${live}/normal.sh" normal "${live}/normal.sh"
fi fi
} }