Added boot entry sections

This commit is contained in:
2Shirt 2019-04-15 23:07:33 -07:00
parent 95f4877862
commit c16e97e49a
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
3 changed files with 44 additions and 4 deletions

View file

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

View file

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

View file

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