Merge branch 'project-overhaul' into dev
This commit is contained in:
commit
8bcf9b032e
3 changed files with 59 additions and 56 deletions
|
|
@ -194,9 +194,11 @@ def run_program(cmd, check=True, pipe=True, shell=False, **kwargs):
|
||||||
pipe=pipe,
|
pipe=pipe,
|
||||||
shell=shell,
|
shell=shell,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
proc = subprocess.run(**cmd_kwargs)
|
||||||
|
LOG.debug('proc: %s', proc)
|
||||||
|
|
||||||
# Ready to run program
|
# Done
|
||||||
return subprocess.run(**cmd_kwargs)
|
return proc
|
||||||
|
|
||||||
|
|
||||||
def start_thread(function, args=None, daemon=True):
|
def start_thread(function, args=None, daemon=True):
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ def build_ufd():
|
||||||
try_print.run(
|
try_print.run(
|
||||||
message='Mounting UFD...',
|
message='Mounting UFD...',
|
||||||
function=linux.mount,
|
function=linux.mount,
|
||||||
mount_source=find_first_partition(ufd_dev),
|
source=find_first_partition(ufd_dev),
|
||||||
mount_point='/mnt/UFD',
|
mount_point='/mnt/UFD',
|
||||||
read_write=True,
|
read_write=True,
|
||||||
)
|
)
|
||||||
|
|
@ -124,7 +124,7 @@ def build_ufd():
|
||||||
try_print.run(
|
try_print.run(
|
||||||
message='Unmounting UFD...',
|
message='Unmounting UFD...',
|
||||||
function=linux.unmount,
|
function=linux.unmount,
|
||||||
mount_point='/mnt/UFD',
|
source_or_mountpoint='/mnt/UFD',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Install syslinux (to device)
|
# Install syslinux (to device)
|
||||||
|
|
@ -300,7 +300,40 @@ def prep_device(dev_path, label, use_mbr=False):
|
||||||
try_print = std.TryAndPrint()
|
try_print = std.TryAndPrint()
|
||||||
try_print.indent = 2
|
try_print.indent = 2
|
||||||
|
|
||||||
# Zero-out first 64MB
|
def _create_table():
|
||||||
|
"""Create GPT or DOS partition table."""
|
||||||
|
cmd = [
|
||||||
|
'parted', dev_path,
|
||||||
|
'--script',
|
||||||
|
'--',
|
||||||
|
'mklabel', 'msdos' if use_mbr else 'gpt',
|
||||||
|
'mkpart', 'primary', 'fat32', '4MiB',
|
||||||
|
'-1s' if use_mbr else '-4MiB',
|
||||||
|
]
|
||||||
|
run_program(cmd)
|
||||||
|
|
||||||
|
def _format_partition():
|
||||||
|
"""Format first partition on device FAT32."""
|
||||||
|
cmd = [
|
||||||
|
'mkfs.vfat',
|
||||||
|
'-F', '32',
|
||||||
|
'-n', label,
|
||||||
|
find_first_partition(dev_path),
|
||||||
|
]
|
||||||
|
run_program(cmd)
|
||||||
|
|
||||||
|
def _set_boot_flag():
|
||||||
|
"""Set modern or legacy boot flag."""
|
||||||
|
cmd = [
|
||||||
|
'parted', dev_path,
|
||||||
|
'set', '1',
|
||||||
|
'boot' if use_mbr else 'legacy_boot',
|
||||||
|
'on',
|
||||||
|
]
|
||||||
|
run_program(cmd)
|
||||||
|
|
||||||
|
def _zero_device():
|
||||||
|
"""Zero-out first 64MB of device."""
|
||||||
cmd = [
|
cmd = [
|
||||||
'dd',
|
'dd',
|
||||||
'bs=4M',
|
'bs=4M',
|
||||||
|
|
@ -308,51 +341,13 @@ def prep_device(dev_path, label, use_mbr=False):
|
||||||
'if=/dev/zero',
|
'if=/dev/zero',
|
||||||
f'of={dev_path}',
|
f'of={dev_path}',
|
||||||
]
|
]
|
||||||
try_print.run(
|
run_program(cmd)
|
||||||
message='Zeroing first 64MiB...',
|
|
||||||
function=run_program,
|
|
||||||
cmd=cmd,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create partition table
|
# Run steps
|
||||||
cmd = [
|
try_print.run('Zeroing first 64MiB...', function=_zero_device)
|
||||||
'parted', dev_path,
|
try_print.run('Creating partition table...', function=_create_table)
|
||||||
'--script',
|
try_print.run('Setting boot flag...', function=_set_boot_flag)
|
||||||
'--',
|
try_print.run('Formatting partition...', function=_format_partition)
|
||||||
'mklabel', 'msdos' if use_mbr else 'gpt',
|
|
||||||
'-1s' if use_mbr else '-4MiB',
|
|
||||||
]
|
|
||||||
try_print.run(
|
|
||||||
message='Creating partition table...',
|
|
||||||
function=run_program,
|
|
||||||
cmd=cmd,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Set boot flag
|
|
||||||
cmd = [
|
|
||||||
'parted', dev_path,
|
|
||||||
'set', '1',
|
|
||||||
'boot' if use_mbr else 'legacy_boot',
|
|
||||||
'on',
|
|
||||||
]
|
|
||||||
try_print.run(
|
|
||||||
message='Setting boot flag...',
|
|
||||||
function=run_program,
|
|
||||||
cmd=cmd,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Format partition
|
|
||||||
cmd = [
|
|
||||||
'mkfs.vfat',
|
|
||||||
'-F', '32',
|
|
||||||
'-n', label,
|
|
||||||
find_first_partition(dev_path),
|
|
||||||
]
|
|
||||||
try_print.run(
|
|
||||||
message='Formatting partition...',
|
|
||||||
function=run_program,
|
|
||||||
cmd=cmd,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def remove_arch():
|
def remove_arch():
|
||||||
|
|
@ -370,7 +365,7 @@ def show_selections(args, sources, ufd_dev, ufd_sources):
|
||||||
std.print_info('Sources')
|
std.print_info('Sources')
|
||||||
for label in ufd_sources.keys():
|
for label in ufd_sources.keys():
|
||||||
if label in sources:
|
if label in sources:
|
||||||
std.print_standard(f' {label+":":<18} {sources["label"]}')
|
std.print_standard(f' {label+":":<18} {sources[label]}')
|
||||||
else:
|
else:
|
||||||
std.print_colored(
|
std.print_colored(
|
||||||
[f' {label+":":<18}', 'Not Specified'],
|
[f' {label+":":<18}', 'Not Specified'],
|
||||||
|
|
@ -411,7 +406,11 @@ def update_boot_entries():
|
||||||
|
|
||||||
# Find config files
|
# Find config files
|
||||||
for c_path, c_ext in BOOT_FILES.items():
|
for c_path, c_ext in BOOT_FILES.items():
|
||||||
c_path = io.case_insensitive_path('/mnt/UFD{c_path}')
|
try:
|
||||||
|
c_path = io.case_insensitive_path(f'/mnt/UFD{c_path}')
|
||||||
|
except FileNotFoundError:
|
||||||
|
# Ignore and continue to next file
|
||||||
|
continue
|
||||||
for item in os.scandir(c_path):
|
for item in os.scandir(c_path):
|
||||||
if item.name.lower().endswith(c_ext.lower()):
|
if item.name.lower().endswith(c_ext.lower()):
|
||||||
configs.append(item.path)
|
configs.append(item.path)
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,8 @@ def mount(source, mount_point=None, read_write=False):
|
||||||
if not running_as_root():
|
if not running_as_root():
|
||||||
cmd.insert(0, 'udevil')
|
cmd.insert(0, 'udevil')
|
||||||
if mount_point:
|
if mount_point:
|
||||||
|
mount_point = pathlib.Path(mount_point).resolve()
|
||||||
|
mount_point.mkdir(parents=True, exist_ok=True)
|
||||||
cmd.append(mount_point)
|
cmd.append(mount_point)
|
||||||
|
|
||||||
# Run mount command
|
# Run mount command
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue