#!/bin/env python3 # ## Wizard Kit: UFD build tool import os import sys # Init sys.path.append(os.path.dirname(os.path.realpath(__file__))) from collections import OrderedDict from docopt import docopt from functions.common import * from functions.ufd import * from settings.ufd import * init_global_vars() set_log_file('Build UFD ({Date-Time}).log'.format(**global_vars)) # Main section if __name__ == '__main__': try: args = docopt(DOCSTRING) sources = OrderedDict() # Verify selections ## UFD try: ufd_dev = find_path(args['--ufd-device']) except FileNotFoundError: print_error('ERROR: UFD device not found: {}'.format( args['--ufd-device'])) abort() if not is_valid_path(ufd_dev, 'UFD'): print_error('ERROR: Invalid UFD device: {}'.format(ufd_dev)) abort() ## Sources for label, data in UFD_SOURCES.items(): s_path = args[data['Arg']] if s_path: try: s_path_obj = find_path(s_path) except FileNotFoundError: print_error('ERROR: {} not found: {}'.format(label, s_path)) abort() if not is_valid_path(s_path_obj, data['Type']): print_error('ERROR: Invalid {} source: {}'.format(label, s_path)) abort() sources[label] = s_path_obj # Show selections ## Header clear_screen() print_success(KIT_NAME_FULL) print_standard('UFD Build Tool') print_standard(' ') ## Sources print_info('Sources') for label in UFD_SOURCES.keys(): if label in sources: print_standard(' {label:<18} {path}'.format( label=label+':', path=sources[label], )) else: print_standard(' {label:<18} {YELLOW}Not Specified{CLEAR}'.format( label=label+':', **COLORS, )) ## Destination print_standard(' ') print_info('Destination') cmd = [ 'lsblk', '--nodeps', '--noheadings', '--output', 'NAME,TRAN,SIZE,VENDOR,MODEL,SERIAL', ] result = run_program(cmd, check=False, encoding='utf-8', errors='ignore') print_standard(result.stdout.strip()) cmd = [ 'lsblk', '--noheadings', '--output', 'NAME,SIZE,FSTYPE,LABEL,MOUNTPOINT', ] result = run_program(cmd, check=False, encoding='utf-8', errors='ignore') for line in result.stdout.splitlines()[1:]: print_standard(line) if args['--use-mbr'] and not args['--update']: print_warning('Formatting using legacy MBR') print_standard(' ') if not ask('Is the above information correct?'): abort() ## Safety check print_standard(' ') print_warning('SAFETY CHECK') print_standard( 'All data will be DELETED from the disk and partition(s) listed above.') print_standard( 'This is irreversible and will lead to {RED}DATA LOSS.{CLEAR}'.format( **COLORS)) if not ask('Asking again to confirm, is this correct?'): abort() print_standard(' ') print_success("It's go-time!") exit_script(1) # TODO FIXME print_standard('UFD: {}'.format(ufd_dev)) print_standard('Sources:') for label, s_path in sources.items(): print_standard(' {:<16} {}'.format(label+':', s_path)) # Double-check if formating device # Format and partition device # Copy sources # Update boot entries # Install syslinux # Hide items # Unmount sources # Done if not args['--force']: print_standard('\nDone.') pause('Press Enter to exit...') exit_script() except SystemExit: pass except: major_exception() # vim: sts=2 sw=2 ts=2