diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index fbe1bdff..e21d876c 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -75,6 +75,12 @@ if __name__ == '__main__': ) # Update boot entries + try_and_print( + message='Enabling boot entries...', + function=enable_boot_entries, + boot_entries=BOOT_ENTRIES, + boot_files=BOOT_FILES, + ) # Install syslinux diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 9a17ea64..dbce5bb6 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -68,6 +68,35 @@ def copy_source(source, items, overwrite=False): unmount('/mnt/Source') +def enable_boot_entries(boot_entries, boot_files): + """Enable boot entries if related paths exist.""" + configs = [] + + # Find config files + for c_path, c_ext in boot_files.items(): + c_path = find_path(c_path) + for item in os.scandir(c_path): + if item.name.lower().endswith(c_ext.lower()): + configs.append(item.path) + + # Uncomment found entries + for b_path, b_comment in boot_entries: + try: + find_path('/mnt/UFD{}'.format(b_path)) + except (FileNotFoundError, NotADirectoryError): + # Entry not found, continue to next entry + continue + + # Update config files + cmd = [ + 'sed', + '--in-place', + '"s/#{}#//"'.format(b_comment), + *configs, + ] + run_program(cmd) + + def find_path(path): """Find path case-insensitively, returns pathlib.Path obj.""" path_obj = pathlib.Path(path).resolve() diff --git a/.bin/Scripts/settings/ufd.py b/.bin/Scripts/settings/ufd.py index b09f84fe..dc7693c4 100644 --- a/.bin/Scripts/settings/ufd.py +++ b/.bin/Scripts/settings/ufd.py @@ -44,11 +44,16 @@ UFD_SOURCES = OrderedDict({ }) # Definitions: Boot entries -## NOTE: if key path exists uncomment #value# lines BOOT_ENTRIES = { - 'arch_minimal': 'MINIMAL', - 'dgpu': 'DGPU', - 'sources/boot.wim': 'WINPE', + # Path to check: Comment to remove + '/arch_minimal': 'UFD-MINIMAL', + '/dgpu': 'UFD-DGPU', + '/sources/boot.wim': 'UFD-WINPE', + } +BOOT_FILES = { + # Directory: extension + '/arch/boot/syslinux': 'cfg', + '/EFI/boot': 'conf', } # Definitions: Sources and Destinations