modules
This commit is contained in:
parent
30b2bff11c
commit
204ef539fc
2 changed files with 90 additions and 67 deletions
121
__main__.py
121
__main__.py
|
@ -4,77 +4,91 @@ import os
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
import rwx
|
||||
import rwx.arg
|
||||
import rwx.fs
|
||||
import rwx.grub
|
||||
import rwx.ps
|
||||
|
||||
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',
|
||||
('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',
|
||||
('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',
|
||||
('date', 'echo', 'eval', 'help', 'sleep', 'test', 'true'),
|
||||
('cpuid', 'lspci'),
|
||||
('cat', 'configfile', 'loadenv', 'progress', 'testspeed'),
|
||||
('hashsum', 'gcry_sha512', 'gcry_sha256'),
|
||||
('pgp', 'gcry_dsa', 'gcry_rsa'),
|
||||
)
|
||||
|
||||
|
||||
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)
|
||||
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')
|
||||
grub_root = os.path.join(esp_root, 'grub')
|
||||
grub_env = os.path.join(esp_root, 'grub.env')
|
||||
#
|
||||
print(f'''
|
||||
esp_root: {esp_root}
|
||||
data_uuid: {data_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_env: {grub_env}
|
||||
''', 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():
|
||||
command, *args = sys.argv
|
||||
def main() -> None:
|
||||
command, args = rwx.arg.split()
|
||||
if args:
|
||||
data, *args = args
|
||||
else:
|
||||
|
@ -82,14 +96,19 @@ def main():
|
|||
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}
|
||||
args: {args}
|
||||
↓
|
||||
project_file: {project_file}
|
||||
project_root: {project_root}
|
||||
parent_root: {parent_root}
|
||||
project_name: {project_name}
|
||||
''', end=str())
|
||||
#
|
||||
if project_name:
|
||||
build(parent_root, data_uuid=data)
|
||||
|
||||
|
||||
|
|
34
rescue.sh
34
rescue.sh
|
@ -1,23 +1,23 @@
|
|||
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}'
|
||||
unset esp
|
||||
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
|
||||
# TODO {}
|
||||
env="(${esp})/grub.env"
|
||||
live="(${esp})/${PROJECT}/live"
|
||||
# TODO {}
|
||||
live="(${esp})/lsgm/live"
|
||||
#
|
||||
# TODO {}
|
||||
for file in ${live}/source/*.sh ; do
|
||||
source "${file}"
|
||||
done
|
||||
|
@ -26,14 +26,18 @@ function set_init {
|
|||
}
|
||||
|
||||
function normal_init {
|
||||
# TODO {}
|
||||
check_signatures='no'
|
||||
pager=1
|
||||
# TODO {}
|
||||
pager=0
|
||||
#
|
||||
set_init
|
||||
if [ "${esp}" ] ; then
|
||||
# TODO {}
|
||||
prefix="(${esp})/grub"
|
||||
root="${esp}"
|
||||
#
|
||||
# TODO {}
|
||||
normal "${live}/normal.sh"
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue