149 lines
3.5 KiB
Python
Executable file
149 lines
3.5 KiB
Python
Executable file
#!/bin/env python3
|
|
#
|
|
# pylint: disable=no-name-in-module,wildcard-import,wrong-import-position
|
|
# vim: sts=2 sw=2 ts=2
|
|
"""Wizard Kit: UFD build tool"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
# Init
|
|
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
|
|
from docopt import docopt
|
|
from functions.common import *
|
|
from functions.ufd import *
|
|
from settings.ufd import *
|
|
init_global_vars(silent=True)
|
|
|
|
# Main section
|
|
if __name__ == '__main__':
|
|
# pylint: disable=invalid-name
|
|
# Set log
|
|
try:
|
|
global_vars['LogDir'] = '{}/Logs'.format(
|
|
get_user_home(get_user_name()))
|
|
set_log_file('Build UFD ({Date-Time}).log'.format(**global_vars))
|
|
except: # pylint: disable=bare-except
|
|
major_exception()
|
|
|
|
# Header
|
|
print_success(KIT_NAME_FULL)
|
|
print_standard('UFD Build Tool')
|
|
print_standard(' ')
|
|
|
|
# Check if running as root
|
|
if not running_as_root():
|
|
print_error('ERROR: This script is meant to be run as root.')
|
|
abort(False)
|
|
|
|
# Docopt
|
|
try:
|
|
args = docopt(DOCSTRING)
|
|
except SystemExit as sys_exit:
|
|
# Catch docopt exits
|
|
exit_script(sys_exit.code)
|
|
except: # pylint: disable=bare-except
|
|
major_exception()
|
|
|
|
try:
|
|
# Verify selections
|
|
ufd_dev = verify_ufd(args['--ufd-device'])
|
|
sources = verify_sources(args, UFD_SOURCES)
|
|
show_selections(args, sources, ufd_dev, UFD_SOURCES)
|
|
if not args['--force']:
|
|
confirm_selections(args)
|
|
|
|
# Prep UFD
|
|
if not args['--update']:
|
|
print_info('Prep UFD')
|
|
prep_device(ufd_dev, UFD_LABEL, use_mbr=args['--use-mbr'])
|
|
|
|
# Mount UFD
|
|
try_and_print(
|
|
indent=2,
|
|
message='Mounting UFD...',
|
|
function=mount,
|
|
mount_source=find_first_partition(ufd_dev),
|
|
mount_point='/mnt/UFD',
|
|
read_write=True,
|
|
)
|
|
|
|
# Remove Arch folder
|
|
if args['--update']:
|
|
try_and_print(
|
|
indent=2,
|
|
message='Removing Linux...',
|
|
function=remove_arch,
|
|
)
|
|
|
|
# Copy sources
|
|
print_standard(' ')
|
|
print_info('Copy Sources')
|
|
for s_label, s_path in sources.items():
|
|
try_and_print(
|
|
indent=2,
|
|
message='Copying {}...'.format(s_label),
|
|
function=copy_source,
|
|
source=s_path,
|
|
items=ITEMS[s_label],
|
|
overwrite=True,
|
|
)
|
|
|
|
# Update boot entries
|
|
print_standard(' ')
|
|
print_info('Boot Setup')
|
|
try_and_print(
|
|
indent=2,
|
|
message='Updating boot entries...',
|
|
function=update_boot_entries,
|
|
boot_entries=BOOT_ENTRIES,
|
|
boot_files=BOOT_FILES,
|
|
iso_label=ISO_LABEL,
|
|
ufd_label=UFD_LABEL,
|
|
)
|
|
|
|
# Install syslinux (to partition)
|
|
try_and_print(
|
|
indent=2,
|
|
message='Syslinux (partition)...',
|
|
function=install_syslinux_to_partition,
|
|
partition=find_first_partition(ufd_dev),
|
|
)
|
|
|
|
# Unmount UFD
|
|
try_and_print(
|
|
indent=2,
|
|
message='Unmounting UFD...',
|
|
function=unmount,
|
|
mount_point='/mnt/UFD',
|
|
)
|
|
|
|
# Install syslinux (to device)
|
|
try_and_print(
|
|
indent=2,
|
|
message='Syslinux (device)...',
|
|
function=install_syslinux_to_dev,
|
|
ufd_dev=ufd_dev,
|
|
use_mbr=args['--use-mbr'],
|
|
)
|
|
|
|
# Hide items
|
|
print_standard(' ')
|
|
print_info('Final Touches')
|
|
try_and_print(
|
|
indent=2,
|
|
message='Hiding items...',
|
|
function=hide_items,
|
|
ufd_dev=ufd_dev,
|
|
items=ITEMS_HIDDEN,
|
|
)
|
|
|
|
# Done
|
|
if not args['--force']:
|
|
print_standard('\nDone.')
|
|
pause('Press Enter to exit...')
|
|
exit_script()
|
|
except SystemExit as sys_exit:
|
|
exit_script(sys_exit.code)
|
|
except: # pylint: disable=bare-except
|
|
major_exception()
|