From a22e6f552f5c3b31db5f5969889e5d63dfa3a68c Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 7 Apr 2019 19:01:03 -0700 Subject: [PATCH 001/113] Start build-ufd rewrite in python --- .bin/Scripts/{build-ufd => build-ufd.bash} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .bin/Scripts/{build-ufd => build-ufd.bash} (100%) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd.bash similarity index 100% rename from .bin/Scripts/build-ufd rename to .bin/Scripts/build-ufd.bash From 639a338cca8101afad48d51e057a2a15090b1da8 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 7 Apr 2019 19:03:56 -0700 Subject: [PATCH 002/113] Initial Python layout * Going to use docopt for argument handling * Script will be run as user using sudo where needed * Tentatively dropping tmux usage --- .bin/Scripts/build-ufd | 89 ++++++++++++++++++++++++++++++++ .bin/Scripts/functions/common.py | 51 +++++++++--------- .linux_items/packages/live_add | 1 + 3 files changed, 114 insertions(+), 27 deletions(-) create mode 100755 .bin/Scripts/build-ufd diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd new file mode 100755 index 00000000..d73b306c --- /dev/null +++ b/.bin/Scripts/build-ufd @@ -0,0 +1,89 @@ +#!/bin/env python3 +# +## Wizard Kit: UFD build tool + +# Init +import os +import sys + +sys.path.append(os.path.dirname(os.path.realpath(__file__))) + +from docopt import docopt +from functions.common import * + +set_log_file('Build UFD ({Date-Time}).log'.format(**global_vars['Env'])) + + +# STATIC VARIABLES +DOCSTRING = '''Build UFD. + +Usage: + build-ufd [options] --ufd-device PATH --linux-iso PATH + [--linux-minimal-iso PATH] + [--main-kit PATH] + [--winpe-iso PATH] + [--extra-dir PATH] + build-ufd (-h | --help) + +Options: + -e PATH, --extra-dir PATH + -k PATH, --main-kit PATH + -l PATH, --linux-iso PATH + -m PATH, --linux-minimal-iso PATH + -u PATH, --ufd-device PATH + -w PATH, --winpe-iso PATH + + -d --debug Enable debug mode + -h --help Show this page + -v --verbose Enable verbose mode + -M --use-mbr Use real MBR instead of GPT w/ Protective MBR + -F --force Bypass all confirmation messages. USE WITH EXTREME CAUTION! + -U --update Don't format device, just update +''' +ISO_LABEL = '{}_LINUX'.format(KIT_NAME_SHORT) +UFD_LABEL = '{}_UFD'.format(KIT_NAME_SHORT) + + +# Functions +def get_full_path(item): + """Get full path to item, returns str.""" + #TODO + pass + + +def is_block_device(item): + """Verify item is a block device, returns bool.""" + #TODO + pass + + +def is_valid_main_kit(path): + """Verify path contains the main kit, returns bool.""" + + +# Main section +if __name__ == '__main__': + args = docopt(DOCSTRING) + + # Verify selections + + # Show selections + + # Double-check if formating device + + # Format and partition device + + # Mount sources + + # Copy sources + + # Update boot entries + + # Install syslinux + + # Hide items + + # Unmount sources + + +# vim: sts=2 sw=2 ts=2 diff --git a/.bin/Scripts/functions/common.py b/.bin/Scripts/functions/common.py index 502c985b..bbc2529c 100644 --- a/.bin/Scripts/functions/common.py +++ b/.bin/Scripts/functions/common.py @@ -879,25 +879,19 @@ def make_tmp_dirs(): def set_common_vars(): """Set common variables.""" - global_vars['Date'] = time.strftime("%Y-%m-%d") - global_vars['Date-Time'] = time.strftime("%Y-%m-%d_%H%M_%z") - global_vars['Env'] = os.environ.copy() + global_vars['Date'] = time.strftime("%Y-%m-%d") + global_vars['Date-Time'] = time.strftime("%Y-%m-%d_%H%M_%z") + global_vars['Env'] = os.environ.copy() global_vars['ArchivePassword'] = ARCHIVE_PASSWORD - global_vars['BinDir'] = r'{BaseDir}\.bin'.format( - **global_vars) - global_vars['CBinDir'] = r'{BaseDir}\.cbin'.format( - **global_vars) - global_vars['ClientDir'] = r'{SYSTEMDRIVE}\{prefix}'.format( - prefix=KIT_NAME_SHORT, **global_vars['Env']) - global_vars['BackupDir'] = r'{ClientDir}\Backups'.format( - **global_vars) - global_vars['LogDir'] = r'{ClientDir}\Logs\{Date}'.format( - **global_vars) - global_vars['QuarantineDir'] = r'{ClientDir}\Quarantine'.format( - **global_vars) - global_vars['TmpDir'] = r'{BinDir}\tmp'.format( - **global_vars) + global_vars['BinDir'] = r'{BaseDir}\.bin'.format(**global_vars) + global_vars['CBinDir'] = r'{BaseDir}\.cbin'.format(**global_vars) + global_vars['ClientDir'] = r'{SYSTEMDRIVE}\{prefix}'.format( + prefix=KIT_NAME_SHORT, **global_vars['Env']) + global_vars['BackupDir'] = r'{ClientDir}\Backups'.format(**global_vars) + global_vars['LogDir'] = r'{ClientDir}\Logs\{Date}'.format(**global_vars) + global_vars['QuarantineDir'] = r'{ClientDir}\Quarantine'.format(**global_vars) + global_vars['TmpDir'] = r'{BinDir}\tmp'.format(**global_vars) def set_linux_vars(): @@ -905,12 +899,12 @@ def set_linux_vars(): These assume we're running under a WK-Linux build.""" result = run_program(['mktemp', '-d']) - global_vars['TmpDir'] = result.stdout.decode().strip() - global_vars['Date'] = time.strftime("%Y-%m-%d") - global_vars['Date-Time'] = time.strftime("%Y-%m-%d_%H%M_%z") - global_vars['Env'] = os.environ.copy() - global_vars['BinDir'] = '/usr/local/bin' - global_vars['LogDir'] = global_vars['TmpDir'] + global_vars['TmpDir'] = result.stdout.decode().strip() + global_vars['Date'] = time.strftime("%Y-%m-%d") + global_vars['Date-Time'] = time.strftime("%Y-%m-%d_%H%M_%z") + global_vars['Env'] = os.environ.copy() + global_vars['BinDir'] = '/usr/local/bin' + global_vars['LogDir'] = '{}/Logs',format(global_vars['Env']['HOME']) global_vars['Tools'] = { 'wimlib-imagex': 'wimlib-imagex', 'SevenZip': '7z', @@ -919,10 +913,13 @@ def set_linux_vars(): def set_log_file(log_name): """Sets global var LogFile and creates path as needed.""" - folder_path = '{}{}{}'.format( - global_vars['LogDir'], - os.sep, - KIT_NAME_FULL) + if psutil.LINUX: + folder_path = global_vars['LogDir'] + else: + folder_path = '{}{}{}'.format( + global_vars['LogDir'], + os.sep, + KIT_NAME_FULL) log_file = '{}{}{}'.format( folder_path, os.sep, diff --git a/.linux_items/packages/live_add b/.linux_items/packages/live_add index 668c10c0..57f77bc1 100644 --- a/.linux_items/packages/live_add +++ b/.linux_items/packages/live_add @@ -31,6 +31,7 @@ networkmanager p7zip progsreiserfs python +python-docopt python-psutil python-requests reiserfsprogs From 3ff0bcd3c97f32b12852fbb0a94050560cde3aa3 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 7 Apr 2019 19:07:31 -0700 Subject: [PATCH 003/113] Updated new_system_setup.py to match other scripts * i.e. don't change dir when setting sys.path --- .bin/Scripts/new_system_setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.bin/Scripts/new_system_setup.py b/.bin/Scripts/new_system_setup.py index 170cf323..1f6cfcd0 100644 --- a/.bin/Scripts/new_system_setup.py +++ b/.bin/Scripts/new_system_setup.py @@ -4,8 +4,7 @@ import os import sys # Init -os.chdir(os.path.dirname(os.path.realpath(__file__))) -sys.path.append(os.getcwd()) +sys.path.append(os.path.dirname(os.path.realpath(__file__))) from functions.activation import * from functions.browsers import * from functions.cleanup import * From 575126eaa2ce91e1f1f34750258b92ea851e7216 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 7 Apr 2019 20:51:54 -0700 Subject: [PATCH 004/113] Split build-ufd file to match other scripts --- .bin/Scripts/build-ufd | 109 +++++++++++++++------------------- .bin/Scripts/functions/ufd.py | 27 +++++++++ .bin/Scripts/settings/ufd.py | 80 +++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 62 deletions(-) create mode 100644 .bin/Scripts/functions/ufd.py create mode 100644 .bin/Scripts/settings/ufd.py diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index d73b306c..b7324dd1 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -2,88 +2,73 @@ # ## Wizard Kit: UFD build tool -# Init 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() set_log_file('Build UFD ({Date-Time}).log'.format(**global_vars['Env'])) -# STATIC VARIABLES -DOCSTRING = '''Build UFD. - -Usage: - build-ufd [options] --ufd-device PATH --linux-iso PATH - [--linux-minimal-iso PATH] - [--main-kit PATH] - [--winpe-iso PATH] - [--extra-dir PATH] - build-ufd (-h | --help) - -Options: - -e PATH, --extra-dir PATH - -k PATH, --main-kit PATH - -l PATH, --linux-iso PATH - -m PATH, --linux-minimal-iso PATH - -u PATH, --ufd-device PATH - -w PATH, --winpe-iso PATH - - -d --debug Enable debug mode - -h --help Show this page - -v --verbose Enable verbose mode - -M --use-mbr Use real MBR instead of GPT w/ Protective MBR - -F --force Bypass all confirmation messages. USE WITH EXTREME CAUTION! - -U --update Don't format device, just update -''' -ISO_LABEL = '{}_LINUX'.format(KIT_NAME_SHORT) -UFD_LABEL = '{}_UFD'.format(KIT_NAME_SHORT) - - -# Functions -def get_full_path(item): - """Get full path to item, returns str.""" - #TODO - pass - - -def is_block_device(item): - """Verify item is a block device, returns bool.""" - #TODO - pass - - -def is_valid_main_kit(path): - """Verify path contains the main kit, returns bool.""" - - # Main section if __name__ == '__main__': - args = docopt(DOCSTRING) + try: + args = docopt(DOCSTRING) + sources = () - # Verify selections + # Verify selections + ## UFD + try: + ufd_dev = get_full_path(args['--ufd-device']) + if not is_block_device(ufd_dev): + print_error('Invalid UFD device: {}'.format(ufd_dev)) + abort() + except Exception: + # TODO Catch FileNotFound exception and abort accordingly + raise + ## Sources + for label, source in UFD_SOURCES: + if args[source]: + try: + sources.append((label, get_full_path(source))) + except Exception: + # TODO Catch FileNotFound exception and abort accordingly + raise - # Show selections + # Show selections + # TODO FIXME + print_standard('UFD: {}'.format(ufd_dev)) + print_standard('Sources:') + for s in sources: + print_standard(' {}: {}'.format(*s)) - # Double-check if formating device + # Double-check if formating device - # Format and partition device + # Format and partition device - # Mount sources + # Copy sources - # Copy sources + # Update boot entries - # Update boot entries + # Install syslinux - # Install syslinux + # Hide items - # Hide items + # Unmount sources - # 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 diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py new file mode 100644 index 00000000..654f1f27 --- /dev/null +++ b/.bin/Scripts/functions/ufd.py @@ -0,0 +1,27 @@ +# Wizard Kit: Functions - UFD + +from functions.common import * + + +def get_full_path(item): + """Get full path to item, returns str.""" + #TODO + pass + + +def is_block_device(item): + """Verify item is a block device, returns bool.""" + #TODO + pass + + +def is_valid_main_kit(path): + """Verify path contains the main kit, returns bool.""" + #TODO + pass + + +if __name__ == '__main__': + print("This file is not meant to be called directly.") + +# vim: sts=2 sw=2 ts=2 diff --git a/.bin/Scripts/settings/ufd.py b/.bin/Scripts/settings/ufd.py new file mode 100644 index 00000000..b7f552eb --- /dev/null +++ b/.bin/Scripts/settings/ufd.py @@ -0,0 +1,80 @@ +# Wizard Kit: Settings - UFD + +from settings.main import * + +# General +DOCSTRING = '''WizardKit: Build UFD + +Usage: + build-ufd [options] --ufd-device PATH --linux-iso PATH + [--linux-minimal-iso PATH] + [--main-kit PATH] + [--winpe-iso PATH] + [--extra-dir PATH] + build-ufd (-h | --help) + +Options: + -e PATH, --extra-dir PATH + -k PATH, --main-kit PATH + -l PATH, --linux-iso PATH + -m PATH, --linux-minimal-iso PATH + -u PATH, --ufd-device PATH + -w PATH, --winpe-iso PATH + + -d --debug Enable debug mode + -h --help Show this page + -v --verbose Enable verbose mode + -M --use-mbr Use real MBR instead of GPT w/ Protective MBR + -F --force Bypass all confirmation messages. USE WITH EXTREME CAUTION! + -U --update Don't format device, just update +''' +ISO_LABEL = '{}_LINUX'.format(KIT_NAME_SHORT) +UFD_LABEL = '{}_UFD'.format(KIT_NAME_SHORT) +UFD_SOURCES = ( + # NOTE: Using tuple of tuples to ensure copy order + ('Linux', '--linux-iso'), + ('Linux (Minimal)', '--linux-minimal-iso'), + ('WinPE', '--winpe-iso'), + ('Main Kit', '--main-kit'), + ('Extras', '--extra-dir'), + ) + +# Definitions: Boot entries +## NOTE: if key path exists uncomment #value# lines +BOOT_ENTRIES = { + 'arch_minimal': 'MINIMAL', + 'sources/boot.wim': 'WINPE', + } + +# Definitions: Sources and Destinations +## NOTES: Paths are relative to the root of the ISO/UFD +## Sources use rsync's trailing slash syntax +ITEMS_LINUX_FULL = ( + ('/arch', '/'), + ('/isolinux', '/'), + ('/EFI/boot', '/EFI/'), + ('/EFI/memtest86', '/EFI/'), + ) +ITEMS_LINUX_MINIMAL = ( + ('/arch/boot/archiso.img', '/arch_minimal/'), + ('/arch/boot/vmlinuz', '/arch_minimal/'), + ('/arch/pkglist.x86_64.txt', '/arch_minimal/'), + ('/arch/x86_64', '/arch_minimal/'), + ) +ITEMS_WINPE = ( + ('/bootmgr', '/'), + ('/bootmgr.efi', '/'), + ('/en_us', '/'), + ('/Boot/', '/boot/'), + ('/EFI/Boot/', '/EFI/Microsoft/'), + ('/EFI/Microsoft/', '/EFI/Microsoft/'), + ('/Boot/BCD', '/sources/'), + ('/Boot/boot.sdi', '/sources/'), + ('/bootmgr', '/sources/'), + ('/sources/boot.wim', '/sources/'), + ) + +if __name__ == '__main__': + print("This file is not meant to be called directly.") + +# vim: sts=2 sw=2 ts=2 From c4d00a2073cc2580715c6bf0c8c4b562ea3cca06 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 7 Apr 2019 22:35:09 -0700 Subject: [PATCH 005/113] Fix typos --- .bin/Scripts/build-ufd | 2 +- .bin/Scripts/functions/common.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index b7324dd1..a5577907 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -11,7 +11,7 @@ from docopt import docopt from functions.ufd import * from settings.ufd import * init_global_vars() -set_log_file('Build UFD ({Date-Time}).log'.format(**global_vars['Env'])) +set_log_file('Build UFD ({Date-Time}).log'.format(**global_vars)) # Main section diff --git a/.bin/Scripts/functions/common.py b/.bin/Scripts/functions/common.py index bbc2529c..b6008d27 100644 --- a/.bin/Scripts/functions/common.py +++ b/.bin/Scripts/functions/common.py @@ -904,7 +904,7 @@ def set_linux_vars(): global_vars['Date-Time'] = time.strftime("%Y-%m-%d_%H%M_%z") global_vars['Env'] = os.environ.copy() global_vars['BinDir'] = '/usr/local/bin' - global_vars['LogDir'] = '{}/Logs',format(global_vars['Env']['HOME']) + global_vars['LogDir'] = '{}/Logs'.format(global_vars['Env']['HOME']) global_vars['Tools'] = { 'wimlib-imagex': 'wimlib-imagex', 'SevenZip': '7z', From cd0a9456cb20cb862140409d49f72c3dbdde59ee Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 7 Apr 2019 22:41:41 -0700 Subject: [PATCH 006/113] Use pathlib.Path to resolve paths * is_block_device() is no longer needed * (pathlib.Path provides that functionality) --- .bin/Scripts/functions/ufd.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 654f1f27..441b4770 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -1,24 +1,21 @@ # Wizard Kit: Functions - UFD +import pathlib from functions.common import * def get_full_path(item): - """Get full path to item, returns str.""" - #TODO - pass + """Get full path to item, returns pathlib.Path obj.""" + path_obj = pathlib.Path(item).resolve() + if not path_obj.exists(): + raise FileNotFoundError(path_obj) + + return path_obj -def is_block_device(item): - """Verify item is a block device, returns bool.""" - #TODO - pass - - -def is_valid_main_kit(path): - """Verify path contains the main kit, returns bool.""" - #TODO - pass +def is_valid_main_kit(path_obj): + """Verify PathObj contains the main kit, returns bool.""" + return path_obj.is_dir() and path_obj.joinpath('.bin').exists() if __name__ == '__main__': From b6c6fc9aa9f9c8e0aa503cc7b06792dfb5de8bc0 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 7 Apr 2019 22:44:15 -0700 Subject: [PATCH 007/113] Find paths case-insensitively --- .bin/Scripts/functions/ufd.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 441b4770..9aeb1b3d 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -4,6 +4,33 @@ import pathlib from functions.common import * +def case_insensitive_search(path, item): + """Search path for item case insensitively, returns str.""" + if os.path.exists('{}/{}'.format(path, item)): + # Easy mode + return '{}/{}'.format(path, item) + + # Check all items in dir + for entry in os.scandir(path): + if re.match(entry.name, item, re.IGNORECASE): + return '{}/{}'.format(path, entry.name) + + # If we get here the item wasn't found + raise FileNotFoundError('{}/{}'.format(path, item)) + + +def find_source_item(source_dir, item): + """Find item relative to source dir, returns str.""" + path = source_dir + if item.startswith('/'): + item = item[1:] + + for part in item.split('/'): + path = case_insensitive_search(path, part) + + return path + + def get_full_path(item): """Get full path to item, returns pathlib.Path obj.""" path_obj = pathlib.Path(item).resolve() From 50cb765108c5cb84bd22c63a314564b24d3e9dce Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 7 Apr 2019 23:26:22 -0700 Subject: [PATCH 008/113] Merged find_source_item() and get_full_path() * Also fixed regex match (it wasn't matching the whole string) --- .bin/Scripts/functions/ufd.py | 49 +++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 9aeb1b3d..e6a13c47 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -6,37 +6,48 @@ from functions.common import * def case_insensitive_search(path, item): """Search path for item case insensitively, returns str.""" + regex_match = '^{}$'.format(item) + real_path = '' + + # Quick check first if os.path.exists('{}/{}'.format(path, item)): - # Easy mode - return '{}/{}'.format(path, item) + real_path = '{}{}{}'.format( + path, + '' if path == '/' else '/', + item, + ) # Check all items in dir for entry in os.scandir(path): - if re.match(entry.name, item, re.IGNORECASE): - return '{}/{}'.format(path, entry.name) + if re.match(regex_match, entry.name, re.IGNORECASE): + real_path = '{}{}{}'.format( + path, + '' if path == '/' else '/', + entry.name, + ) - # If we get here the item wasn't found - raise FileNotFoundError('{}/{}'.format(path, item)) + # Done + if real_path: + return real_path + else: + raise FileNotFoundError('{}/{}'.format(path, item)) -def find_source_item(source_dir, item): - """Find item relative to source dir, returns str.""" - path = source_dir - if item.startswith('/'): - item = item[1:] +def find_path(path): + """Find path case-insensitively, returns pathlib.Path obj.""" + parts = pathlib.Path(path).resolve().relative_to('/').parts + real_path = '/' - for part in item.split('/'): - path = case_insensitive_search(path, part) + # Fix case + for part in parts: + real_path = case_insensitive_search(real_path, part) - return path - - -def get_full_path(item): - """Get full path to item, returns pathlib.Path obj.""" - path_obj = pathlib.Path(item).resolve() + # Raise error if path doesn't exist + path_obj = pathlib.Path(real_path) if not path_obj.exists(): raise FileNotFoundError(path_obj) + # Done return path_obj From e420074c833f39c3157a7804a8d0d3bc97a2f8e9 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 7 Apr 2019 23:35:00 -0700 Subject: [PATCH 009/113] Use correct errors in find_path() * FileNotFoundError is accurate since we're just looking for a path --- .bin/Scripts/functions/ufd.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index e6a13c47..83dd1852 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -40,7 +40,11 @@ def find_path(path): # Fix case for part in parts: - real_path = case_insensitive_search(real_path, part) + try: + real_path = case_insensitive_search(real_path, part) + except NotADirectoryError: + # Reclassify error + raise FileNotFoundError(path) # Raise error if path doesn't exist path_obj = pathlib.Path(real_path) From b166172d10faabff877f72094edc7be5746423a1 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 7 Apr 2019 23:45:08 -0700 Subject: [PATCH 010/113] Only perform case-insensitive search if needed --- .bin/Scripts/functions/ufd.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 83dd1852..f0ce6ad3 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -35,10 +35,15 @@ def case_insensitive_search(path, item): def find_path(path): """Find path case-insensitively, returns pathlib.Path obj.""" - parts = pathlib.Path(path).resolve().relative_to('/').parts - real_path = '/' + path_obj = pathlib.Path(path).resolve() + + # Quick check first + if path_obj.exists(): + return path_obj # Fix case + parts = path_obj.relative_to('/').parts + real_path = '/' for part in parts: try: real_path = case_insensitive_search(real_path, part) From 4c33c110b758d7fbb9b9ef0c58e8d1a7d6a37d7e Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 8 Apr 2019 00:35:53 -0700 Subject: [PATCH 011/113] Fixed source validation --- .bin/Scripts/build-ufd | 39 +++++++++++++++++++++-------------- .bin/Scripts/functions/ufd.py | 16 +++++++++++--- .bin/Scripts/settings/ufd.py | 28 ++++++++++++------------- 3 files changed, 50 insertions(+), 33 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index a5577907..9c048dea 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -7,6 +7,7 @@ import sys # Init sys.path.append(os.path.dirname(os.path.realpath(__file__))) +from collections import OrderedDict from docopt import docopt from functions.ufd import * from settings.ufd import * @@ -18,33 +19,39 @@ set_log_file('Build UFD ({Date-Time}).log'.format(**global_vars)) if __name__ == '__main__': try: args = docopt(DOCSTRING) - sources = () + sources = OrderedDict() # Verify selections ## UFD try: - ufd_dev = get_full_path(args['--ufd-device']) - if not is_block_device(ufd_dev): - print_error('Invalid UFD device: {}'.format(ufd_dev)) - abort() - except Exception: - # TODO Catch FileNotFound exception and abort accordingly - raise + 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, source in UFD_SOURCES: - if args[source]: + for label, data in UFD_SOURCES.items(): + s_path = args[data['Arg']] + if s_path: try: - sources.append((label, get_full_path(source))) - except Exception: - # TODO Catch FileNotFound exception and abort accordingly - raise + 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 # TODO FIXME print_standard('UFD: {}'.format(ufd_dev)) print_standard('Sources:') - for s in sources: - print_standard(' {}: {}'.format(*s)) + for label, s_path in sources.items(): + print_standard(' {:<16} {}'.format(label+':', s_path)) # Double-check if formating device diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index f0ce6ad3..ae1bc37d 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -60,9 +60,19 @@ def find_path(path): return path_obj -def is_valid_main_kit(path_obj): - """Verify PathObj contains the main kit, returns bool.""" - return path_obj.is_dir() and path_obj.joinpath('.bin').exists() +def is_valid_path(path_obj, path_type): + """Verify path_obj is valid by type, returns bool.""" + valid_path = False + if path_type == 'DIR': + valid_path = path_obj.is_dir() + elif path_type == 'KIT': + valid_path = path_obj.is_dir() and path_obj.joinpath('.bin').exists() + elif path_type == 'ISO': + valid_path = path_obj.is_file() and path_obj.suffix.lower() == '.iso' + elif path_type == 'UFD': + valid_path = path_obj.is_block_device() + + return valid_path if __name__ == '__main__': diff --git a/.bin/Scripts/settings/ufd.py b/.bin/Scripts/settings/ufd.py index b7f552eb..50fc6934 100644 --- a/.bin/Scripts/settings/ufd.py +++ b/.bin/Scripts/settings/ufd.py @@ -1,25 +1,26 @@ # Wizard Kit: Settings - UFD +from collections import OrderedDict from settings.main import * # General DOCSTRING = '''WizardKit: Build UFD Usage: - build-ufd [options] --ufd-device PATH --linux-iso PATH - [--linux-minimal-iso PATH] + build-ufd [options] --ufd-device PATH --linux PATH + [--linux-minimal PATH] [--main-kit PATH] - [--winpe-iso PATH] + [--winpe PATH] [--extra-dir PATH] build-ufd (-h | --help) Options: -e PATH, --extra-dir PATH -k PATH, --main-kit PATH - -l PATH, --linux-iso PATH - -m PATH, --linux-minimal-iso PATH + -l PATH, --linux PATH + -m PATH, --linux-minimal PATH -u PATH, --ufd-device PATH - -w PATH, --winpe-iso PATH + -w PATH, --winpe PATH -d --debug Enable debug mode -h --help Show this page @@ -30,14 +31,13 @@ Options: ''' ISO_LABEL = '{}_LINUX'.format(KIT_NAME_SHORT) UFD_LABEL = '{}_UFD'.format(KIT_NAME_SHORT) -UFD_SOURCES = ( - # NOTE: Using tuple of tuples to ensure copy order - ('Linux', '--linux-iso'), - ('Linux (Minimal)', '--linux-minimal-iso'), - ('WinPE', '--winpe-iso'), - ('Main Kit', '--main-kit'), - ('Extras', '--extra-dir'), - ) +UFD_SOURCES = ({ + 'Linux': {'Arg': '--linux', 'Type': 'ISO'}, + 'Linux (Minimal)': {'Arg': '--linux-minimal', 'Type': 'ISO'}, + 'WinPE': {'Arg': '--winpe', 'Type': 'ISO'}, + 'Main Kit': {'Arg': '--main-kit', 'Type': 'KIT'}, + 'Extra Dir': {'Arg': '--extra-dir', 'Type': 'DIR'}, + }) # Definitions: Boot entries ## NOTE: if key path exists uncomment #value# lines From 5fe37b62b288bda89c7084f9fa3f4d85fea15bc6 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 8 Apr 2019 02:58:07 -0700 Subject: [PATCH 012/113] Adjusted source/dest items --- .bin/Scripts/settings/ufd.py | 56 ++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/.bin/Scripts/settings/ufd.py b/.bin/Scripts/settings/ufd.py index 50fc6934..4f99018c 100644 --- a/.bin/Scripts/settings/ufd.py +++ b/.bin/Scripts/settings/ufd.py @@ -49,30 +49,38 @@ BOOT_ENTRIES = { # Definitions: Sources and Destinations ## NOTES: Paths are relative to the root of the ISO/UFD ## Sources use rsync's trailing slash syntax -ITEMS_LINUX_FULL = ( - ('/arch', '/'), - ('/isolinux', '/'), - ('/EFI/boot', '/EFI/'), - ('/EFI/memtest86', '/EFI/'), - ) -ITEMS_LINUX_MINIMAL = ( - ('/arch/boot/archiso.img', '/arch_minimal/'), - ('/arch/boot/vmlinuz', '/arch_minimal/'), - ('/arch/pkglist.x86_64.txt', '/arch_minimal/'), - ('/arch/x86_64', '/arch_minimal/'), - ) -ITEMS_WINPE = ( - ('/bootmgr', '/'), - ('/bootmgr.efi', '/'), - ('/en_us', '/'), - ('/Boot/', '/boot/'), - ('/EFI/Boot/', '/EFI/Microsoft/'), - ('/EFI/Microsoft/', '/EFI/Microsoft/'), - ('/Boot/BCD', '/sources/'), - ('/Boot/boot.sdi', '/sources/'), - ('/bootmgr', '/sources/'), - ('/sources/boot.wim', '/sources/'), - ) +ITEMS = { + 'Extra Dir': ( + ('/', '/'), + ), + 'Linux': ( + ('/arch', '/'), + ('/isolinux', '/'), + ('/EFI/boot', '/EFI/'), + ('/EFI/memtest86', '/EFI/'), + ), + 'Linux (Minimal)': ( + ('/arch/boot/archiso.img', '/arch_minimal/'), + ('/arch/boot/vmlinuz', '/arch_minimal/'), + ('/arch/pkglist.x86_64.txt', '/arch_minimal/'), + ('/arch/x86_64', '/arch_minimal/'), + ), + 'Main Kit': ( + ('/', '/{}/'.format(KIT_NAME_FULL)), + ), + 'WinPE': ( + ('/bootmgr', '/'), + ('/bootmgr.efi', '/'), + ('/en_us', '/'), + ('/Boot/', '/boot/'), + ('/EFI/Boot/', '/EFI/Microsoft/'), + ('/EFI/Microsoft/', '/EFI/Microsoft/'), + ('/Boot/BCD', '/sources/'), + ('/Boot/boot.sdi', '/sources/'), + ('/bootmgr', '/sources/'), + ('/sources/boot.wim', '/sources/'), + ), + } if __name__ == '__main__': print("This file is not meant to be called directly.") From 8cdb834499670a73059008d7f736d48b01291239 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 8 Apr 2019 02:59:03 -0700 Subject: [PATCH 013/113] Initial, incomplete version of recursive_copy() --- .bin/Scripts/functions/ufd.py | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index ae1bc37d..92782d12 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -75,6 +75,46 @@ def is_valid_path(path_obj, path_type): return valid_path +def recursive_copy(source, dest, overwrite=True): + """Copy source to dest recursively. + + NOTE: This uses rsync style source/dest syntax. + If the source has a trailing slash then it's contents are copied, + otherwise the source itself is copied. + + Examples assuming "ExDir/ExFile.txt" exists: + recursive_copy("ExDir", "Dest/") results in "Dest/ExDir/ExFile.txt" + recursive_copy("ExDir/", "Dest/") results in "Dest/ExFile.txt" + + NOTE 2: dest does not use find_path because it might not exist. + """ + copy_contents = source.endswith('/') + source = find_path(source) + dest = pathlib.Path(dest) + + if copy_contents: + for item in os.scandir(source): + recursive_copy(item.path, dest, overwrite=overwrite) + elif source.is_dir(): + if not dest.exists(): + shutil.copytree(source, dest.joinpath('source.name')) + elif not dest.is_dir(): + raise GenericError('Unexpected item in dest: {}'.format(dest)) + else: + # Dest exists and is a dir + for item in os.scandir(source): + recursive_copy( + item.path, + dest.joinpath(source.name), + overwrite=overwrite, + ) + elif source.is_file(): + # TODO FIXME + if dest.exists(): + # TODO FIXME + pass + + if __name__ == '__main__': print("This file is not meant to be called directly.") From b43309be754d5647f5d07acd1038dfdfee17272a Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 8 Apr 2019 15:55:52 -0700 Subject: [PATCH 014/113] Avoid rare crash when scanning CoreStorage volumes --- .bin/Scripts/functions/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bin/Scripts/functions/data.py b/.bin/Scripts/functions/data.py index eb59d030..a8a4deb7 100644 --- a/.bin/Scripts/functions/data.py +++ b/.bin/Scripts/functions/data.py @@ -111,7 +111,7 @@ def find_core_storage_volumes(device_path=None): # Check log for found volumes cs_vols = {} - with open(log_path, 'r') as f: + with open(log_path, 'r', encoding='utf-8', errors='ignore') as f: for line in f.readlines(): r = re.match( r'^.*echo "([^"]+)" . dmsetup create test(\d)$', From 14ebc23b81aebf7d125fdbc534373da624166eef Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 8 Apr 2019 17:39:43 -0700 Subject: [PATCH 015/113] Fix issue #101 --- .linux_items/packages/live_add | 1 + 1 file changed, 1 insertion(+) diff --git a/.linux_items/packages/live_add b/.linux_items/packages/live_add index 668c10c0..92b92a6c 100644 --- a/.linux_items/packages/live_add +++ b/.linux_items/packages/live_add @@ -32,6 +32,7 @@ p7zip progsreiserfs python python-psutil +python-pytz python-requests reiserfsprogs rfkill From 4d9ab2215bed296d54803055cf2d9164e2c4995f Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 8 Apr 2019 18:57:38 -0700 Subject: [PATCH 016/113] Ensure SMART values are shown for some disks * smartctl can return non-zero if there are errors in the SMART logs --- .bin/Scripts/functions/hw_diags.py | 2 +- .bin/Scripts/functions/json.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bin/Scripts/functions/hw_diags.py b/.bin/Scripts/functions/hw_diags.py index f5235111..4b018447 100644 --- a/.bin/Scripts/functions/hw_diags.py +++ b/.bin/Scripts/functions/hw_diags.py @@ -350,7 +350,7 @@ class DiskObj(): def get_smart_details(self): """Get data from smartctl.""" cmd = ['sudo', 'smartctl', '--all', '--json', self.path] - self.smartctl = get_json_from_command(cmd) + self.smartctl = get_json_from_command(cmd, check=False) # Check for attributes if KEY_NVME in self.smartctl: diff --git a/.bin/Scripts/functions/json.py b/.bin/Scripts/functions/json.py index b4527c0d..49481903 100644 --- a/.bin/Scripts/functions/json.py +++ b/.bin/Scripts/functions/json.py @@ -4,7 +4,7 @@ import json from functions.common import * -def get_json_from_command(cmd, ignore_errors=True): +def get_json_from_command(cmd, check=True, ignore_errors=True): """Capture JSON content from cmd output, returns dict. If the data can't be decoded then either an exception is raised @@ -17,7 +17,7 @@ def get_json_from_command(cmd, ignore_errors=True): errors = 'ignore' try: - result = run_program(cmd, encoding='utf-8', errors=errors) + result = run_program(cmd, check=check, encoding='utf-8', errors=errors) json_data = json.loads(result.stdout) except (subprocess.CalledProcessError, json.decoder.JSONDecodeError): if not ignore_errors: From 415f56863d89b9f54946232526a24d536a7be217 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 8 Apr 2019 20:26:41 -0700 Subject: [PATCH 017/113] Finished recursive_copy() --- .bin/Scripts/functions/ufd.py | 49 +++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 92782d12..3671a262 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -90,29 +90,38 @@ def recursive_copy(source, dest, overwrite=True): """ copy_contents = source.endswith('/') source = find_path(source) - dest = pathlib.Path(dest) + dest = pathlib.Path(dest).resolve().joinpath(source.name) + os.makedirs(dest.parent, exist_ok=True) - if copy_contents: - for item in os.scandir(source): - recursive_copy(item.path, dest, overwrite=overwrite) - elif source.is_dir(): - if not dest.exists(): - shutil.copytree(source, dest.joinpath('source.name')) - elif not dest.is_dir(): - raise GenericError('Unexpected item in dest: {}'.format(dest)) - else: - # Dest exists and is a dir + if source.is_dir(): + if copy_contents: + # Trailing slash syntax for item in os.scandir(source): - recursive_copy( - item.path, - dest.joinpath(source.name), - overwrite=overwrite, - ) + recursive_copy(item.path, dest.parent, overwrite=overwrite) + elif not dest.exists(): + # No conflict, copying whole tree (no merging needed) + shutil.copytree(source, dest) + elif not dest.is_dir(): + # Refusing to replace file with dir + raise GenericError('Refusing to replace file with dir: {}'.format(dest)) + else: + # Dest exists and is a dir, merge dirs + for item in os.scandir(source): + recursive_copy(item.path, dest, overwrite=overwrite) elif source.is_file(): - # TODO FIXME - if dest.exists(): - # TODO FIXME - pass + if not dest.exists(): + # No conflict, copying file + shutil.copy2(source, dest) + elif not dest.is_file(): + # Refusing to replace dir with file + raise GenericError('Refusing to replace dir with file: {}'.format(dest)) + elif overwrite: + # Dest file exists, deleting and replacing file + os.remove(dest) + shutil.copy2(source, dest) + else: + # Refusing to delete file when overwrite=False + raise GenericError('Refusing to delete file: {}'.format(dest)) if __name__ == '__main__': From 1a8b6705e01a1c9bb71dd654eff764f7c2bfede9 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 8 Apr 2019 20:57:35 -0700 Subject: [PATCH 018/113] Show selections before starting work --- .bin/Scripts/build-ufd | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 9c048dea..2f7f7451 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -47,6 +47,60 @@ if __name__ == '__main__': 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:') From d33f78960d81d4db3d551f61384fe06a6df2ccf4 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 11 Apr 2019 20:50:21 -0700 Subject: [PATCH 019/113] Reduced imports --- .bin/Scripts/build-ufd | 1 + .bin/Scripts/functions/ufd.py | 16 +++++++++------- .bin/Scripts/settings/ufd.py | 10 +++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 2f7f7451..a2f47a7e 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -9,6 +9,7 @@ import sys 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() diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 3671a262..e8fb164f 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -1,7 +1,9 @@ # Wizard Kit: Functions - UFD +import os +import re +import shutil import pathlib -from functions.common import * def case_insensitive_search(path, item): @@ -27,11 +29,11 @@ def case_insensitive_search(path, item): ) # Done - if real_path: - return real_path - else: + if not real_path: raise FileNotFoundError('{}/{}'.format(path, item)) + return real_path + def find_path(path): """Find path case-insensitively, returns pathlib.Path obj.""" @@ -103,7 +105,7 @@ def recursive_copy(source, dest, overwrite=True): shutil.copytree(source, dest) elif not dest.is_dir(): # Refusing to replace file with dir - raise GenericError('Refusing to replace file with dir: {}'.format(dest)) + raise FileExistsError('Refusing to replace file: {}'.format(dest)) else: # Dest exists and is a dir, merge dirs for item in os.scandir(source): @@ -114,14 +116,14 @@ def recursive_copy(source, dest, overwrite=True): shutil.copy2(source, dest) elif not dest.is_file(): # Refusing to replace dir with file - raise GenericError('Refusing to replace dir with file: {}'.format(dest)) + raise FileExistsError('Refusing to replace dir: {}'.format(dest)) elif overwrite: # Dest file exists, deleting and replacing file os.remove(dest) shutil.copy2(source, dest) else: # Refusing to delete file when overwrite=False - raise GenericError('Refusing to delete file: {}'.format(dest)) + raise FileExistsError('Refusing to delete file: {}'.format(dest)) if __name__ == '__main__': diff --git a/.bin/Scripts/settings/ufd.py b/.bin/Scripts/settings/ufd.py index 4f99018c..13ecd4e9 100644 --- a/.bin/Scripts/settings/ufd.py +++ b/.bin/Scripts/settings/ufd.py @@ -1,7 +1,9 @@ -# Wizard Kit: Settings - UFD +'''Wizard Kit: Settings - UFD''' +# pylint: disable=C0326,E0611 +# vim: sts=2 sw=2 ts=2 from collections import OrderedDict -from settings.main import * +from settings.main import KIT_NAME_FULL,KIT_NAME_SHORT # General DOCSTRING = '''WizardKit: Build UFD @@ -31,7 +33,7 @@ Options: ''' ISO_LABEL = '{}_LINUX'.format(KIT_NAME_SHORT) UFD_LABEL = '{}_UFD'.format(KIT_NAME_SHORT) -UFD_SOURCES = ({ +UFD_SOURCES = OrderedDict({ 'Linux': {'Arg': '--linux', 'Type': 'ISO'}, 'Linux (Minimal)': {'Arg': '--linux-minimal', 'Type': 'ISO'}, 'WinPE': {'Arg': '--winpe', 'Type': 'ISO'}, @@ -84,5 +86,3 @@ ITEMS = { if __name__ == '__main__': print("This file is not meant to be called directly.") - -# vim: sts=2 sw=2 ts=2 From a8afd793e0dc035024be29aee6de6beafc66c3a8 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 11 Apr 2019 20:55:40 -0700 Subject: [PATCH 020/113] Added setup-wifi script * This will replace the connect_to_network() function --- .bin/Scripts/setup-wifi | 72 +++++++++++++++++++++++++++++++++++++ .linux_items/known_networks | 2 ++ 2 files changed, 74 insertions(+) create mode 100644 .bin/Scripts/setup-wifi create mode 100644 .linux_items/known_networks diff --git a/.bin/Scripts/setup-wifi b/.bin/Scripts/setup-wifi new file mode 100644 index 00000000..6047c438 --- /dev/null +++ b/.bin/Scripts/setup-wifi @@ -0,0 +1,72 @@ +#!/bin/env python3 +# +## Convert saved WiFi connections for NetworkManager + +import os +import re +import uuid + +KNOWN_NETWORKS = '/root/known_networks' +TEMPLATE = '''[connection] +id={ssid} +uuid={uuid} +type=wifi +permissions=user:{user}:; + +[wifi] +mac-address-blacklist= +mode=infrastructure +ssid={ssid} + +[wifi-security] +auth-alg=open +key-mgmt=wpa-psk +psk={password} + +[ipv4] +dns-search= +method=auto + +[ipv6] +addr-gen-mode=stable-privacy +dns-search= +method=auto +''' + +def get_user_name(): + """Get real user name, returns str.""" + user = None + if 'SUDO_USER' in os.environ: + user = os.environ.get('SUDO_USER') + else: + user = os.environ.get('USER') + + return user + +if __name__ == '__main__': + known_networks = {} + #try: + with open('/root/known_networks', 'r') as f: + for line in f.readlines(): + r = re.search(r"^'(.*)':\s+'(.*)'", line.strip()) + if r: + known_networks[r.group(1)] = r.group(2) + for ssid, password in known_networks.items(): + out_path = '{}/{}.nmconnection'.format( + '/etc/NetworkManager/system-connections', + password, + ) + if not os.path.exists(out_path): + with open(out_path, 'w') as f: + f.write(TEMPLATE.format( + user=get_user_name(), + ssid=ssid, + password=password, + uuid=uuid.uuid4(), + )) + os.chmod(out_path, 0o600) + #except: + # # Meh + # pass + +# vim: sts=2 sw=2 ts=2 diff --git a/.linux_items/known_networks b/.linux_items/known_networks new file mode 100644 index 00000000..7f110889 --- /dev/null +++ b/.linux_items/known_networks @@ -0,0 +1,2 @@ +#Put WiFi network info here +#'WiFi SSID': 'WiFi Password' From ceb6a9e294376ea884bae1f0d7fb49653973db44 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 11 Apr 2019 20:57:30 -0700 Subject: [PATCH 021/113] Use setup-wifi instead of connect-to-network --- .linux_items/include/airootfs/etc/skel/.update_network | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.linux_items/include/airootfs/etc/skel/.update_network b/.linux_items/include/airootfs/etc/skel/.update_network index e7119a37..f518623e 100755 --- a/.linux_items/include/airootfs/etc/skel/.update_network +++ b/.linux_items/include/airootfs/etc/skel/.update_network @@ -3,9 +3,9 @@ # ## Connect to network and update hostname -# Connect -connect-to-network -sleep 2s +# Add saved networks to NetworkManager +sudo setup-wifi +sudo systemctl restart NetworkManager IP="$(ip a show scope global \ | grep inet \ From c4755124a0b9e9b69349fcc91fa2cac41bc1bbf0 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 11 Apr 2019 20:59:42 -0700 Subject: [PATCH 022/113] Remove more connect-to-network sections --- .bin/Scripts/connect-to-network | 30 ------------------------------ .bin/Scripts/functions/network.py | 21 --------------------- .bin/Scripts/settings/main.py | 3 --- 3 files changed, 54 deletions(-) delete mode 100755 .bin/Scripts/connect-to-network diff --git a/.bin/Scripts/connect-to-network b/.bin/Scripts/connect-to-network deleted file mode 100755 index 02500b37..00000000 --- a/.bin/Scripts/connect-to-network +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/python3 -# -## Wizard Kit: Network connection tool - -import os -import sys - -# Init -sys.path.append(os.path.dirname(os.path.realpath(__file__))) -from functions.network import * -init_global_vars() - -if __name__ == '__main__': - try: - # Prep - clear_screen() - - # Connect - connect_to_network() - - # Done - print_standard('\nDone.') - #pause("Press Enter to exit...") - exit_script() - except SystemExit: - pass - except: - major_exception() - -# vim: sts=2 sw=2 ts=2 diff --git a/.bin/Scripts/functions/network.py b/.bin/Scripts/functions/network.py index 492ba16f..5b5d4f52 100644 --- a/.bin/Scripts/functions/network.py +++ b/.bin/Scripts/functions/network.py @@ -15,27 +15,6 @@ REGEX_VALID_IP = re.compile( re.IGNORECASE) -def connect_to_network(): - """Connect to network if not already connected.""" - net_ifs = psutil.net_if_addrs() - net_ifs = [i[:2] for i in net_ifs.keys()] - - # Bail if currently connected - if is_connected(): - return - - # WiFi - if 'wl' in net_ifs: - cmd = [ - 'nmcli', 'dev', 'wifi', - 'connect', WIFI_SSID, - 'password', WIFI_PASSWORD] - try_and_print( - message = 'Connecting to {}...'.format(WIFI_SSID), - function = run_program, - cmd = cmd) - - def is_connected(): """Check for a valid private IP.""" devs = psutil.net_if_addrs() diff --git a/.bin/Scripts/settings/main.py b/.bin/Scripts/settings/main.py index 99011cf9..9b478feb 100644 --- a/.bin/Scripts/settings/main.py +++ b/.bin/Scripts/settings/main.py @@ -21,9 +21,6 @@ QUICKBOOKS_SERVER_IP='10.0.0.10' # Time Zones LINUX_TIME_ZONE='America/Denver' # See 'timedatectl list-timezones' for valid values WINDOWS_TIME_ZONE='Mountain Standard Time' # See 'tzutil /l' for valid values -# WiFi -WIFI_SSID='SomeWiFi' -WIFI_PASSWORD='Abracadabra' # SERVER VARIABLES ## NOTE: Windows can only use one user per server. This means that if From d113d710a768bcbc3f292f2fb8ef8fd6e6688ab6 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 11 Apr 2019 21:00:32 -0700 Subject: [PATCH 023/113] Avoid dig errors if not connected to a network --- .linux_items/include/airootfs/etc/skel/.update_network | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.linux_items/include/airootfs/etc/skel/.update_network b/.linux_items/include/airootfs/etc/skel/.update_network index f518623e..be604a52 100755 --- a/.linux_items/include/airootfs/etc/skel/.update_network +++ b/.linux_items/include/airootfs/etc/skel/.update_network @@ -11,10 +11,12 @@ IP="$(ip a show scope global \ | grep inet \ | head -1 \ | sed -r 's#.*inet ([0-9]+.[0-9]+.[0-9]+.[0-9]+.)/.*#\1#')" -HOSTNAME="$(dig +noall +answer +short -x "$IP" \ - | grep -v ';' \ - | head -1 \ - | sed 's/\.$//')" +if [[ "${IP:+x}" ]]; then + HOSTNAME="$(dig +noall +answer +short -x "$IP" \ + | grep -v ';' \ + | head -1 \ + | sed 's/\.$//')" +fi # Set hostname if [[ "${HOSTNAME:+x}" ]]; then From c3ebdee5d008bee97f9e171ed871d336d5848a8a Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 11 Apr 2019 21:14:32 -0700 Subject: [PATCH 024/113] Only update hostname when necessary * If $IP was empty then HOSTNAME would remain set to the current HOSTNAME * This allowed the redundant set-hostname call --- .../include/airootfs/etc/skel/.update_network | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.linux_items/include/airootfs/etc/skel/.update_network b/.linux_items/include/airootfs/etc/skel/.update_network index be604a52..0b66717f 100755 --- a/.linux_items/include/airootfs/etc/skel/.update_network +++ b/.linux_items/include/airootfs/etc/skel/.update_network @@ -1,25 +1,23 @@ -## .update_network ## #!/bin/env bash # -## Connect to network and update hostname +## Setup network and update hostname # Add saved networks to NetworkManager sudo setup-wifi sudo systemctl restart NetworkManager +# Set hostname IP="$(ip a show scope global \ | grep inet \ | head -1 \ | sed -r 's#.*inet ([0-9]+.[0-9]+.[0-9]+.[0-9]+.)/.*#\1#')" if [[ "${IP:+x}" ]]; then - HOSTNAME="$(dig +noall +answer +short -x "$IP" \ + NEW_HOSTNAME="$(dig +noall +answer +short -x "$IP" \ | grep -v ';' \ | head -1 \ | sed 's/\.$//')" fi - -# Set hostname -if [[ "${HOSTNAME:+x}" ]]; then - sudo hostnamectl set-hostname "${HOSTNAME}" +if [[ "${NEW_HOSTNAME:+x}" ]]; then + sudo hostnamectl set-hostname "${NEW_HOSTNAME}" fi From 56ca60525731c2e8d6e4d4c9afbc9c0fe802054c Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 11 Apr 2019 21:30:53 -0700 Subject: [PATCH 025/113] Regularly update conky config * This should allow USB adapters to be shown if connected after login --- .../timers.target.wants/update-conky.timer | 1 + .../.config/systemd/user/update-conky.service | 6 ++++ .../.config/systemd/user/update-conky.timer | 10 +++++++ .../etc/skel/{.conkyrc => .conkyrc_base} | 0 .../include_x/airootfs/etc/skel/.update_conky | 30 +++++++++++-------- 5 files changed, 35 insertions(+), 12 deletions(-) create mode 120000 .linux_items/include_x/airootfs/etc/skel/.config/systemd/user/timers.target.wants/update-conky.timer create mode 100644 .linux_items/include_x/airootfs/etc/skel/.config/systemd/user/update-conky.service create mode 100644 .linux_items/include_x/airootfs/etc/skel/.config/systemd/user/update-conky.timer rename .linux_items/include_x/airootfs/etc/skel/{.conkyrc => .conkyrc_base} (100%) diff --git a/.linux_items/include_x/airootfs/etc/skel/.config/systemd/user/timers.target.wants/update-conky.timer b/.linux_items/include_x/airootfs/etc/skel/.config/systemd/user/timers.target.wants/update-conky.timer new file mode 120000 index 00000000..dc3ece34 --- /dev/null +++ b/.linux_items/include_x/airootfs/etc/skel/.config/systemd/user/timers.target.wants/update-conky.timer @@ -0,0 +1 @@ +../update-conky.timer \ No newline at end of file diff --git a/.linux_items/include_x/airootfs/etc/skel/.config/systemd/user/update-conky.service b/.linux_items/include_x/airootfs/etc/skel/.config/systemd/user/update-conky.service new file mode 100644 index 00000000..d2048e93 --- /dev/null +++ b/.linux_items/include_x/airootfs/etc/skel/.config/systemd/user/update-conky.service @@ -0,0 +1,6 @@ +[Unit] +Description=Conky config update service + +[Service] +Type=oneshot +ExecStart=%h/.update_conky diff --git a/.linux_items/include_x/airootfs/etc/skel/.config/systemd/user/update-conky.timer b/.linux_items/include_x/airootfs/etc/skel/.config/systemd/user/update-conky.timer new file mode 100644 index 00000000..c742a10a --- /dev/null +++ b/.linux_items/include_x/airootfs/etc/skel/.config/systemd/user/update-conky.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Conky config update timer + +[Timer] +OnBootSec=5s +OnUnitActiveSec=30s +Unit=update-conky.service + +[Install] +WantedBy=timers.target diff --git a/.linux_items/include_x/airootfs/etc/skel/.conkyrc b/.linux_items/include_x/airootfs/etc/skel/.conkyrc_base similarity index 100% rename from .linux_items/include_x/airootfs/etc/skel/.conkyrc rename to .linux_items/include_x/airootfs/etc/skel/.conkyrc_base diff --git a/.linux_items/include_x/airootfs/etc/skel/.update_conky b/.linux_items/include_x/airootfs/etc/skel/.update_conky index 79801d8b..0e45e13d 100755 --- a/.linux_items/include_x/airootfs/etc/skel/.update_conky +++ b/.linux_items/include_x/airootfs/etc/skel/.update_conky @@ -1,18 +1,24 @@ #!/bin/bash -IF_LIST=($(ip l | egrep '^[0-9]+:\s+(eth|en|wl)' | sed -r 's/^[0-9]+:\s+(\w+):.*/\1/' | sort)) +IF_LIST=($(ip l \ + | egrep '^[0-9]+:\s+(eth|en|wl)' \ + | sed -r 's/^[0-9]+:\s+(\w+):.*/\1/' \ + | sort)) + +# Reset conkyrc to default +rm "${HOME}/.conkyrc" +cp "${HOME}/.conkyrc_base" "${HOME}/.conkyrc" # Add interfaces to conkyrc -if fgrep '#Network' $HOME/.conkyrc; then - for i in "${IF_LIST[@]}"; do - if [[ "${i:0:1}" == "e" ]]; then - sed -i -r "s/#Network/Wired:\${alignr}\${addr $i}\n#Network/" $HOME/.conkyrc - else - sed -i -r "s/#Network/Wireless:\${alignr}\${addr $i}\n#Network/" $HOME/.conkyrc - fi - done +for i in "${IF_LIST[@]}"; do + if [[ "${i:0:1}" == "e" ]]; then + sed -i -r "s/#Network/Wired:\${alignr}\${addr $i}\n#Network/" $HOME/.conkyrc + else + sed -i -r "s/#Network/Wireless:\${alignr}\${addr $i}\n#Network/" $HOME/.conkyrc + fi +done - # Remove '#Network' line to prevent duplicating lines if this script is re-run - sed -i -r "s/#Network//" $HOME/.conkyrc -fi +# Remove '#Network' line to prevent duplicating lines if this script is re-run +sed -i -r "s/#Network//" $HOME/.conkyrc +# vim: sts=2 sw=2 ts=2 From 23add7e27637beca0608618d4718607ac414a7d4 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 11 Apr 2019 21:40:51 -0700 Subject: [PATCH 026/113] Preserve DPI settings when updating conky --- .linux_items/include_x/airootfs/etc/skel/.update_x | 11 +++++++---- .linux_items/include_x/airootfs/etc/skel/.zlogin | 3 --- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.linux_items/include_x/airootfs/etc/skel/.update_x b/.linux_items/include_x/airootfs/etc/skel/.update_x index 650d3162..c1f67cf4 100755 --- a/.linux_items/include_x/airootfs/etc/skel/.update_x +++ b/.linux_items/include_x/airootfs/etc/skel/.update_x @@ -32,10 +32,10 @@ offset_urxvt="24" # Update settings if necessary if [[ "${dpi}" -ge 192 ]]; then # Conky - sed -i 's/minimum_size 180 0/minimum_size 360 0/' "${HOME}/.conkyrc" - sed -i 's/maximum_width 180/maximum_width 360/' "${HOME}/.conkyrc" - sed -i 's/gap_x 20/gap_x 40/' "${HOME}/.conkyrc" - sed -i 's/gap_y 24/gap_y 48/' "${HOME}/.conkyrc" + sed -i 's/minimum_size 180 0/minimum_size 360 0/' "${HOME}/.conkyrc_base" + sed -i 's/maximum_width 180/maximum_width 360/' "${HOME}/.conkyrc_base" + sed -i 's/gap_x 20/gap_x 40/' "${HOME}/.conkyrc_base" + sed -i 's/gap_y 24/gap_y 48/' "${HOME}/.conkyrc_base" # Fonts sed -i 's/!Xft.dpi: 192/Xft.dpi: 192/' "${HOME}/.Xresources" @@ -67,6 +67,9 @@ fi urxvt_geometry="${width_urxvt}x${height_urxvt}+${offset_urxvt}+${offset_urxvt}" sed -i -r "s/${REGEX_URXVT}/\1${urxvt_geometry}/" "${HOME}/.Xresources" +# Update conky +$HOME/.update_conky + # Update X xset s off xset -dpms diff --git a/.linux_items/include_x/airootfs/etc/skel/.zlogin b/.linux_items/include_x/airootfs/etc/skel/.zlogin index 04b1316e..8901bb31 100644 --- a/.linux_items/include_x/airootfs/etc/skel/.zlogin +++ b/.linux_items/include_x/airootfs/etc/skel/.zlogin @@ -9,9 +9,6 @@ if [ "$(fgconsole 2>/dev/null)" -eq "1" ]; then sed -i -r 's/openbox-session/i3/' ~/.xinitrc fi - # Update Conky - $HOME/.update_conky - # Start X or HW-diags if ! fgrep -q "nox" /proc/cmdline; then # Kill Xorg after 30 seconds if it doesn't fully initialize From 0883b099fd7c83aa56d11553940bec15c2bbc6a7 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 11 Apr 2019 22:24:25 -0700 Subject: [PATCH 027/113] Skip safety check if upgrading --- .bin/Scripts/build-ufd | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index a2f47a7e..05458c6b 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -82,32 +82,29 @@ if __name__ == '__main__': 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']: + if args['--update']: + print_warning('Updating kit in-place') + elif args['--use-mbr']: 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() + if not args['--update']: + 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 From b2528b90f8abc4a35672ff707c4e561e4d925c55 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 11 Apr 2019 22:25:13 -0700 Subject: [PATCH 028/113] Fix docopt handling * Show usage if invalid arguments are used --- .bin/Scripts/build-ufd | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 05458c6b..726efa4d 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -20,6 +20,13 @@ set_log_file('Build UFD ({Date-Time}).log'.format(**global_vars)) if __name__ == '__main__': try: args = docopt(DOCSTRING) + except SystemExit as err: + # Catch docopt exits + print(err) + exit_script() + except: + major_exception() + try: sources = OrderedDict() # Verify selections From 5a1f7b1829a20f8e46fd669341064cb9108ce916 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 14 Apr 2019 15:58:09 -0700 Subject: [PATCH 029/113] Silence build-ufd init --- .bin/Scripts/build-ufd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 726efa4d..c4fcb26a 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -12,7 +12,7 @@ from docopt import docopt from functions.common import * from functions.ufd import * from settings.ufd import * -init_global_vars() +init_global_vars(silent=True) set_log_file('Build UFD ({Date-Time}).log'.format(**global_vars)) From d62a647fa9cfe90dc14aaa9f9d609c72cd1bf8b8 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 14 Apr 2019 16:46:50 -0700 Subject: [PATCH 030/113] Avoid setting LogDir to /root/Logs under su/sudo --- .bin/Scripts/build-ufd | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index c4fcb26a..d83eddf2 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -13,11 +13,36 @@ from functions.common import * from functions.ufd import * from settings.ufd import * init_global_vars(silent=True) -set_log_file('Build UFD ({Date-Time}).log'.format(**global_vars)) + +# Functions +def get_user_home(user): + """Get path to user's home dir, returns str.""" + home_dir = None + cmd = ['getent', 'passwd', user] + result = run_program(cmd, encoding='utf-8', errors='ignore', check=False) + try: + home_dir = result.stdout.split(':')[5] + except Exception: + # Just use HOME from ENV (or '/root' if that fails) + home_dir = os.environ.get('HOME', '/root') + + return home_dir + + +def get_user_name(): + """Get real user name, returns str.""" + user = None + if 'SUDO_USER' in os.environ: + user = os.environ.get('SUDO_USER') + else: + user = os.environ.get('USER') + + return user # Main section if __name__ == '__main__': + # Docopt try: args = docopt(DOCSTRING) except SystemExit as err: @@ -26,10 +51,15 @@ if __name__ == '__main__': exit_script() except: major_exception() + try: - sources = OrderedDict() + # Set log + global_vars['LogDir'] = '{}/Logs'.format( + get_user_home(get_user_name())) + set_log_file('Build UFD ({Date-Time}).log'.format(**global_vars)) # Verify selections + sources = OrderedDict() ## UFD try: ufd_dev = find_path(args['--ufd-device']) From fde9be6b3ff16cdd9c709ab5929f1cc3f6e3c928 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 14 Apr 2019 16:48:34 -0700 Subject: [PATCH 031/113] Updated get_user_name() --- .bin/Scripts/build-ufd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index d83eddf2..610a1e66 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -33,9 +33,9 @@ def get_user_name(): """Get real user name, returns str.""" user = None if 'SUDO_USER' in os.environ: - user = os.environ.get('SUDO_USER') + user = os.environ.get('SUDO_USER', 'Unknown') else: - user = os.environ.get('USER') + user = os.environ.get('USER', 'Unknown') return user From 6734460d42d553551b2986c159859255e243509c Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 14 Apr 2019 17:01:53 -0700 Subject: [PATCH 032/113] Added option to skip pause in abort() * Also use exit_script(1) --- .bin/Scripts/build-ufd | 12 ++++++------ .bin/Scripts/functions/common.py | 9 +++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 610a1e66..5542a0ac 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -66,10 +66,10 @@ if __name__ == '__main__': except FileNotFoundError: print_error('ERROR: UFD device not found: {}'.format( args['--ufd-device'])) - abort() + abort(False) if not is_valid_path(ufd_dev, 'UFD'): print_error('ERROR: Invalid UFD device: {}'.format(ufd_dev)) - abort() + abort(False) ## Sources for label, data in UFD_SOURCES.items(): s_path = args[data['Arg']] @@ -78,10 +78,10 @@ if __name__ == '__main__': s_path_obj = find_path(s_path) except FileNotFoundError: print_error('ERROR: {} not found: {}'.format(label, s_path)) - abort() + abort(False) if not is_valid_path(s_path_obj, data['Type']): print_error('ERROR: Invalid {} source: {}'.format(label, s_path)) - abort() + abort(False) sources[label] = s_path_obj # Show selections @@ -125,7 +125,7 @@ if __name__ == '__main__': print_warning('Formatting using legacy MBR') print_standard(' ') if not ask('Is the above information correct?'): - abort() + abort(False) ## Safety check if not args['--update']: print_standard(' ') @@ -136,7 +136,7 @@ if __name__ == '__main__': 'This is irreversible and will lead to {RED}DATA LOSS.{CLEAR}'.format( **COLORS)) if not ask('Asking again to confirm, is this correct?'): - abort() + abort(False) print_standard(' ') print_success("It's go-time!") diff --git a/.bin/Scripts/functions/common.py b/.bin/Scripts/functions/common.py index b6008d27..fe75f1ef 100644 --- a/.bin/Scripts/functions/common.py +++ b/.bin/Scripts/functions/common.py @@ -90,12 +90,13 @@ class SecureBootUnknownError(Exception): # General functions -def abort(): +def abort(show_prompt=True): """Abort script.""" print_warning('Aborted.') - sleep(1) - pause(prompt='Press Enter to exit... ') - exit_script() + if show_prompt: + sleep(timeout) + pause(prompt='Press Enter to exit... ') + exit_script(1) def ask(prompt='Kotaero!'): From cc1a318e3dece2dab58c85dcdd5ec7387da86ecc Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 14 Apr 2019 17:03:04 -0700 Subject: [PATCH 033/113] Abort if not running as root --- .bin/Scripts/build-ufd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 5542a0ac..38b6f8d6 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -42,6 +42,11 @@ def get_user_name(): # Main section if __name__ == '__main__': + # Check if running as root + if os.geteuid() != 0: + print_error('ERROR: This script is meant to be run as root.') + abort(False) + # Docopt try: args = docopt(DOCSTRING) From cf1d11eb789280ddf9eb44aac2cb37363a8460be Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 14 Apr 2019 17:16:13 -0700 Subject: [PATCH 034/113] Always show header --- .bin/Scripts/build-ufd | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 38b6f8d6..592a6143 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -42,6 +42,19 @@ def get_user_name(): # Main section if __name__ == '__main__': + # 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: + major_exception() + + # Header + print_success(KIT_NAME_FULL) + print_standard('UFD Build Tool') + print_standard(' ') + # Check if running as root if os.geteuid() != 0: print_error('ERROR: This script is meant to be run as root.') @@ -58,11 +71,6 @@ if __name__ == '__main__': major_exception() try: - # Set log - global_vars['LogDir'] = '{}/Logs'.format( - get_user_home(get_user_name())) - set_log_file('Build UFD ({Date-Time}).log'.format(**global_vars)) - # Verify selections sources = OrderedDict() ## UFD @@ -90,11 +98,6 @@ if __name__ == '__main__': 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(): @@ -145,7 +148,7 @@ if __name__ == '__main__': print_standard(' ') print_success("It's go-time!") - exit_script(1) + exit_script() # Double-check if formating device From 1b312658e949a93cfafbdc9dd4b3772671678af6 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 14 Apr 2019 17:17:11 -0700 Subject: [PATCH 035/113] Fixed return code handling --- .bin/Scripts/build-ufd | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 592a6143..3b688e17 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -42,6 +42,7 @@ def get_user_name(): # Main section if __name__ == '__main__': + return_code = 0 # Set log try: global_vars['LogDir'] = '{}/Logs'.format( @@ -169,10 +170,11 @@ if __name__ == '__main__': print_standard('\nDone.') pause('Press Enter to exit...') exit_script() - except SystemExit: - pass + except SystemExit as e: + return_code = e.code except: major_exception() + exit_script(return_code) # vim: sts=2 sw=2 ts=2 From 0e6be3ad08620de0042beffa8ca3694ab63b9534 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 14 Apr 2019 17:57:46 -0700 Subject: [PATCH 036/113] Better SystemExit handling --- .bin/Scripts/build-ufd | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 3b688e17..cfb19124 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -42,7 +42,6 @@ def get_user_name(): # Main section if __name__ == '__main__': - return_code = 0 # Set log try: global_vars['LogDir'] = '{}/Logs'.format( @@ -170,11 +169,9 @@ if __name__ == '__main__': print_standard('\nDone.') pause('Press Enter to exit...') exit_script() - except SystemExit as e: - return_code = e.code + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() - exit_script(return_code) - # vim: sts=2 sw=2 ts=2 From 164fd4c646d6df829ec4c646cdd367bbea7f3ecc Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 14 Apr 2019 18:09:36 -0700 Subject: [PATCH 037/113] Fixed SystemExit calls from docopt --- .bin/Scripts/build-ufd | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index cfb19124..15e4e680 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -63,10 +63,9 @@ if __name__ == '__main__': # Docopt try: args = docopt(DOCSTRING) - except SystemExit as err: + except SystemExit as sys_exit: # Catch docopt exits - print(err) - exit_script() + exit_script(sys_exit.code) except: major_exception() From 3310e3d2537f49c9d6d655f64cc17a1300e240c9 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 14 Apr 2019 18:43:08 -0700 Subject: [PATCH 038/113] Moved most logic to functions.ufd --- .bin/Scripts/build-ufd | 108 ++-------------------------- .bin/Scripts/functions/ufd.py | 131 ++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 102 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 15e4e680..887932a7 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -7,39 +7,12 @@ 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(silent=True) -# Functions -def get_user_home(user): - """Get path to user's home dir, returns str.""" - home_dir = None - cmd = ['getent', 'passwd', user] - result = run_program(cmd, encoding='utf-8', errors='ignore', check=False) - try: - home_dir = result.stdout.split(':')[5] - except Exception: - # Just use HOME from ENV (or '/root' if that fails) - home_dir = os.environ.get('HOME', '/root') - - return home_dir - - -def get_user_name(): - """Get real user name, returns str.""" - user = None - if 'SUDO_USER' in os.environ: - user = os.environ.get('SUDO_USER', 'Unknown') - else: - user = os.environ.get('USER', 'Unknown') - - return user - - # Main section if __name__ == '__main__': # Set log @@ -56,7 +29,7 @@ if __name__ == '__main__': print_standard(' ') # Check if running as root - if os.geteuid() != 0: + if not running_as_root(): print_error('ERROR: This script is meant to be run as root.') abort(False) @@ -71,81 +44,12 @@ if __name__ == '__main__': try: # Verify selections - sources = OrderedDict() - ## UFD - try: - ufd_dev = find_path(args['--ufd-device']) - except FileNotFoundError: - print_error('ERROR: UFD device not found: {}'.format( - args['--ufd-device'])) - abort(False) - if not is_valid_path(ufd_dev, 'UFD'): - print_error('ERROR: Invalid UFD device: {}'.format(ufd_dev)) - abort(False) - ## 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(False) - if not is_valid_path(s_path_obj, data['Type']): - print_error('ERROR: Invalid {} source: {}'.format(label, s_path)) - abort(False) - sources[label] = s_path_obj + ufd_dev = verify_ufd(args['--ufd-device']) + sources = verify_sources(args, UFD_SOURCES) + show_selections(args, sources, ufd_dev, UFD_SOURCES) + confirm_selections(args) - # Show selections - ## 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['--update']: - print_warning('Updating kit in-place') - elif args['--use-mbr']: - print_warning('Formatting using legacy MBR') - print_standard(' ') - if not ask('Is the above information correct?'): - abort(False) - ## Safety check - if not args['--update']: - 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(False) - - print_standard(' ') + # TODO: DELETEME print_success("It's go-time!") exit_script() diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index e8fb164f..7c7a9b48 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -4,6 +4,8 @@ import os import re import shutil import pathlib +from collections import OrderedDict +from functions.common import * def case_insensitive_search(path, item): @@ -35,6 +37,25 @@ def case_insensitive_search(path, item): return real_path +def confirm_selections(args): + """Ask tech to confirm selections, twice if necessary.""" + if not ask('Is the above information correct?'): + abort(False) + ## Safety check + if not args['--update']: + 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(False) + + print_standard(' ') + + def find_path(path): """Find path case-insensitively, returns pathlib.Path obj.""" path_obj = pathlib.Path(path).resolve() @@ -62,6 +83,31 @@ def find_path(path): return path_obj +def get_user_home(user): + """Get path to user's home dir, returns str.""" + home_dir = None + cmd = ['getent', 'passwd', user] + result = run_program(cmd, encoding='utf-8', errors='ignore', check=False) + try: + home_dir = result.stdout.split(':')[5] + except Exception: + # Just use HOME from ENV (or '/root' if that fails) + home_dir = os.environ.get('HOME', '/root') + + return home_dir + + +def get_user_name(): + """Get real user name, returns str.""" + user = None + if 'SUDO_USER' in os.environ: + user = os.environ.get('SUDO_USER', 'Unknown') + else: + user = os.environ.get('USER', 'Unknown') + + return user + + def is_valid_path(path_obj, path_type): """Verify path_obj is valid by type, returns bool.""" valid_path = False @@ -126,6 +172,91 @@ def recursive_copy(source, dest, overwrite=True): raise FileExistsError('Refusing to delete file: {}'.format(dest)) +def running_as_root(): + """Check if running with effective UID of 0, returns bool.""" + return os.geteuid() == 0 + + +def show_selections(args, sources, ufd_dev, ufd_sources): + """Show selections including non-specified options.""" + + # 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, + )) + print_standard(' ') + + # Destination + 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) + + # Notes + if args['--update']: + print_warning('Updating kit in-place') + elif args['--use-mbr']: + print_warning('Formatting using legacy MBR') + print_standard(' ') + + +def verify_sources(args, ufd_sources): + """Check all sources and abort if necessary, returns dict.""" + sources = OrderedDict() + + 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(False) + if not is_valid_path(s_path_obj, data['Type']): + print_error('ERROR: Invalid {} source: {}'.format(label, s_path)) + abort(False) + sources[label] = s_path_obj + + return sources + + +def verify_ufd(dev_path): + """Check that dev_path is a valid UFD, returns pathlib.Path obj.""" + ufd_dev = None + + try: + ufd_dev = find_path(dev_path) + except FileNotFoundError: + print_error('ERROR: UFD device not found: {}'.format( + args['--ufd-device'])) + abort(False) + + if not is_valid_path(ufd_dev, 'UFD'): + print_error('ERROR: Invalid UFD device: {}'.format(ufd_dev)) + abort(False) + + return ufd_dev + + if __name__ == '__main__': print("This file is not meant to be called directly.") From 72cc33cb7ed75a61bdb27b05d5cce271d82863ed Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 14 Apr 2019 18:48:54 -0700 Subject: [PATCH 039/113] Only show destination device, not all devices --- .bin/Scripts/functions/ufd.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 7c7a9b48..7753d88a 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -200,12 +200,14 @@ def show_selections(args, sources, ufd_dev, ufd_sources): cmd = [ 'lsblk', '--nodeps', '--noheadings', '--output', 'NAME,TRAN,SIZE,VENDOR,MODEL,SERIAL', + ufd_dev, ] 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', + ufd_dev, ] result = run_program(cmd, check=False, encoding='utf-8', errors='ignore') for line in result.stdout.splitlines()[1:]: @@ -246,8 +248,7 @@ def verify_ufd(dev_path): try: ufd_dev = find_path(dev_path) except FileNotFoundError: - print_error('ERROR: UFD device not found: {}'.format( - args['--ufd-device'])) + print_error('ERROR: UFD device not found: {}'.format(dev_path)) abort(False) if not is_valid_path(ufd_dev, 'UFD'): From e098d40c2fb1d06bd9712ca317e756ac0d72f061 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 14 Apr 2019 18:49:32 -0700 Subject: [PATCH 040/113] Added pylint exceptions --- .bin/Scripts/build-ufd | 13 +++++++------ .bin/Scripts/functions/ufd.py | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 887932a7..72967920 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -1,6 +1,8 @@ #!/bin/env python3 # -## Wizard Kit: UFD build tool +# pylint: disable=no-name-in-module,wildcard-import +# vim: sts=2 sw=2 ts=2 +"""Wizard Kit: UFD build tool""" import os import sys @@ -15,12 +17,13 @@ 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: + except: # pylint: disable=bare-except major_exception() # Header @@ -39,7 +42,7 @@ if __name__ == '__main__': except SystemExit as sys_exit: # Catch docopt exits exit_script(sys_exit.code) - except: + except: # pylint: disable=bare-except major_exception() try: @@ -74,7 +77,5 @@ if __name__ == '__main__': exit_script() except SystemExit as sys_exit: exit_script(sys_exit.code) - except: + except: # pylint: disable=bare-except major_exception() - -# vim: sts=2 sw=2 ts=2 diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 7753d88a..1d9d9970 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -1,4 +1,6 @@ -# Wizard Kit: Functions - UFD +"""Wizard Kit: Functions - UFD""" +# pylint: disable=broad-except,wildcard-import +# vim: sts=2 sw=2 ts=2 import os import re @@ -260,5 +262,3 @@ def verify_ufd(dev_path): if __name__ == '__main__': print("This file is not meant to be called directly.") - -# vim: sts=2 sw=2 ts=2 From 2230ea1eeab4634155b6dde5983c0e6e49a69ceb Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 20:30:39 -0700 Subject: [PATCH 041/113] Added prep_device() * Skipped if --update is used --- .bin/Scripts/build-ufd | 4 +-- .bin/Scripts/functions/ufd.py | 53 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 72967920..1b29b91b 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -56,9 +56,9 @@ if __name__ == '__main__': print_success("It's go-time!") exit_script() - # Double-check if formating device - # Format and partition device + if not args['--update']: + prep_device(ufd_dev, UFD_LABEL, use_mbr=args['--use-mbr']) # Copy sources diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 1d9d9970..902d3b14 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -125,6 +125,59 @@ def is_valid_path(path_obj, path_type): return valid_path +def prep_device(dev_path, label, use_mbr=False): + """Format device in preparation for applying the WizardKit components + + This is done is four steps: + 1. Zero-out first 64MB (this deletes the partition table and/or bootloader) + 2. Create a new partition table (GPT by default, optionally MBR) + 3. Set boot flag + 4. Format partition (FAT32, 4K aligned) + """ + # Zero-out first 64MB + cmd = 'dd bs=4M count=16 if=/dev/zero of={}'.format(dev_path).split() + try_and_print( + message='Zeroing first 64MB...', + function=run_program, + cmd=cmd, + ) + + # Create partition table + cmd = 'parted {} --script -- mklabel {} primary fat32 4MiB {}'.format( + dev_path, + 'msdos' if use_mbr else 'gpt', + '-1s' if use_mbr else '-4MiB', + ).split() + try_and_print( + message='Creating partition table...', + function=run_program, + cmd=cmd, + ) + + # Set boot flag + cmd = 'parted {} set 1 {} on'.format( + dev_path, + 'boot' if use_mbr else 'legacy_boot', + ).split() + try_and_print( + message='Setting boot flag...', + function=run_program, + cmd=cmd, + ) + + # Format partition + cmd = [ + 'mkfs.vfat', '-F', '32', + '-n', label, + '{}1'.format(dev_path), + ] + try_and_print( + message='Formatting partition...', + function=run_program, + cmd=cmd, + ) + + def recursive_copy(source, dest, overwrite=True): """Copy source to dest recursively. From c8944e5a14b6beb87aa722b1a30a05867ff2f2af Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 21:27:27 -0700 Subject: [PATCH 042/113] Fixed prep_device() --- .bin/Scripts/build-ufd | 8 ++++---- .bin/Scripts/functions/ufd.py | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 1b29b91b..3c0abbe6 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -52,14 +52,14 @@ if __name__ == '__main__': show_selections(args, sources, ufd_dev, UFD_SOURCES) confirm_selections(args) - # TODO: DELETEME - print_success("It's go-time!") - exit_script() - # Format and partition device if not args['--update']: prep_device(ufd_dev, UFD_LABEL, use_mbr=args['--use-mbr']) + # TODO: DELETEME + print_success("It's go-time!") + exit_script() + # Copy sources # Update boot entries diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 902d3b14..34940e1f 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -143,7 +143,7 @@ def prep_device(dev_path, label, use_mbr=False): ) # Create partition table - cmd = 'parted {} --script -- mklabel {} primary fat32 4MiB {}'.format( + cmd = 'parted {} --script -- mklabel {} mkpart primary fat32 4MiB {}'.format( dev_path, 'msdos' if use_mbr else 'gpt', '-1s' if use_mbr else '-4MiB', @@ -165,11 +165,23 @@ def prep_device(dev_path, label, use_mbr=False): cmd=cmd, ) + # Find partition + cmd = [ + 'lsblk', + '--list', + '--noheadings', + '--output', 'name', + '--paths', + dev_path, + ] + result = run_program(cmd, encoding='utf-8', errors='ignore') + part_path = result.stdout.splitlines()[-1].strip() + # Format partition cmd = [ 'mkfs.vfat', '-F', '32', '-n', label, - '{}1'.format(dev_path), + part_path, ] try_and_print( message='Formatting partition...', From af757c5582514c5ee02a7395b9ce14a598b4cfff Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 21:28:53 -0700 Subject: [PATCH 043/113] Show full device paths --- .bin/Scripts/functions/ufd.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 34940e1f..93e0644c 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -265,14 +265,14 @@ def show_selections(args, sources, ufd_dev, ufd_sources): # Destination print_info('Destination') cmd = [ - 'lsblk', '--nodeps', '--noheadings', - '--output', 'NAME,TRAN,SIZE,VENDOR,MODEL,SERIAL', + 'lsblk', '--nodeps', '--noheadings', '--paths', + '--output', 'NAME,FSTYPE,TRAN,SIZE,VENDOR,MODEL,SERIAL', ufd_dev, ] result = run_program(cmd, check=False, encoding='utf-8', errors='ignore') print_standard(result.stdout.strip()) cmd = [ - 'lsblk', '--noheadings', + 'lsblk', '--noheadings', '--paths', '--output', 'NAME,SIZE,FSTYPE,LABEL,MOUNTPOINT', ufd_dev, ] From 807c94e2cef8d3207b57571183c49f2d5b91e433 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 21:29:10 -0700 Subject: [PATCH 044/113] Add argument for Linux (dGPU) --- .bin/Scripts/settings/ufd.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bin/Scripts/settings/ufd.py b/.bin/Scripts/settings/ufd.py index 13ecd4e9..c754d2b9 100644 --- a/.bin/Scripts/settings/ufd.py +++ b/.bin/Scripts/settings/ufd.py @@ -18,6 +18,7 @@ Usage: Options: -e PATH, --extra-dir PATH + -g PATH, --linux-dgpu PATH -k PATH, --main-kit PATH -l PATH, --linux PATH -m PATH, --linux-minimal PATH @@ -35,6 +36,7 @@ ISO_LABEL = '{}_LINUX'.format(KIT_NAME_SHORT) UFD_LABEL = '{}_UFD'.format(KIT_NAME_SHORT) UFD_SOURCES = OrderedDict({ 'Linux': {'Arg': '--linux', 'Type': 'ISO'}, + 'Linux (dGPU)': {'Arg': '--linux-dgpu', 'Type': 'ISO'}, 'Linux (Minimal)': {'Arg': '--linux-minimal', 'Type': 'ISO'}, 'WinPE': {'Arg': '--winpe', 'Type': 'ISO'}, 'Main Kit': {'Arg': '--main-kit', 'Type': 'KIT'}, From 996b01bb340aafcc91684d7ea577c6d98935c175 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 21:30:44 -0700 Subject: [PATCH 045/113] Add Linux dGPU items --- .bin/Scripts/settings/ufd.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.bin/Scripts/settings/ufd.py b/.bin/Scripts/settings/ufd.py index c754d2b9..2aa9b5e2 100644 --- a/.bin/Scripts/settings/ufd.py +++ b/.bin/Scripts/settings/ufd.py @@ -63,6 +63,12 @@ ITEMS = { ('/EFI/boot', '/EFI/'), ('/EFI/memtest86', '/EFI/'), ), + 'Linux (dGPU)': ( + ('/arch/boot/archiso.img', '/dgpu/'), + ('/arch/boot/vmlinuz', '/dgpu/'), + ('/arch/pkglist.x86_64.txt', '/dgpu/'), + ('/arch/x86_64', '/dgpu/'), + ), 'Linux (Minimal)': ( ('/arch/boot/archiso.img', '/arch_minimal/'), ('/arch/boot/vmlinuz', '/arch_minimal/'), From d769b1ad4ee79c9894cc20985b413cf4dbe05004 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 22:05:48 -0700 Subject: [PATCH 046/113] Set overwrite=False by default --- .bin/Scripts/functions/ufd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 93e0644c..06bb3e45 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -190,7 +190,7 @@ def prep_device(dev_path, label, use_mbr=False): ) -def recursive_copy(source, dest, overwrite=True): +def recursive_copy(source, dest, overwrite=False): """Copy source to dest recursively. NOTE: This uses rsync style source/dest syntax. From 7ee04060d80d7176cae7a66e08f77ce4821d9481 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 22:37:58 -0700 Subject: [PATCH 047/113] Added dGPU to BOOT_ENTRIES --- .bin/Scripts/settings/ufd.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.bin/Scripts/settings/ufd.py b/.bin/Scripts/settings/ufd.py index 2aa9b5e2..b09f84fe 100644 --- a/.bin/Scripts/settings/ufd.py +++ b/.bin/Scripts/settings/ufd.py @@ -46,7 +46,8 @@ UFD_SOURCES = OrderedDict({ # Definitions: Boot entries ## NOTE: if key path exists uncomment #value# lines BOOT_ENTRIES = { - 'arch_minimal': 'MINIMAL', + 'arch_minimal': 'MINIMAL', + 'dgpu': 'DGPU', 'sources/boot.wim': 'WINPE', } From 26aca0df9f87d8d5a6ffbb23e69cb661c85dfccb Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 22:38:54 -0700 Subject: [PATCH 048/113] Added mount and unmount sections --- .bin/Scripts/build-ufd | 12 +++++++----- .bin/Scripts/functions/ufd.py | 13 +++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 3c0abbe6..7571eae3 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -56,9 +56,13 @@ if __name__ == '__main__': if not args['--update']: prep_device(ufd_dev, UFD_LABEL, use_mbr=args['--use-mbr']) - # TODO: DELETEME - print_success("It's go-time!") - exit_script() + # Mount UFD + try_and_print( + message='Mounting UFD...', + function=mount, + mount_source=ufd_dev, + mount_point='/mnt/UFD', + ) # Copy sources @@ -68,8 +72,6 @@ if __name__ == '__main__': # Hide items - # Unmount sources - # Done if not args['--force']: print_standard('\nDone.') diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 06bb3e45..96ce2d0a 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -125,6 +125,19 @@ def is_valid_path(path_obj, path_type): return valid_path +def mount(mount_source, mount_point): + """Mount mount_source on mount_point.""" + os.makedirs(mount_point, exist_ok=True) + cmd = ['mount', mount_source, mount_point] + run_program(cmd) + + +def unmount(mount_point): + """Unmount mount_point.""" + cmd = ['umount', mount_point] + run_program(cmd) + + def prep_device(dev_path, label, use_mbr=False): """Format device in preparation for applying the WizardKit components From fc9de6126996556c4cf672e29f0d1905466802dd Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 22:40:20 -0700 Subject: [PATCH 049/113] Added copy_source() --- .bin/Scripts/build-ufd | 8 ++++++++ .bin/Scripts/functions/ufd.py | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 7571eae3..fbe1bdff 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -65,6 +65,14 @@ if __name__ == '__main__': ) # Copy sources + for s_label, s_path in sources.items(): + try_and_print( + message='Copying {} files...'.format(s_label), + function=copy_source, + source=s_path, + items=ITEMS[s_label], + overwrite=True, + ) # Update boot entries diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 96ce2d0a..344c273d 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -58,6 +58,17 @@ def confirm_selections(args): print_standard(' ') +def copy_source(source, items, overwrite=False): + """Mount source and copy items to /mnt/UFD.""" + os.makedirs('/mnt/Source', exist_ok=True) + mount(source, '/mnt/Source') + for i_source, i_dest in items: + i_source = '/mnt/Source{}'.format(i_source) + i_dest = '/mnt/UFD{}'.format(i_dest) + recursive_copy(i_source, i_dest, overwrite=overwrite) + unmount('/mnt/Source') + + def find_path(path): """Find path case-insensitively, returns pathlib.Path obj.""" path_obj = pathlib.Path(path).resolve() From 95f4877862e8edcc63895820bfed4a9992dccb2f Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 23:04:37 -0700 Subject: [PATCH 050/113] Reordered functions --- .bin/Scripts/functions/ufd.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 344c273d..9a17ea64 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -60,7 +60,6 @@ def confirm_selections(args): def copy_source(source, items, overwrite=False): """Mount source and copy items to /mnt/UFD.""" - os.makedirs('/mnt/Source', exist_ok=True) mount(source, '/mnt/Source') for i_source, i_dest in items: i_source = '/mnt/Source{}'.format(i_source) @@ -143,12 +142,6 @@ def mount(mount_source, mount_point): run_program(cmd) -def unmount(mount_point): - """Unmount mount_point.""" - cmd = ['umount', mount_point] - run_program(cmd) - - def prep_device(dev_path, label, use_mbr=False): """Format device in preparation for applying the WizardKit components @@ -312,6 +305,12 @@ def show_selections(args, sources, ufd_dev, ufd_sources): print_standard(' ') +def unmount(mount_point): + """Unmount mount_point.""" + cmd = ['umount', mount_point] + run_program(cmd) + + def verify_sources(args, ufd_sources): """Check all sources and abort if necessary, returns dict.""" sources = OrderedDict() From c16e97e49a4f72dffcec2138137abbe38deaf3fa Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 23:07:33 -0700 Subject: [PATCH 051/113] Added boot entry sections --- .bin/Scripts/build-ufd | 6 ++++++ .bin/Scripts/functions/ufd.py | 29 +++++++++++++++++++++++++++++ .bin/Scripts/settings/ufd.py | 13 +++++++++---- 3 files changed, 44 insertions(+), 4 deletions(-) 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 From c66b2facbf37bafc00f801f2c7e93133f70d0a1b Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 23:12:27 -0700 Subject: [PATCH 052/113] Skip confirm_selections if --force is used --- .bin/Scripts/build-ufd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index e21d876c..4ad726e1 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -50,7 +50,8 @@ if __name__ == '__main__': ufd_dev = verify_ufd(args['--ufd-device']) sources = verify_sources(args, UFD_SOURCES) show_selections(args, sources, ufd_dev, UFD_SOURCES) - confirm_selections(args) + if not args['--force']: + confirm_selections(args) # Format and partition device if not args['--update']: From 4115f3cfe178648b5e4f637d204e04c50d4309b2 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 23:16:57 -0700 Subject: [PATCH 053/113] Removed unused args --- .bin/Scripts/settings/ufd.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.bin/Scripts/settings/ufd.py b/.bin/Scripts/settings/ufd.py index dc7693c4..5123a8a1 100644 --- a/.bin/Scripts/settings/ufd.py +++ b/.bin/Scripts/settings/ufd.py @@ -17,17 +17,15 @@ Usage: build-ufd (-h | --help) Options: + -d PATH, --linux-dgpu PATH -e PATH, --extra-dir PATH - -g PATH, --linux-dgpu PATH -k PATH, --main-kit PATH -l PATH, --linux PATH -m PATH, --linux-minimal PATH -u PATH, --ufd-device PATH -w PATH, --winpe PATH - -d --debug Enable debug mode -h --help Show this page - -v --verbose Enable verbose mode -M --use-mbr Use real MBR instead of GPT w/ Protective MBR -F --force Bypass all confirmation messages. USE WITH EXTREME CAUTION! -U --update Don't format device, just update From 89ac824d828a7adf7f4c90bda0d10c27201cf795 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 23:44:42 -0700 Subject: [PATCH 054/113] Expanded boot entries sections * Update Arch labels from ISO_LABEL to UFD_LABEL * Added Linux (Minimal) to syslinux * Added Linux (Minimal) and Linux (dGPU) entries to rEFInd * Removed Linux (i3) entries * I guess this is a hidden feature now... --- .bin/Scripts/build-ufd | 6 +++-- .bin/Scripts/functions/ufd.py | 18 ++++++++++--- .linux_items/include/EFI/boot/icons/dgpu.png | Bin 0 -> 3086 bytes .linux_items/include/EFI/boot/refind.conf | 23 +++++++++++++--- .../include/syslinux/wk_sys_linux.cfg | 25 +++++++++--------- 5 files changed, 50 insertions(+), 22 deletions(-) create mode 100644 .linux_items/include/EFI/boot/icons/dgpu.png diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 4ad726e1..646d96dd 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -77,10 +77,12 @@ if __name__ == '__main__': # Update boot entries try_and_print( - message='Enabling boot entries...', - function=enable_boot_entries, + 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 diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index dbce5bb6..f6083da0 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -68,8 +68,8 @@ 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.""" +def update_boot_entries(boot_entries, boot_files, iso_label, ufd_label): + """Update boot files for UFD usage""" configs = [] # Find config files @@ -79,7 +79,17 @@ def enable_boot_entries(boot_entries, boot_files): if item.name.lower().endswith(c_ext.lower()): configs.append(item.path) - # Uncomment found entries + # Update Linux labels + cmd = [ + 'sed', + '--in-place', + '--regexp-extended', + 's/{}/{}/'.format(iso_label, ufd_label), + *configs, + ] + run_program(cmd) + + # Uncomment extra entries if present for b_path, b_comment in boot_entries: try: find_path('/mnt/UFD{}'.format(b_path)) @@ -87,7 +97,7 @@ def enable_boot_entries(boot_entries, boot_files): # Entry not found, continue to next entry continue - # Update config files + # Entry found, update config files cmd = [ 'sed', '--in-place', diff --git a/.linux_items/include/EFI/boot/icons/dgpu.png b/.linux_items/include/EFI/boot/icons/dgpu.png new file mode 100644 index 0000000000000000000000000000000000000000..e9770abd1ba2487b1e3d08e9a643004f94d019c3 GIT binary patch literal 3086 zcmV+p4Ds`cP)Tvy7{wCK`mp%wa=cJ5>U=$&R3OXpGM z&Y8LAo7|+G%$>*nxBwb z4BQ{8JP-;11=u3fGGVnf$j6AY0JjCm05D&s+Kt+$ewm&ekjOF4Y_FfA=D zBHiK;kZolF+T~0R6#=CA!3pMevuxQicI?=}qD6}^O%p{?Fin#mfBaE6MngpacL?)k zi(eo?6otaVLdwd@n3$MAQIzS=gW(Xgh0wJ8G$V}w5&+=(>#wJ#riS$NbS5V!|IhSb zUA%ZvQ~-=fBS1J+L`Uf9r=Mocnl+ea=suUTXU`^HmL@H}ysE0I$j!|S%Y1;7Cr=8S zgGm4)kjLX;-@bk1l6#XP|YeZoJ#;{kZ+p@$+q z=iIq-l$4Yt#q&EJfWpGUh`v8OJj}xnKb$nr?`QxrGBWV_d|_AjdU|@;ym@nS)qtD~ zz`S|$!v1bULjzS+RmoQcb}|4Sk0<0?-{0R)MMVXjot;UU295^c(q`X4zrV-hp|`h} z{rmUR)YO#JY2au8d_Et#uH*On(KLYP-%jc;~%`_cBYW9+} zs$!aE*dvE*)*k>Jm>|MIp+aiy+O@1$v4UG}xrMZ}wCN^Xzu(WVzy3;ldpnJdjp(`_ zlk4Am@4XZi6>;sg*Wz}&al75PTrLd5z%UGST}RV2Mn^|!Yir}cfddQ=56cJ;td(Y2tFZICbh2pMU;2 zpMLsj*ypZVwThymB37iRR?%eUWtOLcWM-QC?1fSKg=dU@=z$5^vw%@zG! z(=_pVy&O1jfVQ@_8LM@R7A@kAJMLi9rcHP}o;jO7+r2b5H&aiju1R$W>Zo7?& ziVFOGe@w4qnkH#!X&gOzl>YvH($mwq{r1~uob40KdjQzJeLFopJraPOJ9n~i<3?K& zU$h!Td3ibQ?d{G5prWFJB}ebTuAnCf!d+)uM`~YNU zXR~|vZbygxnbh6g%>xfSko*9=^2#eQYpP9DwYIjhbLUPpO|$j7w)X|BU%#G(3l~bq zgYy2my1KYcF0s8Dc<9ifkOMKCWPWXJEp>HuvAm2p)xgc0H;cNCPF&2dudk1_`C^p; z)~#D73w}WbzM7hvxZj6u0OaTAla-YvooA|xc=ztzLfngO06hBWqfyPkNk+Z)+G~uA zj5rH`8*jW(hJRpUVuCNe_(GWbu?2v6^X75&)mO_`A9&-9H-w6Wwg9kU!v@*#1B{Q4 z$Fkd3TmaUuUoWeDrfKIeFmV7-Rh5j4495eYC<^bt|GqN;aJgKL2f#24A=eU&IRGw~ zE2`yJl1&2x147IB`O{Z|R5#aRFxJ$h6+A5<22^2sNi1wda!olRwBr85Bd;DZljIba3|^7Hd~_uY5nRx_{-fZu-mjlsb|>G}*1+;GDUG&VMp zlarIY004ad{r55(xC{g?my6okT8fK{Z5>5zD*%TM9g=Q`0Ab6PEi^SXv2x|gU_9$BrG7i$>0%ufP7<)|td{1HkY1vuDp9>G&mYzujpP*OeO%A3iL{ z3kK<%Z@#g8{lK^{-SN^(FG=SCP1EACdT87M`0A^#=r+_S-^adBSZUA9y<&8X8DVO-)Jwe*XDqwr<^O*X0st`}km`rl!)^ z*qC(7%xap(#*G{8+#fJ;$^gNdn3!PKu3bq5fN7d++O)~`%^?%23=pjD?rzG<%VRd7 z#5BzrkC^1Oio%W^JA~OQXga$U{jF(lZ%0uS%F4>-{N|XZNlHozr%s)sv$K;kXU_1; zFTYH$C>l$OW)bb04WwALLj?j$r4_D z^;O(%cSMGmrishtqNk^a=H_NT`Q($Zm#oRm%%r%um^<&hGpaR@P19s>aF8dSc!K`^ z{&*$b9{>%QjIa(=>cOA9Zzg?BBotieKC7^|EW%E(!_?@OV6^s*0+r)4=)tewv$`*}HeI2uXDj z$g#}#M*;vA09OI^K%t1`165T?PfsT+D+`~`$Kc=~nx@&ZE}^0*(}&ybM%Q%=!-#1? zG77Z<{{TiU03s>`2A<+$Q2{UvgOQPuxRk7ejTU$rypJ#Ol1L(e3V5yX-vKN{Dv@*+ z_zQ3W7zd0<+W|}~Y-qrCnVt!!?UsN3*&;xw7M8$?=Ycc8UuC)`g#HP%SXKDRxd4C_ zI!vGkI1UtuRx6O2RzI)}IAYZRe3uLT;gkV_zvB)n4`c%O14Tf-gh7a^-oJr^K!X*n zFIxG&Hrv}DE&ze=xtQu9^jgPN){%nXeF{k|!wT`E*5L!jnCkh{Lzy250DL};3{{R3007*qoM6N<$f`+B;Bme*a literal 0 HcmV?d00001 diff --git a/.linux_items/include/EFI/boot/refind.conf b/.linux_items/include/EFI/boot/refind.conf index 4ab3be7b..62a639f7 100644 --- a/.linux_items/include/EFI/boot/refind.conf +++ b/.linux_items/include/EFI/boot/refind.conf @@ -26,15 +26,30 @@ menuentry "Linux" { initrd /arch/boot/amd_ucode.img initrd /arch/boot/x86_64/archiso.img options "archisobasedir=arch archisolabel=%ARCHISO_LABEL% copytoram loglevel=3" - submenuentry "Linux (i3)" { - add_options "i3" - } submenuentry "Linux (CLI)" { - add_options "loglevel=4 nomodeset nox" + add_options "nox" } + #UFD-MINIMAL#submenuentry "Linux (Minimal)" { + #UFD-MINIMAL# loader /arch_minimal/vmlinuz + #UFD-MINIMAL# initrd + #UFD-MINIMAL# initrd /arch/boot/intel_ucode.img + #UFD-MINIMAL# initrd /arch/boot/amd_ucode.img + #UFD-MINIMAL# initrd /arch_minimal/archiso.img + #UFD-MINIMAL# options + #UFD-MINIMAL# options "archisobasedir=arch_minimal archisolabel=%ARCHISO_LABEL% copytoram loglevel=3" + #UFD-MINIMAL#} } #UFD-WINPE#menuentry "WindowsPE" { #UFD-WINPE# ostype windows #UFD-WINPE# icon /EFI/boot/icons/wk_win.png #UFD-WINPE# loader /EFI/microsoft/bootx64.efi #UFD-WINPE#} +#UFD-DGPU#menuentry "Mac dGPU Disable Tool" { +#UFD-DGPU# icon /EFI/boot/icons/dgpu.png +#UFD-DGPU# loader /dgpu/vmlinuz +#UFD-DGPU# initrd /arch/boot/intel_ucode.img +#UFD-DGPU# initrd /arch/boot/amd_ucode.img +#UFD-DGPU# initrd /dgpu/archiso.img +#UFD-DGPU# options "archisobasedir=dgpu archisolabel=%ARCHISO_LABEL% nomodeset" +#UFD-DGPU#} + diff --git a/.linux_items/include/syslinux/wk_sys_linux.cfg b/.linux_items/include/syslinux/wk_sys_linux.cfg index d4319c00..b6a9370c 100644 --- a/.linux_items/include/syslinux/wk_sys_linux.cfg +++ b/.linux_items/include/syslinux/wk_sys_linux.cfg @@ -8,17 +8,6 @@ LINUX boot/x86_64/vmlinuz INITRD boot/intel_ucode.img,boot/amd_ucode.img,boot/x86_64/archiso.img APPEND archisobasedir=%INSTALL_DIR% archisolabel=%ARCHISO_LABEL% copytoram loglevel=3 -LABEL wk_linux_i3 -TEXT HELP -A live Linux environment (i3) - * HW diagnostics, file-based backups, data recovery, etc -ENDTEXT -MENU LABEL Linux (i3) -LINUX boot/x86_64/vmlinuz -INITRD boot/intel_ucode.img,boot/amd_ucode.img,boot/x86_64/archiso.img -APPEND archisobasedir=%INSTALL_DIR% archisolabel=%ARCHISO_LABEL% copytoram loglevel=3 i3 -SYSAPPEND 3 - LABEL wk_linux_cli TEXT HELP A live Linux environment (CLI) @@ -27,5 +16,17 @@ ENDTEXT MENU LABEL Linux (CLI) LINUX boot/x86_64/vmlinuz INITRD boot/intel_ucode.img,boot/amd_ucode.img,boot/x86_64/archiso.img -APPEND archisobasedir=%INSTALL_DIR% archisolabel=%ARCHISO_LABEL% copytoram nox nomodeset +APPEND archisobasedir=%INSTALL_DIR% archisolabel=%ARCHISO_LABEL% copytoram nox SYSAPPEND 3 + +#UFD-MINIMAL#LABEL wk_linux_minimal +#UFD-MINIMAL#TEXT HELP +#UFD-MINIMAL#A live Linux environment (Minimal) +#UFD-MINIMAL# * HW diagnostics, file-based backups, data recovery, etc +#UFD-MINIMAL#ENDTEXT +#UFD-MINIMAL#MENU LABEL Linux (Minimal) +#UFD-MINIMAL#LINUX ../arch_minimal/vmlinuz +#UFD-MINIMAL#INITRD boot/intel_ucode.img,boot/amd_ucode.img,../arch_minimal/archiso.img +#UFD-MINIMAL#APPEND archisobasedir=arch_minimal archisolabel=%ARCHISO_LABEL% copytoram loglevel=3 +#UFD-MINIMAL#SYSAPPEND 3 + From 091c31d33ac28d2ab6a31e5b99168bc6cea595ab Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 23:52:06 -0700 Subject: [PATCH 055/113] Bugfix --- .bin/Scripts/functions/setup.py | 10 ---------- .bin/Scripts/new_system_setup.py | 2 -- 2 files changed, 12 deletions(-) diff --git a/.bin/Scripts/functions/setup.py b/.bin/Scripts/functions/setup.py index dc6c53a4..05a9dca3 100644 --- a/.bin/Scripts/functions/setup.py +++ b/.bin/Scripts/functions/setup.py @@ -73,16 +73,6 @@ def config_windows_updates(): write_registry_settings(SETTINGS_WINDOWS_UPDATES, all_users=True) -def disable_windows_telemetry(): - """Disable Windows 10 telemetry settings with O&O ShutUp10.""" - extract_item('ShutUp10', silent=True) - cmd = [ - r'{BinDir}\ShutUp10\OOSU10.exe'.format(**global_vars), - r'{BinDir}\ShutUp10\1201.cfg'.format(**global_vars), - '/quiet'] - run_program(cmd) - - def update_clock(): """Set Timezone and sync clock.""" run_program(['tzutil' ,'/s', WINDOWS_TIME_ZONE], check=False) diff --git a/.bin/Scripts/new_system_setup.py b/.bin/Scripts/new_system_setup.py index 1f6cfcd0..9cc93142 100644 --- a/.bin/Scripts/new_system_setup.py +++ b/.bin/Scripts/new_system_setup.py @@ -100,8 +100,6 @@ if __name__ == '__main__': if global_vars['OS']['Version'] == '10': try_and_print(message='Explorer (system)...', function=config_explorer_system, cs='Done') - try_and_print(message='Disabling telemetry...', - function=disable_windows_telemetry, cs='Done') try_and_print(message='Windows Updates...', function=config_windows_updates, cs='Done') try_and_print(message='Updating Clock...', From 9652aa4623565503134ea2f3c238625a3aa43a0a Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 15 Apr 2019 23:57:46 -0700 Subject: [PATCH 056/113] Added install Syslinux section --- .bin/Scripts/build-ufd | 6 ++++++ .bin/Scripts/functions/ufd.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 646d96dd..1fbb1f46 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -86,6 +86,12 @@ if __name__ == '__main__': ) # Install syslinux + try_and_print( + message='Installing Syslinux...', + function=install_syslinux, + ufd_dev=ufd_dev, + use_mbr=args['--use-mbr'], + ) # Hide items diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index f6083da0..5b289a73 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -159,6 +159,20 @@ def get_user_name(): return user +def install_syslinux(ufd_dev, use_mbr): + """Install Syslinux to UFD.""" + cmd = [ + 'dd', + 'bs=440', + 'count=1', + 'if=/usr/lib/syslinux/bios/{}.bin'.format( + 'mbr' if use_mbr else 'gptmbr', + ), + 'of={}'.format(ufd_dev), + ] + run_program(cmd) + + def is_valid_path(path_obj, path_type): """Verify path_obj is valid by type, returns bool.""" valid_path = False From 4215a2fd78103a5a3e6c36b8a1bda8959cf26f5e Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 16 Apr 2019 00:14:46 -0700 Subject: [PATCH 057/113] Added find_first_partition() --- .bin/Scripts/functions/ufd.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 5b289a73..274b50c1 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -107,6 +107,22 @@ def update_boot_entries(boot_entries, boot_files, iso_label, ufd_label): run_program(cmd) +def find_first_partition(dev_path): + """Find path to first partition of dev, returns str.""" + cmd = [ + 'lsblk', + '--list', + '--noheadings', + '--output', 'name', + '--paths', + dev_path, + ] + result = run_program(cmd, encoding='utf-8', errors='ignore') + part_path = result.stdout.splitlines()[-1].strip() + + return part_path + + def find_path(path): """Find path case-insensitively, returns pathlib.Path obj.""" path_obj = pathlib.Path(path).resolve() @@ -235,23 +251,11 @@ def prep_device(dev_path, label, use_mbr=False): cmd=cmd, ) - # Find partition - cmd = [ - 'lsblk', - '--list', - '--noheadings', - '--output', 'name', - '--paths', - dev_path, - ] - result = run_program(cmd, encoding='utf-8', errors='ignore') - part_path = result.stdout.splitlines()[-1].strip() - # Format partition cmd = [ 'mkfs.vfat', '-F', '32', '-n', label, - part_path, + find_first_partition(dev_path), ] try_and_print( message='Formatting partition...', From a9461311bc97075d083160d5bf1bccc669483330 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 16 Apr 2019 00:15:33 -0700 Subject: [PATCH 058/113] Unmount UFD before installing Syslinux --- .bin/Scripts/build-ufd | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 1fbb1f46..27f0b1af 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -85,6 +85,13 @@ if __name__ == '__main__': ufd_label=UFD_LABEL, ) + # Unmount UFD + try_and_print( + message='Unmounting UFD...', + function=mount, + mount_point='/mnt/UFD', + ) + # Install syslinux try_and_print( message='Installing Syslinux...', From 949efa4de60d604222944ac4394a63099a40a5c0 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 16 Apr 2019 00:16:05 -0700 Subject: [PATCH 059/113] Added hide items sections --- .bin/Scripts/build-ufd | 6 ++++++ .bin/Scripts/functions/ufd.py | 14 ++++++++++++++ .bin/Scripts/settings/ufd.py | 15 +++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 27f0b1af..21363677 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -101,6 +101,12 @@ if __name__ == '__main__': ) # Hide items + try_and_print( + message='Hiding items...', + function=hide_items, + ufd_dev=ufd_dev, + items=ITEMS_HIDDEN, + ) # Done if not args['--force']: diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 274b50c1..de4994cb 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -175,6 +175,20 @@ def get_user_name(): return user +def hide_items(ufd_dev, items): + """Set FAT32 hidden flag for items.""" + # pylint: disable=invalid-name + with open('/root/.mtoolsrc', 'w') as f: + f.write('drive U: file="{}"\n'.format( + find_first_partition(ufd_dev))) + f.write('mtools_skip_check=1\n') + + # Hide items + for item in items: + cmd = ['yes | mattrib +h "U:/{}"'.format(item)] + run_program(cmd, check=False, shell=True) + + def install_syslinux(ufd_dev, use_mbr): """Install Syslinux to UFD.""" cmd = [ diff --git a/.bin/Scripts/settings/ufd.py b/.bin/Scripts/settings/ufd.py index 5123a8a1..db4a2127 100644 --- a/.bin/Scripts/settings/ufd.py +++ b/.bin/Scripts/settings/ufd.py @@ -95,6 +95,21 @@ ITEMS = { ('/sources/boot.wim', '/sources/'), ), } +ITEMS_HIDDEN = ( + # Linux (all versions) + 'arch', + 'arch_minimal', + 'dgpu', + 'EFI', + 'isolinux', + # WinPE + 'boot', + 'bootmgr', + 'bootmgr.efi', + 'en-us', + 'images', + 'sources', + ) if __name__ == '__main__': print("This file is not meant to be called directly.") From cd4ea7586208bb36e7fda7e4ad08a1b2e18767c2 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 16 Apr 2019 00:23:58 -0700 Subject: [PATCH 060/113] Remove the arch dir when updating the UFD --- .bin/Scripts/build-ufd | 11 +++++++++-- .bin/Scripts/functions/ufd.py | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 21363677..2cb06ac1 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -53,8 +53,15 @@ if __name__ == '__main__': if not args['--force']: confirm_selections(args) - # Format and partition device - if not args['--update']: + # Prep UFD + if args['--update']: + # Remove arch folder + try_and_print( + message='Removing Linux...', + function=remove_arch, + ) + else: + # Format and partition prep_device(ufd_dev, UFD_LABEL, use_mbr=args['--use-mbr']) # Mount UFD diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index de4994cb..f771c1da 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -327,6 +327,14 @@ def recursive_copy(source, dest, overwrite=False): raise FileExistsError('Refusing to delete file: {}'.format(dest)) +def remove_arch(): + """Remove arch dir from UFD. + + This ensures a clean installation to the UFD and resets the boot files + """ + shutil.rmtree(find_path('/mnt/UFD/arch')) + + def running_as_root(): """Check if running with effective UID of 0, returns bool.""" return os.geteuid() == 0 From 427243c9339a4c2b461e543a31f300fa73712529 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 16 Apr 2019 00:33:47 -0700 Subject: [PATCH 061/113] Reordered functions --- .bin/Scripts/functions/ufd.py | 78 +++++++++++++++++------------------ 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index f771c1da..51b1ad7c 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -68,45 +68,6 @@ def copy_source(source, items, overwrite=False): unmount('/mnt/Source') -def update_boot_entries(boot_entries, boot_files, iso_label, ufd_label): - """Update boot files for UFD usage""" - 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) - - # Update Linux labels - cmd = [ - 'sed', - '--in-place', - '--regexp-extended', - 's/{}/{}/'.format(iso_label, ufd_label), - *configs, - ] - run_program(cmd) - - # Uncomment extra entries if present - 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 - - # Entry found, update config files - cmd = [ - 'sed', - '--in-place', - '"s/#{}#//"'.format(b_comment), - *configs, - ] - run_program(cmd) - - def find_first_partition(dev_path): """Find path to first partition of dev, returns str.""" cmd = [ @@ -390,6 +351,45 @@ def unmount(mount_point): run_program(cmd) +def update_boot_entries(boot_entries, boot_files, iso_label, ufd_label): + """Update boot files for UFD usage""" + 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) + + # Update Linux labels + cmd = [ + 'sed', + '--in-place', + '--regexp-extended', + 's/{}/{}/'.format(iso_label, ufd_label), + *configs, + ] + run_program(cmd) + + # Uncomment extra entries if present + 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 + + # Entry found, update config files + cmd = [ + 'sed', + '--in-place', + '"s/#{}#//"'.format(b_comment), + *configs, + ] + run_program(cmd) + + def verify_sources(args, ufd_sources): """Check all sources and abort if necessary, returns dict.""" sources = OrderedDict() From 21a587ee0f95872e353fd6db70be1bf327faa91c Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 18 Apr 2019 19:24:39 -0700 Subject: [PATCH 062/113] Bugfix sleep() --- .bin/Scripts/functions/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bin/Scripts/functions/common.py b/.bin/Scripts/functions/common.py index fe75f1ef..28834660 100644 --- a/.bin/Scripts/functions/common.py +++ b/.bin/Scripts/functions/common.py @@ -94,7 +94,7 @@ def abort(show_prompt=True): """Abort script.""" print_warning('Aborted.') if show_prompt: - sleep(timeout) + sleep(1) pause(prompt='Press Enter to exit... ') exit_script(1) From e07c019fb2c422db772b1ced224a87793ebd2d3b Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 18 Apr 2019 19:25:13 -0700 Subject: [PATCH 063/113] Bugfix: Call unmount() not mount() --- .bin/Scripts/build-ufd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 2cb06ac1..5dd15a7c 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -95,7 +95,7 @@ if __name__ == '__main__': # Unmount UFD try_and_print( message='Unmounting UFD...', - function=mount, + function=unmount, mount_point='/mnt/UFD', ) From 050bef7f85fb7aeb10e2c1407d71bd7f6837b141 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 18 Apr 2019 19:26:28 -0700 Subject: [PATCH 064/113] Skip FileNotFoundError in copy_source() * Avoids crash when copying some WinPE ISOs --- .bin/Scripts/functions/ufd.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 51b1ad7c..1bbe0b53 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -64,7 +64,11 @@ def copy_source(source, items, overwrite=False): for i_source, i_dest in items: i_source = '/mnt/Source{}'.format(i_source) i_dest = '/mnt/UFD{}'.format(i_dest) - recursive_copy(i_source, i_dest, overwrite=overwrite) + try: + recursive_copy(i_source, i_dest, overwrite=overwrite) + except FileNotFoundError: + # Going to assume (hope) that this is fine + pass unmount('/mnt/Source') From 153cda7cf8f6652924bfd588fe6e9bb98b2ad9f4 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 18 Apr 2019 19:27:41 -0700 Subject: [PATCH 065/113] Fixed update_boot_entries() --- .bin/Scripts/functions/ufd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 1bbe0b53..be341b59 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -361,7 +361,7 @@ def update_boot_entries(boot_entries, boot_files, iso_label, ufd_label): # Find config files for c_path, c_ext in boot_files.items(): - c_path = find_path(c_path) + c_path = find_path('/mnt/UFD{}'.format(c_path)) for item in os.scandir(c_path): if item.name.lower().endswith(c_ext.lower()): configs.append(item.path) @@ -377,7 +377,7 @@ def update_boot_entries(boot_entries, boot_files, iso_label, ufd_label): run_program(cmd) # Uncomment extra entries if present - for b_path, b_comment in boot_entries: + for b_path, b_comment in boot_entries.items(): try: find_path('/mnt/UFD{}'.format(b_path)) except (FileNotFoundError, NotADirectoryError): From f062f3ce7168e7de14357efc2f5c14a97d8b48c6 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 18 Apr 2019 19:28:15 -0700 Subject: [PATCH 066/113] Fixed source ITEMS --- .bin/Scripts/settings/ufd.py | 48 ++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/.bin/Scripts/settings/ufd.py b/.bin/Scripts/settings/ufd.py index db4a2127..94cf333e 100644 --- a/.bin/Scripts/settings/ufd.py +++ b/.bin/Scripts/settings/ufd.py @@ -59,40 +59,40 @@ BOOT_FILES = { ## Sources use rsync's trailing slash syntax ITEMS = { 'Extra Dir': ( - ('/', '/'), + ('/', '/'), ), 'Linux': ( - ('/arch', '/'), - ('/isolinux', '/'), - ('/EFI/boot', '/EFI/'), - ('/EFI/memtest86', '/EFI/'), + ('/arch', '/'), + ('/isolinux', '/'), + ('/EFI/boot', '/EFI/'), + ('/EFI/memtest86', '/EFI/'), ), 'Linux (dGPU)': ( - ('/arch/boot/archiso.img', '/dgpu/'), - ('/arch/boot/vmlinuz', '/dgpu/'), - ('/arch/pkglist.x86_64.txt', '/dgpu/'), - ('/arch/x86_64', '/dgpu/'), + ('/arch/boot/x86_64/archiso.img', '/dgpu/'), + ('/arch/boot/x86_64/vmlinuz', '/dgpu/'), + ('/arch/pkglist.x86_64.txt', '/dgpu/'), + ('/arch/x86_64', '/dgpu/'), ), 'Linux (Minimal)': ( - ('/arch/boot/archiso.img', '/arch_minimal/'), - ('/arch/boot/vmlinuz', '/arch_minimal/'), - ('/arch/pkglist.x86_64.txt', '/arch_minimal/'), - ('/arch/x86_64', '/arch_minimal/'), + ('/arch/boot/x86_64/archiso.img', '/arch_minimal/'), + ('/arch/boot/x86_64/vmlinuz', '/arch_minimal/'), + ('/arch/pkglist.x86_64.txt', '/arch_minimal/'), + ('/arch/x86_64', '/arch_minimal/'), ), 'Main Kit': ( - ('/', '/{}/'.format(KIT_NAME_FULL)), + ('/', '/{}/'.format(KIT_NAME_FULL)), ), 'WinPE': ( - ('/bootmgr', '/'), - ('/bootmgr.efi', '/'), - ('/en_us', '/'), - ('/Boot/', '/boot/'), - ('/EFI/Boot/', '/EFI/Microsoft/'), - ('/EFI/Microsoft/', '/EFI/Microsoft/'), - ('/Boot/BCD', '/sources/'), - ('/Boot/boot.sdi', '/sources/'), - ('/bootmgr', '/sources/'), - ('/sources/boot.wim', '/sources/'), + ('/bootmgr', '/'), + ('/bootmgr.efi', '/'), + ('/en_us', '/'), + ('/Boot/', '/boot/'), + ('/EFI/Boot/', '/EFI/Microsoft/'), + ('/EFI/Microsoft/', '/EFI/Microsoft/'), + ('/Boot/BCD', '/sources/'), + ('/Boot/boot.sdi', '/sources/'), + ('/bootmgr', '/sources/'), + ('/sources/boot.wim', '/sources/'), ), } ITEMS_HIDDEN = ( From 8edf16452225ecc36d5ecac8a4467d20bac2edd5 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 18 Apr 2019 19:29:40 -0700 Subject: [PATCH 067/113] Avoid crash present in archiso v40-1 * Fix is present in upstream archiso-git * iwd would be installed as a dependency for NetworkManager anyway --- .linux_items/packages/live_add | 1 + .linux_items/packages/live_remove | 1 + 2 files changed, 2 insertions(+) diff --git a/.linux_items/packages/live_add b/.linux_items/packages/live_add index 92b92a6c..c01545c5 100644 --- a/.linux_items/packages/live_add +++ b/.linux_items/packages/live_add @@ -16,6 +16,7 @@ e2fsprogs hexedit hfsprogs htop +iwd ldmtool ldns lha diff --git a/.linux_items/packages/live_remove b/.linux_items/packages/live_remove index 9feb3c02..2e1ffbe7 100644 --- a/.linux_items/packages/live_remove +++ b/.linux_items/packages/live_remove @@ -14,6 +14,7 @@ rp-pppoe smartmontools speedtouch testdisk +wpa_actiond vim-minimal vpnc wvdial From b05057d743bb313bc4c3c4ef2841e2d3c7f6a1b1 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 18 Apr 2019 20:00:37 -0700 Subject: [PATCH 068/113] Ignore errors when uncommenting boot entries * Allows using older ISOs which lack newer boot entries * Not a great idea, but it won't crash --- .bin/Scripts/functions/ufd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index be341b59..c1296d44 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -391,7 +391,7 @@ def update_boot_entries(boot_entries, boot_files, iso_label, ufd_label): '"s/#{}#//"'.format(b_comment), *configs, ] - run_program(cmd) + run_program(cmd, check=False) def verify_sources(args, ufd_sources): From 27eb7975ef321bfcc8d5e326c41660dfb4737a53 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 18 Apr 2019 20:51:14 -0700 Subject: [PATCH 069/113] Fixed SYSLINUX installation --- .bin/Scripts/build-ufd | 13 ++++++++++--- .bin/Scripts/functions/ufd.py | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 5dd15a7c..4d0072c4 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -92,6 +92,13 @@ if __name__ == '__main__': ufd_label=UFD_LABEL, ) + # Install syslinux (to partition) + try_and_print( + message='Syslinux (partition)...', + function=install_syslinux_to_partition, + partition=find_first_partition(ufd_dev), + ) + # Unmount UFD try_and_print( message='Unmounting UFD...', @@ -99,10 +106,10 @@ if __name__ == '__main__': mount_point='/mnt/UFD', ) - # Install syslinux + # Install syslinux (to device) try_and_print( - message='Installing Syslinux...', - function=install_syslinux, + message='Syslinux (device)...', + function=install_syslinux_to_dev, ufd_dev=ufd_dev, use_mbr=args['--use-mbr'], ) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index c1296d44..897334f6 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -154,8 +154,8 @@ def hide_items(ufd_dev, items): run_program(cmd, check=False, shell=True) -def install_syslinux(ufd_dev, use_mbr): - """Install Syslinux to UFD.""" +def install_syslinux_to_dev(ufd_dev, use_mbr): + """Install Syslinux to UFD (dev).""" cmd = [ 'dd', 'bs=440', @@ -168,6 +168,18 @@ def install_syslinux(ufd_dev, use_mbr): run_program(cmd) +def install_syslinux_to_partition(partition): + """Install Syslinux to UFD (partition).""" + cmd = [ + 'syslinux', + '--install', + '--directory', + '/arch/boot/syslinux/', + partition, + ] + run_program(cmd) + + def is_valid_path(path_obj, path_type): """Verify path_obj is valid by type, returns bool.""" valid_path = False From 72c0e7515655e2c4bca25bb2646528db90e62841 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 18 Apr 2019 20:52:11 -0700 Subject: [PATCH 070/113] Fix mounting UFD --- .bin/Scripts/build-ufd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 4d0072c4..4ed2212a 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -68,7 +68,7 @@ if __name__ == '__main__': try_and_print( message='Mounting UFD...', function=mount, - mount_source=ufd_dev, + mount_source=find_first_partition(ufd_dev), mount_point='/mnt/UFD', ) From 19799bb1f4594ec554ceb1d85b6a30ba843f4326 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 18 Apr 2019 20:52:47 -0700 Subject: [PATCH 071/113] Adjusting formatting --- .bin/Scripts/build-ufd | 17 ++++++++++++++++- .bin/Scripts/functions/ufd.py | 6 +++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index 4ed2212a..fff63363 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -54,9 +54,11 @@ if __name__ == '__main__': confirm_selections(args) # Prep UFD + print_info('Prep UFD') if args['--update']: # Remove arch folder try_and_print( + indent=2, message='Removing Linux...', function=remove_arch, ) @@ -66,6 +68,7 @@ if __name__ == '__main__': # Mount UFD try_and_print( + indent=2, message='Mounting UFD...', function=mount, mount_source=find_first_partition(ufd_dev), @@ -73,9 +76,12 @@ if __name__ == '__main__': ) # Copy sources + print_standard(' ') + print_info('Copy Sources') for s_label, s_path in sources.items(): try_and_print( - message='Copying {} files...'.format(s_label), + indent=2, + message='Copying {}...'.format(s_label), function=copy_source, source=s_path, items=ITEMS[s_label], @@ -83,7 +89,10 @@ if __name__ == '__main__': ) # Update boot entries + + print_info('Boot Setup') try_and_print( + indent=2, message='Updating boot entries...', function=update_boot_entries, boot_entries=BOOT_ENTRIES, @@ -94,6 +103,7 @@ if __name__ == '__main__': # Install syslinux (to partition) try_and_print( + indent=2, message='Syslinux (partition)...', function=install_syslinux_to_partition, partition=find_first_partition(ufd_dev), @@ -101,6 +111,7 @@ if __name__ == '__main__': # Unmount UFD try_and_print( + indent=2, message='Unmounting UFD...', function=unmount, mount_point='/mnt/UFD', @@ -108,6 +119,7 @@ if __name__ == '__main__': # Install syslinux (to device) try_and_print( + indent=2, message='Syslinux (device)...', function=install_syslinux_to_dev, ufd_dev=ufd_dev, @@ -115,7 +127,10 @@ if __name__ == '__main__': ) # Hide items + print_standard(' ') + print_info('Final Touches') try_and_print( + indent=2, message='Hiding items...', function=hide_items, ufd_dev=ufd_dev, diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 897334f6..c54646b7 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -202,7 +202,7 @@ def mount(mount_source, mount_point): run_program(cmd) -def prep_device(dev_path, label, use_mbr=False): +def prep_device(dev_path, label, use_mbr=False, indent=2): """Format device in preparation for applying the WizardKit components This is done is four steps: @@ -214,6 +214,7 @@ def prep_device(dev_path, label, use_mbr=False): # Zero-out first 64MB cmd = 'dd bs=4M count=16 if=/dev/zero of={}'.format(dev_path).split() try_and_print( + indent=indent, message='Zeroing first 64MB...', function=run_program, cmd=cmd, @@ -226,6 +227,7 @@ def prep_device(dev_path, label, use_mbr=False): '-1s' if use_mbr else '-4MiB', ).split() try_and_print( + indent=indent, message='Creating partition table...', function=run_program, cmd=cmd, @@ -237,6 +239,7 @@ def prep_device(dev_path, label, use_mbr=False): 'boot' if use_mbr else 'legacy_boot', ).split() try_and_print( + indent=indent, message='Setting boot flag...', function=run_program, cmd=cmd, @@ -249,6 +252,7 @@ def prep_device(dev_path, label, use_mbr=False): find_first_partition(dev_path), ] try_and_print( + indent=indent, message='Formatting partition...', function=run_program, cmd=cmd, From 00805395755eaafb79671ab6c7bfe9af1d5a0a5e Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Fri, 19 Apr 2019 14:36:09 -0700 Subject: [PATCH 072/113] Copy the known_networks file to /root/ --- Build Linux | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Build Linux b/Build Linux index 8ed965b5..effd9155 100755 --- a/Build Linux +++ b/Build Linux @@ -281,6 +281,9 @@ function update_live_env() { mkdir -p "$LIVE_DIR/airootfs/usr/share/wallpaper" cp "$ROOT_DIR/Images/Linux.png" "$LIVE_DIR/airootfs/usr/share/wallpaper/burned.in" fi + + # WiFi + cp "$ROOT_DIR/.linux_items/known_networks" "/root/known_networks" } function update_repo() { From e2d788e26563a0e4f1745c06e6e295e3eb310686 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Fri, 19 Apr 2019 15:23:21 -0700 Subject: [PATCH 073/113] Fixed upate_boot_entries() --- .bin/Scripts/functions/ufd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index c54646b7..96b74b51 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -404,7 +404,7 @@ def update_boot_entries(boot_entries, boot_files, iso_label, ufd_label): cmd = [ 'sed', '--in-place', - '"s/#{}#//"'.format(b_comment), + '"s/#UFD-{}#//"'.format(b_comment), *configs, ] run_program(cmd, check=False) From 731a2818053c6224086beec8476940625ea09e2a Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Fri, 19 Apr 2019 16:33:12 -0700 Subject: [PATCH 074/113] More bugfixes --- .bin/Scripts/build-ufd | 2 +- .bin/Scripts/functions/ufd.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index fff63363..bb0813a8 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -89,7 +89,7 @@ if __name__ == '__main__': ) # Update boot entries - + print_standard(' ') print_info('Boot Setup') try_and_print( indent=2, diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 96b74b51..95a55b64 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -404,7 +404,7 @@ def update_boot_entries(boot_entries, boot_files, iso_label, ufd_label): cmd = [ 'sed', '--in-place', - '"s/#UFD-{}#//"'.format(b_comment), + 's/#{}#//'.format(b_comment), *configs, ] run_program(cmd, check=False) From a83dcdd06a7ab293120b4d5e9ae1ea587a7d3dc0 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Fri, 19 Apr 2019 18:14:10 -0700 Subject: [PATCH 075/113] Handle non-ISO source items --- .bin/Scripts/functions/ufd.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 95a55b64..598985d3 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -59,17 +59,29 @@ def confirm_selections(args): def copy_source(source, items, overwrite=False): - """Mount source and copy items to /mnt/UFD.""" - mount(source, '/mnt/Source') + """Copy source items to /mnt/UFD.""" + is_iso = source.name.lower().endswith('.iso') + + # Mount source if necessary + if is_iso: + mount(source, '/mnt/Source') + + # Copy items for i_source, i_dest in items: - i_source = '/mnt/Source{}'.format(i_source) + i_source = '{}{}'.format( + '/mnt/Source' if is_iso else source, + i_source, + ) i_dest = '/mnt/UFD{}'.format(i_dest) try: recursive_copy(i_source, i_dest, overwrite=overwrite) except FileNotFoundError: # Going to assume (hope) that this is fine pass - unmount('/mnt/Source') + + # Unmount source if necessary + if is_iso: + unmount('/mnt/Source') def find_first_partition(dev_path): From 9502ea0bbcedbe6aeaeb59b7513ec26117ecb5a8 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Fri, 19 Apr 2019 19:02:38 -0700 Subject: [PATCH 076/113] Deleted old build-ufd (BASH) --- .bin/Scripts/build-ufd.bash | 671 ------------------------------------ 1 file changed, 671 deletions(-) delete mode 100755 .bin/Scripts/build-ufd.bash diff --git a/.bin/Scripts/build-ufd.bash b/.bin/Scripts/build-ufd.bash deleted file mode 100755 index 5f272d7d..00000000 --- a/.bin/Scripts/build-ufd.bash +++ /dev/null @@ -1,671 +0,0 @@ -#!/usr/bin/env bash -# -## Wizard Kit: UFD Build Tool -# -# Based on a template by BASH3 Boilerplate v2.3.0 -# http://bash3boilerplate.sh/#authors -# -# The MIT License (MIT) -# Copyright (c) 2013 Kevin van Zonneveld and contributors -# You are not obligated to bundle the LICENSE file with your b3bp projects as long -# as you leave these references intact in the header comments of your source files. - -# Exit on error. Append "|| true" if you expect an error. -set -o errexit -# Exit on error inside any functions or subshells. -set -o errtrace -# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR -set -o nounset -# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip` -set -o pipefail -# Turn on traces, useful while debugging but commented out by default -# set -o xtrace - -if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then - __i_am_main_script="0" # false - - if [[ "${__usage+x}" ]]; then - if [[ "${BASH_SOURCE[1]}" = "${0}" ]]; then - __i_am_main_script="1" # true - fi - - __b3bp_external_usage="true" - __b3bp_tmp_source_idx=1 - fi -else - __i_am_main_script="1" # true - [[ "${__usage+x}" ]] && unset -v __usage - [[ "${__helptext+x}" ]] && unset -v __helptext -fi - -# Set magic variables for current file, directory, os, etc. -__dir="$(cd "$(dirname "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")" && pwd)" -__file="${__dir}/$(basename "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")" -__base="$(basename "${__file}" .sh)" -__wd="$(pwd)" -__usage_example="Usage: sudo $(basename "${0}") --ufd-device [device] --linux-iso [path] --main-kit [path] --winpe-iso [path]" -__all_args="" -for a in "${@}"; do - if [[ "${a:0:1}" == "-" ]]; then - __all_args="${__all_args} ${a}" - else - __all_args="${__all_args} \"${a}\"" - fi -done - - -# Define the environment variables (and their defaults) that this script depends on -LOG_LEVEL="${LOG_LEVEL:-6}" # 7 = debug -> 0 = emergency -NO_COLOR="${NO_COLOR:-}" # true = disable color. otherwise autodetected - - -### Functions -############################################################################## - -function __b3bp_log () { - local log_level="${1}" - shift - - # shellcheck disable=SC2034 - local color_debug="\x1b[35m" - # shellcheck disable=SC2034 - local color_info="\x1b[32m" - # shellcheck disable=SC2034 - local color_notice="\x1b[34m" - # shellcheck disable=SC2034 - local color_warning="\x1b[33m" - # shellcheck disable=SC2034 - local color_error="\x1b[31m" - # shellcheck disable=SC2034 - local color_critical="\x1b[1;31m" - # shellcheck disable=SC2034 - local color_alert="\x1b[1;33;41m" - # shellcheck disable=SC2034 - local color_emergency="\x1b[1;4;5;33;41m" - - local colorvar="color_${log_level}" - - local color="${!colorvar:-${color_error}}" - local color_reset="\x1b[0m" - - if [[ "${NO_COLOR:-}" = "true" ]] || ( [[ "${TERM:-}" != *"256color"* ]] && [[ "${TERM:-}" != "xterm"* ]] && [[ "${TERM:-}" != "screen"* ]] ) || [[ ! -t 2 ]]; then - if [[ "${NO_COLOR:-}" != "false" ]]; then - # Don't use colors on pipes or non-recognized terminals - color=""; color_reset="" - fi - fi - - # all remaining arguments are to be printed - local log_line="" - - while IFS=$'\n' read -r log_line; do - echo -e "$(date -u +"%Y-%m-%d %H:%M:%S UTC") ${color}$(printf "[%9s]" "${log_level}")${color_reset} ${log_line}" 1>&2 - done <<< "${@:-}" -} - -function emergency () { __b3bp_log emergency "${@}"; exit 1; } -function alert () { [[ "${LOG_LEVEL:-0}" -ge 1 ]] && __b3bp_log alert "${@}"; true; } -function critical () { [[ "${LOG_LEVEL:-0}" -ge 2 ]] && __b3bp_log critical "${@}"; true; } -function error () { [[ "${LOG_LEVEL:-0}" -ge 3 ]] && __b3bp_log error "${@}"; true; } -function warning () { [[ "${LOG_LEVEL:-0}" -ge 4 ]] && __b3bp_log warning "${@}"; true; } -function notice () { [[ "${LOG_LEVEL:-0}" -ge 5 ]] && __b3bp_log notice "${@}"; true; } -function info () { [[ "${LOG_LEVEL:-0}" -ge 6 ]] && __b3bp_log info "${@}"; true; } -function debug () { [[ "${LOG_LEVEL:-0}" -ge 7 ]] && __b3bp_log debug "${@}"; true; } - -function help () { - echo "" 1>&2 - echo " ${*}" 1>&2 - echo "" 1>&2 - echo " ${__usage:-No usage available}" 1>&2 - echo "" 1>&2 - - if [[ "${__helptext:-}" ]]; then - echo " ${__helptext}" 1>&2 - echo "" 1>&2 - fi - - exit 1 -} - - -### Parse commandline options -############################################################################## - -# Commandline options. This defines the usage page, and is used to parse cli -# opts & defaults from. The parsing is unforgiving so be precise in your syntax -# - A short option must be preset for every long option; but every short option -# need not have a long option -# - `--` is respected as the separator between options and arguments -# - We do not bash-expand defaults, so setting '~/app' as a default will not resolve to ${HOME}. -# you can use bash variables to work around this (so use ${HOME} instead) - -# shellcheck disable=SC2015 -[[ "${__usage+x}" ]] || read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered - OPTIONS: - -u --ufd-device [arg] Device to which the kit will be applied - -l --linux-iso [arg] Path to the Linux ISO - - -e --extra-dir [arg] Path to the Extra folder (optional) - -m --main-kit [arg] Path to the Main Kit (optional) - -w --winpe-iso [arg] Path to the WinPE ISO (optional) - -h --help This page - - ADVANCED: - -d --debug Enable debug mode - -v --verbose Enable verbose mode - -M --use-mbr Use real MBR instead of GPT w/ Protective MBR - -F --force Bypass all confirmation messages. USE WITH EXTREME CAUTION! -EOF - -# shellcheck disable=SC2015 -[[ "${__helptext+x}" ]] || read -r -d '' __helptext <<-'EOF' || true # exits non-zero when EOF encountered - Paths can be relative to the current working directory or absolute -EOF - -# Translate usage string -> getopts arguments, and set $arg_ defaults -while read -r __b3bp_tmp_line; do - if [[ "${__b3bp_tmp_line}" =~ ^- ]]; then - # fetch single character version of option string - __b3bp_tmp_opt="${__b3bp_tmp_line%% *}" - __b3bp_tmp_opt="${__b3bp_tmp_opt:1}" - - # fetch long version if present - __b3bp_tmp_long_opt="" - - if [[ "${__b3bp_tmp_line}" = *"--"* ]]; then - __b3bp_tmp_long_opt="${__b3bp_tmp_line#*--}" - __b3bp_tmp_long_opt="${__b3bp_tmp_long_opt%% *}" - fi - - # map opt long name to+from opt short name - printf -v "__b3bp_tmp_opt_long2short_${__b3bp_tmp_long_opt//-/_}" '%s' "${__b3bp_tmp_opt}" - printf -v "__b3bp_tmp_opt_short2long_${__b3bp_tmp_opt}" '%s' "${__b3bp_tmp_long_opt//-/_}" - - # check if option takes an argument - if [[ "${__b3bp_tmp_line}" =~ \[.*\] ]]; then - __b3bp_tmp_opt="${__b3bp_tmp_opt}:" # add : if opt has arg - __b3bp_tmp_init="" # it has an arg. init with "" - printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "1" - elif [[ "${__b3bp_tmp_line}" =~ \{.*\} ]]; then - __b3bp_tmp_opt="${__b3bp_tmp_opt}:" # add : if opt has arg - __b3bp_tmp_init="" # it has an arg. init with "" - # remember that this option requires an argument - printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "2" - else - __b3bp_tmp_init="0" # it's a flag. init with 0 - printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "0" - fi - __b3bp_tmp_opts="${__b3bp_tmp_opts:-}${__b3bp_tmp_opt}" - fi - - [[ "${__b3bp_tmp_opt:-}" ]] || continue - - if [[ "${__b3bp_tmp_line}" =~ (^|\.\ *)Default= ]]; then - # ignore default value if option does not have an argument - __b3bp_tmp_varname="__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" - - if [[ "${!__b3bp_tmp_varname}" != "0" ]]; then - __b3bp_tmp_init="${__b3bp_tmp_line##*Default=}" - __b3bp_tmp_re='^"(.*)"$' - if [[ "${__b3bp_tmp_init}" =~ ${__b3bp_tmp_re} ]]; then - __b3bp_tmp_init="${BASH_REMATCH[1]}" - else - __b3bp_tmp_re="^'(.*)'$" - if [[ "${__b3bp_tmp_init}" =~ ${__b3bp_tmp_re} ]]; then - __b3bp_tmp_init="${BASH_REMATCH[1]}" - fi - fi - fi - fi - - if [[ "${__b3bp_tmp_line}" =~ (^|\.\ *)Required\. ]]; then - # remember that this option requires an argument - printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "2" - fi - - printf -v "arg_${__b3bp_tmp_opt:0:1}" '%s' "${__b3bp_tmp_init}" -done <<< "${__usage:-}" - -# run getopts only if options were specified in __usage -if [[ "${__b3bp_tmp_opts:-}" ]]; then - # Allow long options like --this - __b3bp_tmp_opts="${__b3bp_tmp_opts}-:" - - # Reset in case getopts has been used previously in the shell. - OPTIND=1 - - # start parsing command line - set +o nounset # unexpected arguments will cause unbound variables - # to be dereferenced - # Overwrite $arg_ defaults with the actual CLI options - while getopts "${__b3bp_tmp_opts}" __b3bp_tmp_opt; do - [[ "${__b3bp_tmp_opt}" = "?" ]] && help "Invalid use of script: ${*} " - - if [[ "${__b3bp_tmp_opt}" = "-" ]]; then - # OPTARG is long-option-name or long-option=value - if [[ "${OPTARG}" =~ .*=.* ]]; then - # --key=value format - __b3bp_tmp_long_opt=${OPTARG/=*/} - # Set opt to the short option corresponding to the long option - __b3bp_tmp_varname="__b3bp_tmp_opt_long2short_${__b3bp_tmp_long_opt//-/_}" - printf -v "__b3bp_tmp_opt" '%s' "${!__b3bp_tmp_varname}" - OPTARG=${OPTARG#*=} - else - # --key value format - # Map long name to short version of option - __b3bp_tmp_varname="__b3bp_tmp_opt_long2short_${OPTARG//-/_}" - printf -v "__b3bp_tmp_opt" '%s' "${!__b3bp_tmp_varname}" - # Only assign OPTARG if option takes an argument - __b3bp_tmp_varname="__b3bp_tmp_has_arg_${__b3bp_tmp_opt}" - printf -v "OPTARG" '%s' "${@:OPTIND:${!__b3bp_tmp_varname}}" - # shift over the argument if argument is expected - ((OPTIND+=__b3bp_tmp_has_arg_${__b3bp_tmp_opt})) - fi - # we have set opt/OPTARG to the short value and the argument as OPTARG if it exists - fi - __b3bp_tmp_varname="arg_${__b3bp_tmp_opt:0:1}" - __b3bp_tmp_default="${!__b3bp_tmp_varname}" - - __b3bp_tmp_value="${OPTARG}" - if [[ -z "${OPTARG}" ]] && [[ "${__b3bp_tmp_default}" = "0" ]]; then - __b3bp_tmp_value="1" - fi - - printf -v "${__b3bp_tmp_varname}" '%s' "${__b3bp_tmp_value}" - debug "cli arg ${__b3bp_tmp_varname} = (${__b3bp_tmp_default}) -> ${!__b3bp_tmp_varname}" - done - set -o nounset # no more unbound variable references expected - - shift $((OPTIND-1)) - - if [[ "${1:-}" = "--" ]] ; then - shift - fi -fi - - -### Automatic validation of required option arguments -############################################################################## - -for __b3bp_tmp_varname in ${!__b3bp_tmp_has_arg_*}; do - # validate only options which required an argument - [[ "${!__b3bp_tmp_varname}" = "2" ]] || continue - - __b3bp_tmp_opt_short="${__b3bp_tmp_varname##*_}" - __b3bp_tmp_varname="arg_${__b3bp_tmp_opt_short}" - [[ "${!__b3bp_tmp_varname}" ]] && continue - - __b3bp_tmp_varname="__b3bp_tmp_opt_short2long_${__b3bp_tmp_opt_short}" - printf -v "__b3bp_tmp_opt_long" '%s' "${!__b3bp_tmp_varname}" - [[ "${__b3bp_tmp_opt_long:-}" ]] && __b3bp_tmp_opt_long=" (--${__b3bp_tmp_opt_long//_/-})" - - help "Option -${__b3bp_tmp_opt_short}${__b3bp_tmp_opt_long:-} requires an argument" -done - - -### Cleanup Environment variables -############################################################################## - -for __tmp_varname in ${!__b3bp_tmp_*}; do - unset -v "${__tmp_varname}" -done - -unset -v __tmp_varname - - -### Externally supplied __usage. Nothing else to do here -############################################################################## - -if [[ "${__b3bp_external_usage:-}" = "true" ]]; then - unset -v __b3bp_external_usage - return -fi - - -### Signal trapping and backtracing -############################################################################## - -function __b3bp_cleanup_before_exit () { - if [[ "$EUID" -eq 0 ]]; then - for d in Dest Linux WinPE; do - if [[ -d "/mnt/${d}" ]]; then - umount "/mnt/${d}" || true - rmdir "/mnt/${d}" || true - fi - done - fi - if [[ "${?}" != "0" ]]; then - info "Sources unmounted" - fi - if [[ ${arg_F:-} == 0 && "${SILENT:-False}" == "False" ]]; then - read -r -p "Press Enter to exit... " ignored_var 2>&1 - fi -} -trap __b3bp_cleanup_before_exit EXIT - -# requires `set -o errtrace` -__b3bp_err_report() { - local error_code - error_code=${?} - error "Error in ${__file} in function ${1} on line ${2}" - exit ${error_code} -} -# Uncomment the following line for always providing an error backtrace -trap '__b3bp_err_report "${FUNCNAME:-.}" ${LINENO}' ERR - - -### Command-line argument switches (like -d for debugmode, -h for showing helppage) -############################################################################## - -# debug mode -if [[ "${arg_d:?}" = "1" ]]; then - set -o xtrace - LOG_LEVEL="7" - # Enable error backtracing - trap '__b3bp_err_report "${FUNCNAME:-.}" ${LINENO}' ERR -fi - -# verbose mode -if [[ "${arg_v:?}" = "1" ]]; then - set -o verbose -fi - - -### Validation. Error out if the things required for your script are not present -############################################################################## - -if [[ "${arg_F:?}" == 1 ]]; then - SILENT="True" -else - SILENT="False" -fi -if [[ "${arg_M:?}" == 1 ]]; then - USE_MBR="True" -else - USE_MBR="False" -fi - -if [[ "${arg_h:?}" == 1 ]]; then - help "${__usage_example}" -else - # Print warning line - [[ "${arg_u:-}" ]] || echo " -u or --ufd-device is required" - [[ "${arg_l:-}" ]] || echo " -l or --linux-iso is required" - - # Bail if necessary - [[ "${arg_u:-}" ]] || help "${__usage_example}" - [[ "${arg_l:-}" ]] || help "${__usage_example}" -fi -[[ "${LOG_LEVEL:-}" ]] || emergency "Cannot continue without LOG_LEVEL. " - - -### More functions -############################################################################## - -function abort () { - local abort_message="Aborted" - [[ "${1:-}" ]] && abort_message="${1}" || true - error "${abort_message}" - #echo -e "${YELLOW}${abort_message}${CLEAR}" - exit 1 -} - -function ask() { - if [[ "${SILENT}" == "True" ]]; then - echo -e "${1:-} Yes ${BLUE}(Silent)${CLEAR}" - return 0 - fi - while :; do - read -p "${1:-} [Y/N] " -r answer - if echo "$answer" | egrep -iq '^(y|yes|sure)$'; then - return 0 - elif echo "$answer" | egrep -iq '^(n|no|nope)$'; then - return 1 - fi - done -} - - -### Runtime -############################################################################## - -# VARIABLES -DEST_DEV="${arg_u}" -DEST_PAR="${DEST_DEV}1" -LOG_FILE="$(getent passwd "$SUDO_USER" | cut -d: -f6)/Logs/build-ufd_${DEST_DEV##*/}_$(date +%Y-%m-%d_%H%M_%z).log" -MAIN_PY="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/settings/main.py" -RSYNC_ARGS="-hrtuvS --modify-window=1 --progress" -MAIN_KIT="$(realpath "${arg_m:-}" 2>/dev/null || true)" -LINUX_ISO="$(realpath "${arg_l:-}" 2>/dev/null || true)" -WINPE_ISO="$(realpath "${arg_w:-}" 2>/dev/null || true)" -EXTRA_DIR="$(realpath "${arg_e:-}" 2>/dev/null || true)" -mkdir -p "$(dirname "$LOG_FILE")" -chown "$SUDO_USER:$SUDO_USER" -R "$(dirname "$LOG_FILE")" - -# COLORS -CLEAR="\e[0m" -RED="\e[31m" -GREEN="\e[32m" -YELLOW="\e[33m" -BLUE="\e[34m" - -# Load main.py settings -if [ ! -f "${MAIN_PY}" ]; then - echo -e "${RED}ERROR${CLEAR}: ${MAIN_PY} not found." - abort -fi -while read line; do - if echo "${line}" | egrep -q "^\w+='"; then - line="$(echo "${line}" | sed -r 's/[\r\n]+//')" - eval "${line}" - fi -done < "${MAIN_PY}" -if [ -z ${KIT_NAME_FULL+x} ]; then - # KIT_NAME_FULL is not set, assume main.py missing or malformatted - echo -e "${RED}ERROR${CLEAR}: failed to load settings from ${MAIN_PY}" - abort -fi -ISO_LABEL="${KIT_NAME_SHORT}_LINUX" -UFD_LABEL="${KIT_NAME_SHORT}_UFD" - -# Check if root -if [[ "$EUID" -ne 0 ]]; then - echo -e "${RED}ERROR${CLEAR}: This script must be run as root." - abort -fi - -# Check if in tmux -if ! tmux list-session 2>/dev/null | grep -q "build-ufd"; then - # Reload in tmux - eval tmux new-session -s "build-ufd" "${0:-}" ${__all_args} - SILENT="True" # avoid two "Press Enter to exit..." prompts - exit 0 -fi - -# Header -echo -e "${GREEN}${KIT_NAME_FULL}${CLEAR}: UFD Build Tool" -echo "" - -# Verify sources -[[ -b "${DEST_DEV}" ]] || abort "${DEST_DEV} is not a valid device." -[[ -e "${LINUX_ISO}" ]] || abort "Linux ISO not found." -if [[ ! -z "${arg_m:-}" ]]; then - [[ -d "${MAIN_KIT}/.bin" ]] || abort "Invalid Main Kit, ${MAIN_KIT}/.bin not found." -fi -if [[ ! -z "${arg_w:-}" ]]; then - [[ -e "${WINPE_ISO}" ]] || abort "WinPE ISO not found." -fi -if [[ ! -z "${arg_e:-}" ]]; then - [[ -d "${EXTRA_DIR}" ]] || abort "Extra Dir not found." -fi - -# Print Info -echo -e "${BLUE}Sources${CLEAR}" | tee -a "${LOG_FILE}" -echo "Main Kit: ${MAIN_KIT}" | tee -a "${LOG_FILE}" -echo "Linux ISO: ${LINUX_ISO}" | tee -a "${LOG_FILE}" -echo "WinPE ISO: ${WINPE_ISO}" | tee -a "${LOG_FILE}" -echo "Extra Dir: ${EXTRA_DIR:-(Not Specified)}" | tee -a "${LOG_FILE}" -echo "" | tee -a "${LOG_FILE}" -echo -e "${BLUE}Destination${CLEAR}" | tee -a "${LOG_FILE}" -lsblk -n -o NAME,LABEL,SIZE,MODEL,SERIAL "${DEST_DEV}" | tee -a "${LOG_FILE}" -if [[ "${USE_MBR}" == "True" ]]; then - echo -e "${YELLOW}Formatting using legacy MBR${CLEAR}" | tee -a "${LOG_FILE}" -fi -echo "" | tee -a "${LOG_FILE}" - -# Ask before starting job -echo "" -if ask "Is the above information correct?"; then - echo "" - echo -e "${YELLOW}SAFETY CHECK${CLEAR}" - echo "All data will be DELETED from the disk and partition(s) listed above." - echo -e "This is irreversible and will lead to ${RED}DATA LOSS.${CLEAR}" - if ! ask "Asking again to confirm, is this correct?"; then - abort - fi -else - abort -fi - -# Start Build -echo "" | tee -a "${LOG_FILE}" -echo -e "${GREEN}Building Kit${CLEAR}" | tee -a "${LOG_FILE}" -touch "${LOG_FILE}" -tmux split-window -dl 10 tail -f "${LOG_FILE}" - -# Zero beginning of device -dd bs=4M count=16 if=/dev/zero of="${DEST_DEV}" >> "${LOG_FILE}" 2>&1 - -# Format -echo "Formatting drive..." | tee -a "${LOG_FILE}" -if [[ "${USE_MBR}" == "True" ]]; then - parted "${DEST_DEV}" --script -- mklabel msdos mkpart primary fat32 4MiB -1s >> "${LOG_FILE}" 2>&1 - parted "${DEST_DEV}" set 1 boot on >> "${LOG_FILE}" 2>&1 -else - parted "${DEST_DEV}" --script -- mklabel gpt mkpart primary fat32 4MiB -4MiB >> "${LOG_FILE}" 2>&1 - parted "${DEST_DEV}" set 1 legacy_boot on >> "${LOG_FILE}" 2>&1 - #parted "${DEST_DEV}" disk_set pmbr_boot on >> "${LOG_FILE}" 2>&1 - # pmbr_boot breaks detection on some UEFI MOBOs -fi -mkfs.vfat -F 32 -n "${UFD_LABEL}" "${DEST_PAR}" >> "${LOG_FILE}" 2>&1 - -# Mount sources and dest -echo "Mounting sources and destination..." | tee -a "${LOG_FILE}" -mkdir /mnt/{Dest,Linux,WinPE} -p >> "${LOG_FILE}" 2>&1 -mount ${DEST_PAR} /mnt/Dest >> "${LOG_FILE}" 2>&1 -mount "${LINUX_ISO}" /mnt/Linux -r >> "${LOG_FILE}" 2>&1 -if [[ ! -z "${arg_w:-}" ]]; then - mount "${WINPE_ISO}" /mnt/WinPE -r >> "${LOG_FILE}" 2>&1 -fi - -# Find WinPE source -w_boot="$(find /mnt/WinPE -iwholename "/mnt/WinPE/Boot")" -w_boot_bcd="$(find /mnt/WinPE -iwholename "/mnt/WinPE/Boot/BCD")" -w_boot_sdi="$(find /mnt/WinPE -iwholename "/mnt/WinPE/Boot/boot.sdi")" -w_bootmgr="$(find /mnt/WinPE -iwholename "/mnt/WinPE/bootmgr")" -w_bootmgr_efi="$(find /mnt/WinPE -iwholename "/mnt/WinPE/bootmgr.efi")" -w_efi_boot="$(find /mnt/WinPE -iwholename "/mnt/WinPE/EFI/Boot")" -w_efi_microsoft="$(find /mnt/WinPE -iwholename "/mnt/WinPE/EFI/Microsoft")" -w_en_us="$(find /mnt/WinPE -iwholename "/mnt/WinPE/en-us")" -w_sources="$(find /mnt/WinPE -iwholename "/mnt/WinPE/sources")" - -# Copy files -echo "Copying Linux files..." | tee -a "${LOG_FILE}" -rsync ${RSYNC_ARGS} /mnt/Linux/* /mnt/Dest/ >> "${LOG_FILE}" 2>&1 -sed -i "s/${ISO_LABEL}/${UFD_LABEL}/" /mnt/Dest/EFI/boot/refind.conf -sed -i "s/${ISO_LABEL}/${UFD_LABEL}/" /mnt/Dest/arch/boot/syslinux/*cfg - -echo "Copying WinPE files..." | tee -a "${LOG_FILE}" -if [[ ! -z "${arg_w:-}" ]]; then - if [[ ! -z "${w_bootmgr:-}" ]]; then - rsync ${RSYNC_ARGS} "${w_bootmgr}" /mnt/Dest/ >> "${LOG_FILE}" 2>&1 - fi - if [[ ! -z "${w_bootmgr_efi:-}" ]]; then - rsync ${RSYNC_ARGS} "${w_bootmgr_efi}" /mnt/Dest/ >> "${LOG_FILE}" 2>&1 - fi - if [[ ! -z "${w_en_us:-}" ]]; then - rsync ${RSYNC_ARGS} "${w_en_us}" /mnt/Dest/ >> "${LOG_FILE}" 2>&1 - fi - if [[ ! -z "${w_boot:-}" ]]; then - rsync ${RSYNC_ARGS} "${w_boot}"/* /mnt/Dest/Boot/ >> "${LOG_FILE}" 2>&1 - fi - if [[ ! -z "${w_efi_boot:-}" ]]; then - rsync ${RSYNC_ARGS} "${w_efi_boot}"/* /mnt/Dest/EFI/Microsoft/ >> "${LOG_FILE}" 2>&1 - fi - if [[ ! -z "${w_efi_microsoft:-}" ]]; then - rsync ${RSYNC_ARGS} "${w_efi_microsoft}"/* /mnt/Dest/EFI/Microsoft/ >> "${LOG_FILE}" 2>&1 - fi - if [[ ! -z "${w_boot_bcd:-}" ]]; then - rsync ${RSYNC_ARGS} "${w_boot_bcd}" /mnt/Dest/sources/ >> "${LOG_FILE}" 2>&1 - fi - if [[ ! -z "${w_boot_sdi:-}" ]]; then - rsync ${RSYNC_ARGS} "${w_boot_sdi}" /mnt/Dest/sources/ >> "${LOG_FILE}" 2>&1 - fi - if [[ ! -z "${w_bootmgr:-}" ]]; then - rsync ${RSYNC_ARGS} "${w_bootmgr}" /mnt/Dest/sources/ >> "${LOG_FILE}" 2>&1 - fi - if [[ ! -z "${w_sources:-}" ]]; then - rsync ${RSYNC_ARGS} "${w_sources}"/* /mnt/Dest/sources/ >> "${LOG_FILE}" 2>&1 - fi - - # Uncomment boot entries - sed -i "s/#UFD-WINPE#//" /mnt/Dest/EFI/boot/refind.conf - sed -i "s/#UFD-WINPE#//" /mnt/Dest/arch/boot/syslinux/*cfg -fi - -echo "Copying Main Kit..." | tee -a "${LOG_FILE}" -if [[ ! -z "${arg_m:-}" ]]; then - rsync ${RSYNC_ARGS} \ - "${MAIN_KIT}/" \ - "/mnt/Dest/${KIT_NAME_FULL}/" >> "${LOG_FILE}" 2>&1 -fi - -if [[ ! -z "${EXTRA_DIR:-}" ]]; then - echo "Copying Extra files..." | tee -a "${LOG_FILE}" - rsync ${RSYNC_ARGS} \ - "${EXTRA_DIR}"/ \ - /mnt/Dest/ >> "${LOG_FILE}" 2>&1 -fi - -# Install syslinux -echo "Copying Syslinux files..." | tee -a "${LOG_FILE}" -rsync ${RSYNC_ARGS} /usr/lib/syslinux/bios/*.c32 /mnt/Dest/arch/boot/syslinux/ >> "${LOG_FILE}" 2>&1 -syslinux --install -d /arch/boot/syslinux/ ${DEST_PAR} >> "${LOG_FILE}" 2>&1 - -echo "Unmounting destination..." | tee -a "${LOG_FILE}" -umount /mnt/Dest >> "${LOG_FILE}" 2>&1 -rmdir /mnt/Dest >> "${LOG_FILE}" 2>&1 -sync - -echo "Installing Syslinux MBR..." | tee -a "${LOG_FILE}" -if [[ "${USE_MBR}" == "True" ]]; then - dd bs=440 count=1 if=/usr/lib/syslinux/bios/mbr.bin of=${DEST_DEV} >> "${LOG_FILE}" 2>&1 -else - dd bs=440 count=1 if=/usr/lib/syslinux/bios/gptmbr.bin of=${DEST_DEV} >> "${LOG_FILE}" 2>&1 -fi -sync - -# Cleanup -echo "Hiding boot files..." | tee -a "${LOG_FILE}" -echo "drive s: file=\"${DEST_PAR}\"" > /root/.mtoolsrc -echo 'mtools_skip_check=1' >> /root/.mtoolsrc -for item in arch Boot bootmgr{,.efi} EFI en-us images isolinux sources "${KIT_NAME_FULL}"/{.bin,.cbin}; do - yes | mattrib +h "S:/${item}" >> "${LOG_FILE}" 2>&1 || true -done -sync - -# Unmount Sources -echo "Unmounting sources..." | tee -a "${LOG_FILE}" -for d in Linux WinPE; do - umount "/mnt/${d}" >> "${LOG_FILE}" 2>&1 || true - rmdir "/mnt/${d}" >> "${LOG_FILE}" 2>&1 || true -done - -# Close progress pane -pkill -f "tail.*${LOG_FILE}" - -# Done -echo "" | tee -a "${LOG_FILE}" -echo "Done." | tee -a "${LOG_FILE}" -echo "" -exit 0 From 5756d14292221fd0460e53a911cc5ae0e60b61e9 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Fri, 19 Apr 2019 19:16:25 -0700 Subject: [PATCH 077/113] Fix issue #102 --- .bin/Scripts/activate.py | 4 ++-- .bin/Scripts/cbs_fix.py | 4 ++-- .bin/Scripts/check_disk.py | 4 ++-- .bin/Scripts/ddrescue-tui-menu | 4 ++-- .bin/Scripts/dism.py | 4 ++-- .bin/Scripts/hw-diags-audio | 4 ++-- .bin/Scripts/hw-diags-menu | 5 ++--- .bin/Scripts/hw-diags-network | 4 ++-- .bin/Scripts/hw-sensors-monitor | 4 ++-- .bin/Scripts/install_sw_bundle.py | 4 ++-- .bin/Scripts/install_vcredists.py | 4 ++-- .bin/Scripts/mount-all-volumes | 4 ++-- .bin/Scripts/mount-backup-shares | 4 ++-- .bin/Scripts/msword-search | 4 ++-- .bin/Scripts/new_system_setup.py | 4 ++-- .bin/Scripts/safemode_enter.py | 4 ++-- .bin/Scripts/safemode_exit.py | 4 ++-- .bin/Scripts/sfc_scan.py | 4 ++-- .bin/Scripts/system_checklist.py | 4 ++-- .bin/Scripts/system_diagnostics.py | 4 ++-- .bin/Scripts/transferred_keys.py | 4 ++-- .bin/Scripts/update_kit.py | 4 ++-- .bin/Scripts/user_checklist.py | 4 ++-- .bin/Scripts/user_data_transfer.py | 4 ++-- .bin/Scripts/winpe_root_menu.py | 4 ++-- 25 files changed, 50 insertions(+), 51 deletions(-) diff --git a/.bin/Scripts/activate.py b/.bin/Scripts/activate.py index f9a9c69d..fa54fa5d 100644 --- a/.bin/Scripts/activate.py +++ b/.bin/Scripts/activate.py @@ -55,8 +55,8 @@ if __name__ == '__main__': print_success('\nDone.') pause("Press Enter to exit...") exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/cbs_fix.py b/.bin/Scripts/cbs_fix.py index 36a7906f..167f95aa 100644 --- a/.bin/Scripts/cbs_fix.py +++ b/.bin/Scripts/cbs_fix.py @@ -35,8 +35,8 @@ if __name__ == '__main__': print_standard('\nDone.') pause("Press Enter to exit...") exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/check_disk.py b/.bin/Scripts/check_disk.py index 5b0f3c14..8919063e 100644 --- a/.bin/Scripts/check_disk.py +++ b/.bin/Scripts/check_disk.py @@ -49,8 +49,8 @@ if __name__ == '__main__': print_success('Done.') pause("Press Enter to exit...") exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/ddrescue-tui-menu b/.bin/Scripts/ddrescue-tui-menu index a6014d76..f65e24e1 100755 --- a/.bin/Scripts/ddrescue-tui-menu +++ b/.bin/Scripts/ddrescue-tui-menu @@ -54,8 +54,8 @@ if __name__ == '__main__': msg = str(ge) print_error(msg) abort() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/dism.py b/.bin/Scripts/dism.py index 2ef3ff25..4de5b788 100644 --- a/.bin/Scripts/dism.py +++ b/.bin/Scripts/dism.py @@ -50,8 +50,8 @@ if __name__ == '__main__': print_success('Done.') pause("Press Enter to exit...") exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/hw-diags-audio b/.bin/Scripts/hw-diags-audio index 3d3a5991..e581330f 100755 --- a/.bin/Scripts/hw-diags-audio +++ b/.bin/Scripts/hw-diags-audio @@ -34,8 +34,8 @@ if __name__ == '__main__': #print_standard('\nDone.') #pause("Press Enter to exit...") exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/hw-diags-menu b/.bin/Scripts/hw-diags-menu index fa7f0cd8..1c241bf9 100755 --- a/.bin/Scripts/hw-diags-menu +++ b/.bin/Scripts/hw-diags-menu @@ -22,9 +22,8 @@ if __name__ == '__main__': print_standard(' ') sleep(1) pause('Press Enter to exit...') - except SystemExit: - # Normal exit - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: # Cleanup tmux_kill_all_panes() diff --git a/.bin/Scripts/hw-diags-network b/.bin/Scripts/hw-diags-network index 3047e131..138ea67e 100755 --- a/.bin/Scripts/hw-diags-network +++ b/.bin/Scripts/hw-diags-network @@ -40,8 +40,8 @@ if __name__ == '__main__': print_standard('\nDone.') #pause("Press Enter to exit...") exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/hw-sensors-monitor b/.bin/Scripts/hw-sensors-monitor index c27d786a..ffdbbad3 100755 --- a/.bin/Scripts/hw-sensors-monitor +++ b/.bin/Scripts/hw-sensors-monitor @@ -28,8 +28,8 @@ if __name__ == '__main__': run_program(cmd, check=False) monitor_sensors(monitor_pane, monitor_file) exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/install_sw_bundle.py b/.bin/Scripts/install_sw_bundle.py index 0faec26e..b536fd64 100644 --- a/.bin/Scripts/install_sw_bundle.py +++ b/.bin/Scripts/install_sw_bundle.py @@ -59,8 +59,8 @@ if __name__ == '__main__': other_results=other_results) print_standard('\nDone.') exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/install_vcredists.py b/.bin/Scripts/install_vcredists.py index a22cc729..1cd31d95 100644 --- a/.bin/Scripts/install_vcredists.py +++ b/.bin/Scripts/install_vcredists.py @@ -27,8 +27,8 @@ if __name__ == '__main__': print_standard('\nDone.') exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/mount-all-volumes b/.bin/Scripts/mount-all-volumes index f49439f2..5b34c579 100755 --- a/.bin/Scripts/mount-all-volumes +++ b/.bin/Scripts/mount-all-volumes @@ -30,8 +30,8 @@ if __name__ == '__main__': pause("Press Enter to exit...") popen_program(['nohup', 'thunar', '/media'], pipe=True) exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/mount-backup-shares b/.bin/Scripts/mount-backup-shares index 57fbe572..6a1e88d7 100755 --- a/.bin/Scripts/mount-backup-shares +++ b/.bin/Scripts/mount-backup-shares @@ -30,8 +30,8 @@ if __name__ == '__main__': print_standard('\nDone.') #pause("Press Enter to exit...") exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/msword-search b/.bin/Scripts/msword-search index b005c3c1..879e6b8d 100755 --- a/.bin/Scripts/msword-search +++ b/.bin/Scripts/msword-search @@ -76,8 +76,8 @@ if __name__ == '__main__': print_standard('\nDone.') #pause("Press Enter to exit...") exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/new_system_setup.py b/.bin/Scripts/new_system_setup.py index 9cc93142..68e508d2 100644 --- a/.bin/Scripts/new_system_setup.py +++ b/.bin/Scripts/new_system_setup.py @@ -152,8 +152,8 @@ if __name__ == '__main__': print_standard('\nDone.') pause('Press Enter to exit...') exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/safemode_enter.py b/.bin/Scripts/safemode_enter.py index bc6d659d..de9ad119 100644 --- a/.bin/Scripts/safemode_enter.py +++ b/.bin/Scripts/safemode_enter.py @@ -31,8 +31,8 @@ if __name__ == '__main__': pause('Press Enter to reboot...') reboot() exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/safemode_exit.py b/.bin/Scripts/safemode_exit.py index bbbdbcf8..6c47b02d 100644 --- a/.bin/Scripts/safemode_exit.py +++ b/.bin/Scripts/safemode_exit.py @@ -31,8 +31,8 @@ if __name__ == '__main__': pause('Press Enter to reboot...') reboot() exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/sfc_scan.py b/.bin/Scripts/sfc_scan.py index 884694f5..ec85836a 100644 --- a/.bin/Scripts/sfc_scan.py +++ b/.bin/Scripts/sfc_scan.py @@ -32,8 +32,8 @@ if __name__ == '__main__': print_standard('\nDone.') pause('Press Enter to exit...') exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/system_checklist.py b/.bin/Scripts/system_checklist.py index d092c8da..a5b86e1e 100644 --- a/.bin/Scripts/system_checklist.py +++ b/.bin/Scripts/system_checklist.py @@ -125,8 +125,8 @@ if __name__ == '__main__': print_standard('\nDone.') pause('Press Enter exit...') exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/system_diagnostics.py b/.bin/Scripts/system_diagnostics.py index 47c35eab..b1a1848d 100644 --- a/.bin/Scripts/system_diagnostics.py +++ b/.bin/Scripts/system_diagnostics.py @@ -165,8 +165,8 @@ if __name__ == '__main__': print_standard('\nDone.') pause('Press Enter to exit...') exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/transferred_keys.py b/.bin/Scripts/transferred_keys.py index 6dab114d..216f2046 100644 --- a/.bin/Scripts/transferred_keys.py +++ b/.bin/Scripts/transferred_keys.py @@ -21,8 +21,8 @@ if __name__ == '__main__': # Done print_standard('\nDone.') exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/update_kit.py b/.bin/Scripts/update_kit.py index 15b3162e..133fe744 100644 --- a/.bin/Scripts/update_kit.py +++ b/.bin/Scripts/update_kit.py @@ -134,8 +134,8 @@ if __name__ == '__main__': print_standard('\nDone.') pause("Press Enter to exit...") exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/user_checklist.py b/.bin/Scripts/user_checklist.py index e74d26f9..0abd88f3 100644 --- a/.bin/Scripts/user_checklist.py +++ b/.bin/Scripts/user_checklist.py @@ -82,8 +82,8 @@ if __name__ == '__main__': print_standard('\nDone.') pause('Press Enter to exit...') exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/user_data_transfer.py b/.bin/Scripts/user_data_transfer.py index e63e0d7d..60b3c464 100644 --- a/.bin/Scripts/user_data_transfer.py +++ b/.bin/Scripts/user_data_transfer.py @@ -59,8 +59,8 @@ if __name__ == '__main__': print_standard('\nDone.') pause("Press Enter to exit...") exit_script() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() diff --git a/.bin/Scripts/winpe_root_menu.py b/.bin/Scripts/winpe_root_menu.py index a9555e07..94669609 100644 --- a/.bin/Scripts/winpe_root_menu.py +++ b/.bin/Scripts/winpe_root_menu.py @@ -15,8 +15,8 @@ set_log_file('WinPE.log') if __name__ == '__main__': try: menu_root() - except SystemExit: - pass + except SystemExit as sys_exit: + exit_script(sys_exit.code) except: major_exception() From 2fb9b36959c91e8e08adf470ff33ad10fa50e13d Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 21 Apr 2019 21:41:02 -0700 Subject: [PATCH 078/113] Minor formatting change --- .linux_items/include/EFI/boot/refind.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.linux_items/include/EFI/boot/refind.conf b/.linux_items/include/EFI/boot/refind.conf index 62a639f7..4912e6c8 100644 --- a/.linux_items/include/EFI/boot/refind.conf +++ b/.linux_items/include/EFI/boot/refind.conf @@ -19,6 +19,7 @@ menuentry "MemTest86" { icon /EFI/boot/icons/wk_memtest.png loader /EFI/memtest86/memtestx64.efi } + menuentry "Linux" { icon /EFI/boot/icons/wk_arch.png loader /arch/boot/x86_64/vmlinuz @@ -39,11 +40,13 @@ menuentry "Linux" { #UFD-MINIMAL# options "archisobasedir=arch_minimal archisolabel=%ARCHISO_LABEL% copytoram loglevel=3" #UFD-MINIMAL#} } + #UFD-WINPE#menuentry "WindowsPE" { #UFD-WINPE# ostype windows #UFD-WINPE# icon /EFI/boot/icons/wk_win.png #UFD-WINPE# loader /EFI/microsoft/bootx64.efi #UFD-WINPE#} + #UFD-DGPU#menuentry "Mac dGPU Disable Tool" { #UFD-DGPU# icon /EFI/boot/icons/dgpu.png #UFD-DGPU# loader /dgpu/vmlinuz From b737696f7f01a45a08dc3ac348f1cfd355c0b932 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 25 Apr 2019 18:13:53 -0700 Subject: [PATCH 079/113] Show more accurate data in mount-all-volumes() * Fixes issue #108 --- .bin/Scripts/functions/data.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/functions/data.py b/.bin/Scripts/functions/data.py index a8a4deb7..fa0bb20c 100644 --- a/.bin/Scripts/functions/data.py +++ b/.bin/Scripts/functions/data.py @@ -238,9 +238,13 @@ def mount_volumes( vol_data['mount_point'] = None else: size_used = human_readable_size( - mounted_volumes[vol_path]['used']) + mounted_volumes[vol_path]['used'], + decimals=1, + ) size_avail = human_readable_size( - mounted_volumes[vol_path]['avail']) + mounted_volumes[vol_path]['avail'], + decimals=1, + ) vol_data['size_avail'] = size_avail vol_data['size_used'] = size_used vol_data['mount_point'] = mounted_volumes[vol_path]['target'] From 896f9e4a059ec68e0c92a2fcda9f6c01b6da024d Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 25 Apr 2019 18:37:17 -0700 Subject: [PATCH 080/113] Explicitly define smartctl tolerance levels * Fixes issue #104 --- .bin/Scripts/functions/hw_diags.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/.bin/Scripts/functions/hw_diags.py b/.bin/Scripts/functions/hw_diags.py index 4b018447..09226f49 100644 --- a/.bin/Scripts/functions/hw_diags.py +++ b/.bin/Scripts/functions/hw_diags.py @@ -84,7 +84,15 @@ class DiskObj(): self.get_size() # Try enabling SMART - run_program(['sudo', 'smartctl', '--smart=on', self.path], check=False) + run_program( + cmd=[ + 'sudo', + 'smartctl', + '--tolerance=permissive', + '--smart=on', + self.path, + ], + check=False) # Get NVMe/SMART data and set description self.get_smart_details() @@ -349,7 +357,14 @@ class DiskObj(): def get_smart_details(self): """Get data from smartctl.""" - cmd = ['sudo', 'smartctl', '--all', '--json', self.path] + cmd = [ + 'sudo', + 'smartctl', + '--tolerance=verypermissive', + '--all', + '--json', + self.path, + ] self.smartctl = get_json_from_command(cmd, check=False) # Check for attributes @@ -1514,7 +1529,13 @@ def run_smart_short_test(state, test): # Start short test print_standard('Running self-test...') - cmd = ['sudo', 'smartctl', '--test=short', dev.path] + cmd = [ + 'sudo', + 'smartctl', + '--tolerance=normal', + '--test=short', + dev.path, + ] run_program(cmd, check=False) # Monitor progress From 1d2d79eceba65cc96e1f634144e1674e62fc0cc3 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 25 Apr 2019 18:50:07 -0700 Subject: [PATCH 081/113] Updated Rofi config * Set font to Noto Sans * Added HiDPI support * Fixes issue #105 --- .linux_items/include_x/airootfs/etc/skel/.config/rofi/config | 2 ++ .linux_items/include_x/airootfs/etc/skel/.update_x | 3 +++ 2 files changed, 5 insertions(+) diff --git a/.linux_items/include_x/airootfs/etc/skel/.config/rofi/config b/.linux_items/include_x/airootfs/etc/skel/.config/rofi/config index 5c27c752..fd8bc24c 100644 --- a/.linux_items/include_x/airootfs/etc/skel/.config/rofi/config +++ b/.linux_items/include_x/airootfs/etc/skel/.config/rofi/config @@ -7,5 +7,7 @@ rofi.color-normal: argb:d02d3036, #d8d8d8, argb:d02d3036, #2d3036, #d64937 rofi.color-active: argb:d0222222, #d64937, argb:d0222222, #d64937, #d8d8d8 rofi.color-urgent: argb:d0888888, #d8d8d8, argb:d0888888, #888888, #d64937 +rofi.font: Noto Sans 12 + rofi.separator-style: solid rofi.hide-scrollbar: true diff --git a/.linux_items/include_x/airootfs/etc/skel/.update_x b/.linux_items/include_x/airootfs/etc/skel/.update_x index c1f67cf4..d7baea80 100755 --- a/.linux_items/include_x/airootfs/etc/skel/.update_x +++ b/.linux_items/include_x/airootfs/etc/skel/.update_x @@ -47,6 +47,9 @@ if [[ "${dpi}" -ge 192 ]]; then # i3 sed -i -r 's/(height\s+) 26/\1 52/' "${HOME}/.config/i3/config" + # Rofi + sed -i -r 's/Noto Sans 12/Noto Sans 24/' "${HOME}/.config/rofi/config" + # Tint2 sed -i 's/panel_size = 100% 30/panel_size = 100% 60/' \ "${HOME}/.config/tint2/tint2rc" From 5ae8ea3be1e674f5758d61c86dbea33ba371d3e9 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 25 Apr 2019 19:05:44 -0700 Subject: [PATCH 082/113] Show more details for loopback devices * Fixes issue #106 --- .bin/Scripts/hw-drive-info | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.bin/Scripts/hw-drive-info b/.bin/Scripts/hw-drive-info index 71a8d388..df1e1748 100755 --- a/.bin/Scripts/hw-drive-info +++ b/.bin/Scripts/hw-drive-info @@ -3,9 +3,9 @@ BLUE='\033[34m' CLEAR='\033[0m' +IFS=$'\n' # List devices -IFS=$'\n' for line in $(lsblk -do NAME,TRAN,SIZE,VENDOR,MODEL,SERIAL); do if [[ "${line:0:4}" == "NAME" ]]; then echo -e "${BLUE}${line}${CLEAR}" @@ -15,6 +15,18 @@ for line in $(lsblk -do NAME,TRAN,SIZE,VENDOR,MODEL,SERIAL); do done echo "" +# List loopback devices +if [[ "$(losetup -l | wc -l)" > 0 ]]; then + for line in $(losetup -lO NAME,PARTSCAN,RO,BACK-FILE); do + if [[ "${line:0:4}" == "NAME" ]]; then + echo -e "${BLUE}${line}${CLEAR}" + else + echo "${line}" | sed -r 's#/dev/(loop[0-9]+)#\1 #' + fi + done + echo "" +fi + # List partitions for line in $(lsblk -o NAME,SIZE,FSTYPE,LABEL,MOUNTPOINT); do if [[ "${line:0:4}" == "NAME" ]]; then From dac20b12f1aa0549dc0acd1cc2debfa92f799ef2 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 25 Apr 2019 19:09:27 -0700 Subject: [PATCH 083/113] Hide .bin and .cbin in build-ufd * Fixes issue #107 --- .bin/Scripts/settings/ufd.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.bin/Scripts/settings/ufd.py b/.bin/Scripts/settings/ufd.py index 94cf333e..b157e392 100644 --- a/.bin/Scripts/settings/ufd.py +++ b/.bin/Scripts/settings/ufd.py @@ -102,6 +102,9 @@ ITEMS_HIDDEN = ( 'dgpu', 'EFI', 'isolinux', + # Main Kit + '{}/.bin'.format(KIT_NAME_FULL), + '{}/.cbin'.format(KIT_NAME_FULL), # WinPE 'boot', 'bootmgr', From d8024be2c3797e228df353c00772d937546ce539 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 25 Apr 2019 20:55:14 -0700 Subject: [PATCH 084/113] Add option to upload hw-diag results for review --- .bin/Scripts/functions/hw_diags.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.bin/Scripts/functions/hw_diags.py b/.bin/Scripts/functions/hw_diags.py index 09226f49..bea5e01e 100644 --- a/.bin/Scripts/functions/hw_diags.py +++ b/.bin/Scripts/functions/hw_diags.py @@ -1634,6 +1634,17 @@ def show_results(state): # Update progress update_progress_pane(state) + # Ask for review + if ENABLED_UPLOAD_DATA and ask('Upload results for review?'): + try_and_print( + message='Saving debug reports...', + function=save_debug_reports, + state=state, global_vars=global_vars) + try_and_print( + message='Uploading Data...', + function=upload_logdir, + global_vars=global_vars) + def update_main_options(state, selection, main_options): """Update menu and state based on selection.""" From f8773e173616ae10eaa484bc50dbe994df3bb688 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 5 May 2019 12:53:07 -0600 Subject: [PATCH 085/113] Add known networks when building the Linux ISO * Instead of at login --- .bin/Scripts/{setup-wifi => add-known-networks} | 0 .linux_items/include/airootfs/etc/skel/.update_network | 5 ++--- Build Linux | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) rename .bin/Scripts/{setup-wifi => add-known-networks} (100%) diff --git a/.bin/Scripts/setup-wifi b/.bin/Scripts/add-known-networks similarity index 100% rename from .bin/Scripts/setup-wifi rename to .bin/Scripts/add-known-networks diff --git a/.linux_items/include/airootfs/etc/skel/.update_network b/.linux_items/include/airootfs/etc/skel/.update_network index 0b66717f..fb3ec990 100755 --- a/.linux_items/include/airootfs/etc/skel/.update_network +++ b/.linux_items/include/airootfs/etc/skel/.update_network @@ -2,9 +2,8 @@ # ## Setup network and update hostname -# Add saved networks to NetworkManager -sudo setup-wifi -sudo systemctl restart NetworkManager +# Wait for WiFi +sleep 1s # Set hostname IP="$(ip a show scope global \ diff --git a/Build Linux b/Build Linux index effd9155..980c2e77 100755 --- a/Build Linux +++ b/Build Linux @@ -284,6 +284,7 @@ function update_live_env() { # WiFi cp "$ROOT_DIR/.linux_items/known_networks" "/root/known_networks" + echo "add-known-networks" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" } function update_repo() { From b554cfebe0a23b978bc01147a970cdb33ad4be05 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Wed, 8 May 2019 19:38:48 -0600 Subject: [PATCH 086/113] Update tmux config to work with v2.9 --- .linux_items/include/airootfs/etc/skel/.tmux.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.linux_items/include/airootfs/etc/skel/.tmux.conf b/.linux_items/include/airootfs/etc/skel/.tmux.conf index a3712835..c82d4600 100644 --- a/.linux_items/include/airootfs/etc/skel/.tmux.conf +++ b/.linux_items/include/airootfs/etc/skel/.tmux.conf @@ -1,5 +1,5 @@ set -g status off -set -g pane-active-border-fg white +set -g pane-active-border-style fg=white # Window names set -g set-titles on From d51538aac3ebafe68f7d47386af42393e308237e Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 16:52:17 -0600 Subject: [PATCH 087/113] Fixed handling of known_networks --- .bin/Scripts/add-known-networks | 11 ++++++++++- Build Linux | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.bin/Scripts/add-known-networks b/.bin/Scripts/add-known-networks index 6047c438..76316055 100644 --- a/.bin/Scripts/add-known-networks +++ b/.bin/Scripts/add-known-networks @@ -4,6 +4,7 @@ import os import re +import sys import uuid KNOWN_NETWORKS = '/root/known_networks' @@ -34,13 +35,21 @@ method=auto ''' def get_user_name(): - """Get real user name, returns str.""" + """Get user name, returns str.""" user = None + + # Get running user if 'SUDO_USER' in os.environ: user = os.environ.get('SUDO_USER') else: user = os.environ.get('USER') + # Check if user manually specified + for a in sys.argv: + a = a.strip().lower() + if a.startswith('--user='): + user = a.replace('--user=', '') + return user if __name__ == '__main__': diff --git a/Build Linux b/Build Linux index 980c2e77..f9acd897 100755 --- a/Build Linux +++ b/Build Linux @@ -283,8 +283,8 @@ function update_live_env() { fi # WiFi - cp "$ROOT_DIR/.linux_items/known_networks" "/root/known_networks" - echo "add-known-networks" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + cp "$ROOT_DIR/.linux_items/known_networks" "$LIVE_DIR/airootfs/root/known_networks" + echo "add-known-networks --user=$username" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" } function update_repo() { From 617bb1484a2494ddf28d95b8c49dd08de0750937 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 16:54:40 -0600 Subject: [PATCH 088/113] Name connections by SSID --- .bin/Scripts/add-known-networks | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bin/Scripts/add-known-networks b/.bin/Scripts/add-known-networks index 76316055..bdfc7a1c 100644 --- a/.bin/Scripts/add-known-networks +++ b/.bin/Scripts/add-known-networks @@ -63,7 +63,7 @@ if __name__ == '__main__': for ssid, password in known_networks.items(): out_path = '{}/{}.nmconnection'.format( '/etc/NetworkManager/system-connections', - password, + ssid, ) if not os.path.exists(out_path): with open(out_path, 'w') as f: From 798876eb10fc5ce62a0b8ea069f41eb08fc620c0 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 17:06:11 -0600 Subject: [PATCH 089/113] Updated UFD sections --- .bin/Scripts/build-ufd | 21 +++++++++++---------- .bin/Scripts/functions/ufd.py | 20 ++++++++++++++------ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index bb0813a8..bd878a12 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -54,16 +54,8 @@ if __name__ == '__main__': confirm_selections(args) # Prep UFD - print_info('Prep UFD') - if args['--update']: - # Remove arch folder - try_and_print( - indent=2, - message='Removing Linux...', - function=remove_arch, - ) - else: - # Format and partition + if not args['--update']: + print_info('Prep UFD') prep_device(ufd_dev, UFD_LABEL, use_mbr=args['--use-mbr']) # Mount UFD @@ -73,8 +65,17 @@ if __name__ == '__main__': 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') diff --git a/.bin/Scripts/functions/ufd.py b/.bin/Scripts/functions/ufd.py index 598985d3..32f08201 100644 --- a/.bin/Scripts/functions/ufd.py +++ b/.bin/Scripts/functions/ufd.py @@ -60,16 +60,16 @@ def confirm_selections(args): def copy_source(source, items, overwrite=False): """Copy source items to /mnt/UFD.""" - is_iso = source.name.lower().endswith('.iso') + is_image = source.is_file() # Mount source if necessary - if is_iso: + if is_image: mount(source, '/mnt/Source') # Copy items for i_source, i_dest in items: i_source = '{}{}'.format( - '/mnt/Source' if is_iso else source, + '/mnt/Source' if is_image else source, i_source, ) i_dest = '/mnt/UFD{}'.format(i_dest) @@ -80,7 +80,7 @@ def copy_source(source, items, overwrite=False): pass # Unmount source if necessary - if is_iso: + if is_image: unmount('/mnt/Source') @@ -199,6 +199,8 @@ def is_valid_path(path_obj, path_type): valid_path = path_obj.is_dir() elif path_type == 'KIT': valid_path = path_obj.is_dir() and path_obj.joinpath('.bin').exists() + elif path_type == 'IMG': + valid_path = path_obj.is_file() and path_obj.suffix.lower() == '.img' elif path_type == 'ISO': valid_path = path_obj.is_file() and path_obj.suffix.lower() == '.iso' elif path_type == 'UFD': @@ -207,10 +209,16 @@ def is_valid_path(path_obj, path_type): return valid_path -def mount(mount_source, mount_point): +def mount(mount_source, mount_point, read_write=False): """Mount mount_source on mount_point.""" os.makedirs(mount_point, exist_ok=True) - cmd = ['mount', mount_source, mount_point] + cmd = [ + 'mount', + mount_source, + mount_point, + '-o', + 'rw' if read_write else 'ro', + ] run_program(cmd) From b9276aa0d7a7c5fc440ff45a5c60515b579747b5 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 17:09:59 -0600 Subject: [PATCH 090/113] Updated build-ufd --- .bin/Scripts/build-ufd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bin/Scripts/build-ufd b/.bin/Scripts/build-ufd index bd878a12..45c3ff35 100755 --- a/.bin/Scripts/build-ufd +++ b/.bin/Scripts/build-ufd @@ -1,6 +1,6 @@ #!/bin/env python3 # -# pylint: disable=no-name-in-module,wildcard-import +# pylint: disable=no-name-in-module,wildcard-import,wrong-import-position # vim: sts=2 sw=2 ts=2 """Wizard Kit: UFD build tool""" From 5ccd6282599f9109a6d47f8eab83ae7ba01c4da8 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 17:10:38 -0600 Subject: [PATCH 091/113] Updated check_disk.py --- .bin/Scripts/check_disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bin/Scripts/check_disk.py b/.bin/Scripts/check_disk.py index 8919063e..fe18650b 100644 --- a/.bin/Scripts/check_disk.py +++ b/.bin/Scripts/check_disk.py @@ -38,7 +38,7 @@ if __name__ == '__main__': if repair: cs = 'Scheduled' else: - cs = 'CS' + cs = 'No issues' message = 'CHKDSK ({SYSTEMDRIVE})...'.format(**global_vars['Env']) try_and_print(message=message, function=run_chkdsk, cs=cs, other_results=other_results, repair=repair) From 7ccd4c605599fc74868fa385c4c2ada95d06d935 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 18:24:01 -0600 Subject: [PATCH 092/113] BITWISE operators =/= LOGICAL operators --- .bin/Scripts/functions/browsers.py | 4 ++-- .bin/Scripts/functions/ddrescue.py | 13 +++++++------ .bin/Scripts/functions/hw_diags.py | 15 +++++++++------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.bin/Scripts/functions/browsers.py b/.bin/Scripts/functions/browsers.py index dcb0ed2f..c4d110f7 100644 --- a/.bin/Scripts/functions/browsers.py +++ b/.bin/Scripts/functions/browsers.py @@ -32,8 +32,8 @@ def archive_all_users(): user_path = os.path.join(users_root, user_name) appdata_local = os.path.join(user_path, r'AppData\Local') appdata_roaming = os.path.join(user_path, r'AppData\Roaming') - valid_user &= os.path.exists(appdata_local) - valid_user &= os.path.exists(appdata_roaming) + valid_user = valid_user and os.path.exists(appdata_local) + valid_user = valid_user and os.path.exists(appdata_roaming) if valid_user: user_envs.append({ 'USERNAME': user_name, diff --git a/.bin/Scripts/functions/ddrescue.py b/.bin/Scripts/functions/ddrescue.py index 545d08e0..4e6f7809 100644 --- a/.bin/Scripts/functions/ddrescue.py +++ b/.bin/Scripts/functions/ddrescue.py @@ -318,7 +318,7 @@ class RecoveryState(): """Checks if pass is done for all block-pairs, returns bool.""" done = True for bp in self.block_pairs: - done &= bp.pass_done[self.current_pass] + done = done and bp.pass_done[self.current_pass] return done def current_pass_min(self): @@ -376,7 +376,8 @@ class RecoveryState(): self.total_size = 0 for bp in self.block_pairs: bp.self_check() - self.resumed |= bp.resumed + if bp.resumed: + self.resumed = True self.total_size += bp.size def set_pass_num(self): @@ -386,7 +387,7 @@ class RecoveryState(): # Iterate backwards through passes pass_done = True for bp in self.block_pairs: - pass_done &= bp.pass_done[pass_num] + pass_done = pass_done and bp.pass_done[pass_num] if pass_done: # All block-pairs reported being done # Set to next pass, unless we're on the last pass (2) @@ -742,9 +743,9 @@ def is_writable_dir(dir_obj): """Check if we have read-write-execute permissions, returns bool.""" is_ok = True path_st_mode = os.stat(dir_obj.path).st_mode - is_ok == is_ok and path_st_mode & stat.S_IRUSR - is_ok == is_ok and path_st_mode & stat.S_IWUSR - is_ok == is_ok and path_st_mode & stat.S_IXUSR + is_ok = is_ok and path_st_mode & stat.S_IRUSR + is_ok = is_ok and path_st_mode & stat.S_IWUSR + is_ok = is_ok and path_st_mode & stat.S_IXUSR return is_ok diff --git a/.bin/Scripts/functions/hw_diags.py b/.bin/Scripts/functions/hw_diags.py index bea5e01e..c085a5ed 100644 --- a/.bin/Scripts/functions/hw_diags.py +++ b/.bin/Scripts/functions/hw_diags.py @@ -186,8 +186,8 @@ class DiskObj(): disk_ok = False # Disable override if necessary - self.override_disabled |= ATTRIBUTES[attr_type][k].get( - 'Critical', False) + if ATTRIBUTES[attr_type][k].get('Critical', False): + self.override_disabled = True # SMART overall assessment ## NOTE: Only fail drives if the overall value exists and reports failed @@ -788,7 +788,7 @@ def menu_diags(state, args): # If so, verify no other tests are enabled and set quick_mode state.quick_mode = True for opt in main_options[3:4] + main_options[5:]: - state.quick_mode &= not opt['Enabled'] + state.quick_mode = state.quick_mode and not opt['Enabled'] else: state.quick_mode = False @@ -1001,7 +1001,8 @@ def run_hw_tests(state): # Run disk safety checks (if necessary) _disk_tests_enabled = False for k in TESTS_DISK: - _disk_tests_enabled |= state.tests[k]['Enabled'] + if state.tests[k]['Enabled']: + _disk_tests_enabled = True if _disk_tests_enabled: for disk in state.disks: try: @@ -1611,7 +1612,8 @@ def show_results(state): # CPU tests _enabled = False for k in TESTS_CPU: - _enabled |= state.tests[k]['Enabled'] + if state.tests[k]['Enabled']: + _enabled = True if _enabled: print_success('CPU:'.format(k)) show_report(state.cpu.generate_cpu_report(), log_report=True) @@ -1620,7 +1622,8 @@ def show_results(state): # Disk tests _enabled = False for k in TESTS_DISK: - _enabled |= state.tests[k]['Enabled'] + if state.tests[k]['Enabled']: + _enabled = True if _enabled: print_success('Disk{}:'.format( '' if len(state.disks) == 1 else 's')) From 35890d6bb31544ff379858f161ffd77a6496031b Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 18:29:32 -0600 Subject: [PATCH 093/113] Fixed setting timezone in Windows --- .bin/Scripts/functions/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bin/Scripts/functions/setup.py b/.bin/Scripts/functions/setup.py index 05a9dca3..20c3eaf3 100644 --- a/.bin/Scripts/functions/setup.py +++ b/.bin/Scripts/functions/setup.py @@ -75,7 +75,7 @@ def config_windows_updates(): def update_clock(): """Set Timezone and sync clock.""" - run_program(['tzutil' ,'/s', WINDOWS_TIME_ZONE], check=False) + run_program(['tzutil', '/s', WINDOWS_TIME_ZONE], check=False) run_program(['net', 'stop', 'w32ime'], check=False) run_program( ['w32tm', '/config', '/syncfromflags:manual', From 214df527230a0e7c779481ec4fc597f58f755908 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 18:33:57 -0600 Subject: [PATCH 094/113] Expanded SW bundle sections --- .bin/Scripts/functions/browsers.py | 31 ++++-- .bin/Scripts/functions/setup.py | 168 +++++++++++++++++++++++++---- .bin/Scripts/functions/update.py | 16 +++ .bin/Scripts/settings/sources.py | 25 +++-- .bin/Scripts/update_kit.py | 1 + 5 files changed, 205 insertions(+), 36 deletions(-) diff --git a/.bin/Scripts/functions/browsers.py b/.bin/Scripts/functions/browsers.py index c4d110f7..8a1f4dcb 100644 --- a/.bin/Scripts/functions/browsers.py +++ b/.bin/Scripts/functions/browsers.py @@ -325,7 +325,6 @@ def install_adblock(indent=8, width=32, just_firefox=False): if just_firefox and browser_data[browser]['base'] != 'mozilla': continue exe_path = browser_data[browser].get('exe_path', None) - function=run_program if not exe_path: if browser_data[browser]['profiles']: print_standard( @@ -375,7 +374,6 @@ def install_adblock(indent=8, width=32, just_firefox=False): elif browser_data[browser]['base'] == 'ie': urls.append(IE_GALLERY) - function=popen_program # By using check=False we're skipping any return codes so # it should only fail if the program can't be run @@ -384,10 +382,16 @@ def install_adblock(indent=8, width=32, just_firefox=False): # installation status. try_and_print(message='{}...'.format(browser), indent=indent, width=width, - cs='Done', function=function, + cs='Started', function=popen_program, cmd=[exe_path, *urls], check=False) +def is_installed(browser_name): + """Checks if browser is installed based on exe_path, returns bool.""" + browser_name = browser_name.replace(' Chromium', '') + return bool(browser_data.get(browser_name, {}).get('exe_path', False)) + + def list_homepages(indent=8, width=32): """List current homepages for reference.""" browser_list = [k for k, v in sorted(browser_data.items()) if v['exe_path']] @@ -419,6 +423,12 @@ def list_homepages(indent=8, width=32): indent=' '*indent, width=width, name=name, page=page)) +def profile_present(browser_name): + """Checks if a profile was detected for browser, returns bool.""" + browser_name = browser_name.replace(' Chromium', '') + return bool(browser_data.get(browser_name, {}).get('profiles', False)) + + def reset_browsers(indent=8, width=32): """Reset all detected browsers to safe defaults.""" browser_list = [k for k, v in sorted(browser_data.items()) if v['profiles']] @@ -437,14 +447,21 @@ def reset_browsers(indent=8, width=32): other_results=other_results, profile=profile) -def scan_for_browsers(just_firefox=False): +def scan_for_browsers(just_firefox=False, silent=False): """Scan system for any supported browsers.""" for name, details in sorted(SUPPORTED_BROWSERS.items()): if just_firefox and details['base'] != 'mozilla': continue - try_and_print(message='{}...'.format(name), - function=get_browser_details, cs='Detected', - other_results=other_results, name=name) + if silent: + try: + get_browser_details(name) + except Exception: + # Ignore errors in silent mode + pass + else: + try_and_print(message='{}...'.format(name), + function=get_browser_details, cs='Detected', + other_results=other_results, name=name) if __name__ == '__main__': diff --git a/.bin/Scripts/functions/setup.py b/.bin/Scripts/functions/setup.py index 20c3eaf3..ad575f75 100644 --- a/.bin/Scripts/functions/setup.py +++ b/.bin/Scripts/functions/setup.py @@ -1,7 +1,10 @@ # Wizard Kit: Functions - Setup +from functions.browsers import * +from functions.json import * from functions.update import * from settings.setup import * +from settings.sources import * # Configuration @@ -63,9 +66,13 @@ def config_explorer_system(): write_registry_settings(SETTINGS_EXPLORER_SYSTEM, all_users=True) -def config_explorer_user(): - """Configure Windows Explorer for current user.""" - write_registry_settings(SETTINGS_EXPLORER_USER, all_users=False) +def config_explorer_user(setup_mode='All'): + """Configure Windows Explorer for current user per setup_mode.""" + settings_explorer_user = { + k: v for k, v in SETTINGS_EXPLORER_USER.items() + if setup_mode not in v.get('Invalid modes', []) + } + write_registry_settings(settings_explorer_user, all_users=False) def config_windows_updates(): @@ -107,6 +114,39 @@ def write_registry_settings(settings, all_users=False): # Installations +def find_current_software(): + """Find currently installed software, returns list.""" + ninite_extras_path = r'{BaseDir}\Installers\Extras'.format(**global_vars) + installers = [] + + # Browsers + scan_for_browsers(silent=True) + for browser in ('Google Chrome', 'Mozilla Firefox', 'Opera Chromium'): + if is_installed(browser): + installers.append( + r'{}\Web Browsers\{}.exe'.format(ninite_extras_path, browser)) + + # TODO: Add more sections + + return installers + +def find_missing_software(): + """Find missing software based on dirs/files present, returns list.""" + ninite_extras_path = r'{BaseDir}\Installers\Extras'.format(**global_vars) + installers = [] + + # Browsers + scan_for_browsers(silent=True) + for browser in ('Google Chrome', 'Mozilla Firefox', 'Opera Chromium'): + if profile_present(browser): + installers.append( + r'{}\Web Browsers\{}.exe'.format(ninite_extras_path, browser)) + + # TODO: Add more sections + + return installers + + def install_adobe_reader(): """Install Adobe Reader.""" cmd = [ @@ -159,29 +199,115 @@ def install_firefox_extensions(): run_program(cmd) -def install_ninite_bundle(mse=False, libreoffice=False): +def install_libreoffice( + quickstart=True, register_mso_types=True, + use_mso_formats=False, vcredist=False): + """Install LibreOffice using specified settings.""" + cmd = [ + 'msiexec', '/passive', '/norestart', + '/i', r'{}\Installers\Extras\Office\LibreOffice.msi'.format( + global_vars['BaseDir']), + 'REBOOTYESNO=No', + 'ISCHECKFORPRODUCTUPDATES=0', + 'QUICKSTART={}'.format(1 if quickstart else 0), + 'UI_LANGS=en_US', + 'VC_REDIST={}'.format(1 if vcredist else 0), + ] + if register_mso_types: + cmd.append('REGISTER_ALL_MSO_TYPES=1') + else: + cmd.append('REGISTER_NO_MSO_TYPES=1') + xcu_dir = r'{APPDATA}\LibreOffice\4\user'.format(**global_vars['Env']) + xcu_file = r'{}\registrymodifications.xcu'.format(xcu_dir) + + # Set default save format + if use_mso_formats and not os.path.exists(xcu_file): + os.makedirs(xcu_dir, exist_ok=True) + with open(xcu_file, 'w', encoding='utf-8', newline='\n') as f: + f.write(LIBREOFFICE_XCU_DATA) + + # Install LibreOffice + run_program(cmd, check=True) + +def install_ninite_bundle( + # pylint: disable=too-many-arguments,too-many-branches + base=True, + browsers_only=False, + libreoffice=False, + missing=False, + mse=False, + standard=True, + ): """Run Ninite installer(s), returns list of Popen objects.""" popen_objects = [] - if global_vars['OS']['Version'] in ('8', '8.1', '10'): - # Modern selection - popen_objects.append( - popen_program(r'{BaseDir}\Installers\Extras\Bundles\Modern.exe'.format( - **global_vars))) - else: - # Legacy selection - if mse: - cmd = r'{BaseDir}\Installers\Extras\Security'.format(**global_vars) - cmd += r'\Microsoft Security Essentials.exe' - popen_objects.append(popen_program(cmd)) - popen_objects.append( - popen_program(r'{BaseDir}\Installers\Extras\Bundles\Legacy.exe'.format( - **global_vars))) + if browsers_only: + # This option is deprecated + installer_path = r'{BaseDir}\Installers\Extras\Web Browsers'.format( + **global_vars) + scan_for_browsers(silent=True) + for browser in ('Google Chrome', 'Mozilla Firefox', 'Opera Chromium'): + if is_installed(browser): + cmd = r'{}\{}.exe'.format(installer_path, browser) + popen_objects.append(popen_program(cmd)) + + # Bail + return popen_objects + + # Main selections + main_selections = [] + if base: + main_selections.append('base') + if standard: + if global_vars['OS']['Version'] in ('8', '8.1', '10'): + main_selections.append('standard') + else: + main_selections.append('standard7') + if main_selections: + # Only run if base and/or standard are enabled + cmd = r'{}\Installers\Extras\Bundles\{}.exe'.format( + global_vars['BaseDir'], + '-'.join(main_selections), + ) + popen_objects.append(popen_program([cmd])) + + # Extra selections + extra_selections = {} + for cmd in find_current_software(): + extra_selections[cmd] = True + if missing: + for cmd in find_missing_software(): + extra_selections[cmd] = True + + # Remove overlapping selections + regex = [] + for n_name, n_group in NINITE_REGEX.items(): + if n_name in main_selections: + regex.extend(n_group) + regex = '({})'.format('|'.join(regex)) + extra_selections = { + cmd: True for cmd in extra_selections + if not re.search(regex, cmd, re.IGNORECASE) + } + + # Start extra selections + for cmd in extra_selections: + popen_objects.append(popen_program([cmd])) + + # Microsoft Security Essentials + if mse: + cmd = r'{}\Installers\Extras\Security\{}'.format( + global_vars['BaseDir'], + 'Microsoft Security Essentials.exe', + ) + popen_objects.append(popen_program([cmd])) # LibreOffice if libreoffice: - cmd = r'{BaseDir}\Installers\Extras\Office'.format(**global_vars) - cmd += r'\LibreOffice.exe' - popen_objects.append(popen_program(cmd)) + cmd = r'{}\Installers\Extras\Office\{}'.format( + global_vars['BaseDir'], + 'LibreOffice.exe', + ) + popen_objects.append(popen_program([cmd])) # Done return popen_objects diff --git a/.bin/Scripts/functions/update.py b/.bin/Scripts/functions/update.py index 40bc3a27..38f881d5 100755 --- a/.bin/Scripts/functions/update.py +++ b/.bin/Scripts/functions/update.py @@ -615,6 +615,22 @@ def update_adobe_reader_dc(): dest, 'Adobe Reader DC.exe', SOURCE_URLS['Adobe Reader DC']) +def update_libreoffice(): + # Prep + dest = r'{}\Installers\Extras\Office'.format( + global_vars['BaseDir']) + + # Remove existing installer + try: + os.remove(r'{}\LibreOffice.msi'.format(dest)) + except FileNotFoundError: + pass + + # Download + download_generic( + dest, 'LibreOffice.msi', SOURCE_URLS['LibreOffice']) + + def update_macs_fan_control(): # Prep dest = r'{}\Installers'.format( diff --git a/.bin/Scripts/settings/sources.py b/.bin/Scripts/settings/sources.py index e6cf5c3a..2abf079f 100644 --- a/.bin/Scripts/settings/sources.py +++ b/.bin/Scripts/settings/sources.py @@ -1,4 +1,6 @@ -# Wizard Kit: Settings - Sources +'''Wizard Kit: Settings - Sources''' +# pylint: disable=line-too-long +# vim: sts=2 sw=2 ts=2 tw=0 SOURCE_URLS = { 'Adobe Reader DC': 'http://ardownload.adobe.com/pub/adobe/reader/win/AcrobatDC/1901020098/AcroRdrDC1901020098_en_US.exe', @@ -15,7 +17,7 @@ SOURCE_URLS = { 'ERUNT': 'http://www.aumha.org/downloads/erunt.zip', 'Everything32': 'https://www.voidtools.com/Everything-1.4.1.935.x86.en-US.zip', 'Everything64': 'https://www.voidtools.com/Everything-1.4.1.935.x64.en-US.zip', - 'FastCopy': 'http://ftp.vector.co.jp/71/31/2323/FastCopy363_installer.exe', + 'FastCopy': 'https://fastcopy.jp/archive/FastCopy380_installer.exe', 'Firefox uBO': 'https://addons.mozilla.org/firefox/downloads/file/1709472/ublock_origin-1.18.6-an+fx.xpi', 'HitmanPro32': 'https://dl.surfright.nl/HitmanPro.exe', 'HitmanPro64': 'https://dl.surfright.nl/HitmanPro_x64.exe', @@ -23,6 +25,7 @@ SOURCE_URLS = { 'Intel SSD Toolbox': r'https://downloadmirror.intel.com/28593/eng/Intel%20SSD%20Toolbox%20-%20v3.5.9.exe', 'IOBit_Uninstaller': r'https://portableapps.com/redirect/?a=IObitUninstallerPortable&s=s&d=pa&f=IObitUninstallerPortable_7.5.0.7.paf.exe', 'KVRT': 'http://devbuilds.kaspersky-labs.com/devbuilds/KVRT/latest/full/KVRT.exe', + 'LibreOffice': 'https://download.documentfoundation.org/libreoffice/stable/6.2.4/win/x86_64/LibreOffice_6.2.4_Win_x64.msi', 'Macs Fan Control': 'https://www.crystalidea.com/downloads/macsfancontrol_setup.exe', 'NirCmd32': 'https://www.nirsoft.net/utils/nircmd.zip', 'NirCmd64': 'https://www.nirsoft.net/utils/nircmd-x64.zip', @@ -37,8 +40,8 @@ SOURCE_URLS = { 'SDIO Torrent': 'http://snappy-driver-installer.org/downloads/SDIO_Update.torrent', 'TDSSKiller': 'https://media.kaspersky.com/utilities/VirusUtilities/EN/tdsskiller.exe', 'TestDisk': 'https://www.cgsecurity.org/testdisk-7.1-WIP.win.zip', - 'wimlib32': 'https://wimlib.net/downloads/wimlib-1.13.0-windows-i686-bin.zip', - 'wimlib64': 'https://wimlib.net/downloads/wimlib-1.13.0-windows-x86_64-bin.zip', + 'wimlib32': 'https://wimlib.net/downloads/wimlib-1.13.1-windows-i686-bin.zip', + 'wimlib64': 'https://wimlib.net/downloads/wimlib-1.13.1-windows-x86_64-bin.zip', 'Winapp2': 'https://github.com/MoscaDotTo/Winapp2/archive/master.zip', 'WizTree': 'https://antibody-software.com/files/wiztree_3_28_portable.zip', 'XMPlay 7z': 'https://support.xmplay.com/files/16/xmp-7z.zip?v=800962', @@ -66,10 +69,18 @@ VCREDIST_SOURCES = { '64': 'https://aka.ms/vs/15/release/vc_redist.x64.exe', }, } +NINITE_REGEX = { + 'base': ['7-Zip', 'VLC'], + 'standard': ['Google Chrome', 'Mozilla Firefox', 'SumatraPDF'], + 'standard7': ['Google Chrome', 'Mozilla Firefox', 'SumatraPDF'], + } NINITE_SOURCES = { 'Bundles': { - 'Legacy.exe': '.net4.7.2-7zip-chrome-firefox-vlc', - 'Modern.exe': '.net4.7.2-7zip-chrome-classicstart-firefox-vlc', + 'base.exe': '.net4.7.2-7zip-vlc', + 'base-standard.exe': '.net4.7.2-7zip-chrome-classicstart-firefox-sumatrapdf-vlc', + 'base-standard7.exe': '.net4.7.2-7zip-chrome-firefox-sumatrapdf-vlc', + 'standard.exe': 'chrome-classicstart-firefox-sumatrapdf', + 'standard7.exe': 'chrome-firefox-sumatrapdf', }, 'Audio-Video': { 'AIMP.exe': 'aimp', @@ -216,5 +227,3 @@ WINDOWS_UPDATE_SOURCES = { if __name__ == '__main__': print("This file is not meant to be called directly.") - -# vim: sts=2 sw=2 ts=2 tw=0 diff --git a/.bin/Scripts/update_kit.py b/.bin/Scripts/update_kit.py index 133fe744..77f527aa 100644 --- a/.bin/Scripts/update_kit.py +++ b/.bin/Scripts/update_kit.py @@ -57,6 +57,7 @@ if __name__ == '__main__': # Installers print_info(' Installers') try_and_print(message='Adobe Reader DC...', function=update_adobe_reader_dc, other_results=other_results, width=40) + try_and_print(message='LibreOffice...', function=update_libreoffice, other_results=other_results, width=40) try_and_print(message='Macs Fan Control...', function=update_macs_fan_control, other_results=other_results, width=40) try_and_print(message='MS Office...', function=update_office, other_results=other_results, width=40) try_and_print(message='Visual C++ Runtimes...', function=update_vcredists, other_results=other_results, width=40) From 7816602685b1c36c4ee3aae9fedef47867f87571 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 18:40:42 -0600 Subject: [PATCH 095/113] 4K Alignment checks --- .bin/Scripts/functions/common.py | 7 +++++-- .bin/Scripts/functions/hw_diags.py | 26 +++++++++++++++++++++++++- .bin/Scripts/functions/sw_diags.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/.bin/Scripts/functions/common.py b/.bin/Scripts/functions/common.py index 28834660..9db75814 100644 --- a/.bin/Scripts/functions/common.py +++ b/.bin/Scripts/functions/common.py @@ -64,10 +64,13 @@ class GenericRepair(Exception): class MultipleInstallationsError(Exception): pass -class NotInstalledError(Exception): +class NoProfilesError(Exception): pass -class NoProfilesError(Exception): +class Not4KAlignedError(Exception): + pass + +class NotInstalledError(Exception): pass class OSInstalledLegacyError(Exception): diff --git a/.bin/Scripts/functions/hw_diags.py b/.bin/Scripts/functions/hw_diags.py index c085a5ed..36be4a30 100644 --- a/.bin/Scripts/functions/hw_diags.py +++ b/.bin/Scripts/functions/hw_diags.py @@ -307,6 +307,11 @@ class DiskObj(): attr_type=self.attr_type, **COLORS)) report.extend(sorted(self.nvme_smart_notes.keys())) + # 4K alignment check + if not self.is_4k_aligned(): + report.append('{YELLOW}Warning{CLEAR}'.format(**COLORS)) + report.append(' One or more partitions are not 4K aligned') + # Tests for test in self.tests.values(): report.extend(test.report) @@ -410,6 +415,26 @@ class DiskObj(): 'self_test', {}).get( k, {}) + def is_4k_aligned(self): + """Check if partitions are 4K aligned, returns bool.""" + cmd = [ + 'sudo', + 'sfdisk', + '--json', + self.path, + ] + aligned = True + + # Get partition details + json_data = get_json_from_command(cmd) + + # Check partitions + for part in json_data.get('partitiontable', {}).get('partitions', []): + aligned = aligned and part.get('start', -1) % 4096 == 0 + + # Done + return aligned + def safety_check(self, silent=False): """Run safety checks and disable tests if necessary.""" test_running = False @@ -454,7 +479,6 @@ class DiskObj(): disk_ok = OVERRIDES_FORCED or ask('Run tests on this device anyway?') print_standard(' ') - # Disable tests if necessary (statuses won't be overwritten) if test_running: if not silent: diff --git a/.bin/Scripts/functions/sw_diags.py b/.bin/Scripts/functions/sw_diags.py index 1b965766..b122528a 100644 --- a/.bin/Scripts/functions/sw_diags.py +++ b/.bin/Scripts/functions/sw_diags.py @@ -6,6 +6,35 @@ from functions.common import * from settings.sw_diags import * +def check_4k_alignment(show_alert=False): + """Check that all partitions are 4K aligned.""" + aligned = True + cmd = ['WMIC', 'partition', 'get', 'StartingOffset'] + offsets = [] + + # Get offsets + result = run_program(cmd, encoding='utf-8', errors='ignore', check=False) + offsets = result.stdout.splitlines() + + # Check offsets + for off in offsets: + off = off.strip() + if not off.isnumeric(): + # Skip + continue + + try: + aligned = aligned and int(off) % 4096 == 0 + except ValueError: + # Ignore, this check is low priority + pass + + # Show alert + if show_alert: + show_alert_box('One or more partitions are not 4K aligned') + raise Not4KAlignedError + + def check_connection(): """Check if the system is online and optionally abort the script.""" while True: From 2d3ccac369e214d787a11d4b71f45157c6e98c08 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 18:46:35 -0600 Subject: [PATCH 096/113] Updated convert_to_bytes and human_readable_size --- .bin/Scripts/functions/common.py | 52 ++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/.bin/Scripts/functions/common.py b/.bin/Scripts/functions/common.py index 9db75814..99b7b662 100644 --- a/.bin/Scripts/functions/common.py +++ b/.bin/Scripts/functions/common.py @@ -167,18 +167,22 @@ def clear_screen(): def convert_to_bytes(size): """Convert human-readable size str to bytes and return an int.""" size = str(size) - tmp = re.search(r'(\d+\.?\d*)\s+([KMGT]B)', size.upper()) + tmp = re.search(r'(\d+\.?\d*)\s+([PTGMKB])B?', size.upper()) if tmp: size = float(tmp.group(1)) units = tmp.group(2) - if units == 'TB': - size *= 1099511627776 - elif units == 'GB': - size *= 1073741824 - elif units == 'MB': - size *= 1048576 - elif units == 'KB': - size *= 1024 + if units == 'P': + size *= 1024 ** 5 + if units == 'T': + size *= 1024 ** 4 + elif units == 'G': + size *= 1024 ** 3 + elif units == 'M': + size *= 1024 ** 2 + elif units == 'K': + size *= 1024 ** 1 + elif units == 'B': + size *= 1024 ** 0 size = int(size) else: return -1 @@ -297,20 +301,24 @@ def human_readable_size(size, decimals=0): return '{size:>{width}} b'.format(size='???', width=width) # Convert to sensible units - if size >= 1099511627776: - size /= 1099511627776 - units = 'Tb' - elif size >= 1073741824: - size /= 1073741824 - units = 'Gb' - elif size >= 1048576: - size /= 1048576 - units = 'Mb' - elif size >= 1024: - size /= 1024 - units = 'Kb' + if size >= 1024 ** 5: + size /= 1024 ** 5 + units = 'PB' + elif size >= 1024 ** 4: + size /= 1024 ** 4 + units = 'TB' + elif size >= 1024 ** 3: + size /= 1024 ** 3 + units = 'GB' + elif size >= 1024 ** 2: + size /= 1024 ** 2 + units = 'MB' + elif size >= 1024 ** 1: + size /= 1024 ** 1 + units = 'KB' else: - units = ' b' + size /= 1024 ** 0 + units = ' B' # Return return '{size:>{width}.{decimals}f} {units}'.format( From b83f2b0c5ff6a8f2e18bf5d6cde1c52662dbdc26 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 18:48:03 -0600 Subject: [PATCH 097/113] Updated pause() --- .bin/Scripts/functions/common.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bin/Scripts/functions/common.py b/.bin/Scripts/functions/common.py index 99b7b662..2828bcb4 100644 --- a/.bin/Scripts/functions/common.py +++ b/.bin/Scripts/functions/common.py @@ -433,6 +433,8 @@ def non_clobber_rename(full_path): def pause(prompt='Press Enter to continue... '): """Simple pause implementation.""" + if prompt[-1] != ' ': + prompt += ' ' input(prompt) From 576cb29281ed3e900f8a84b7aa3515d101a02e10 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 18:57:07 -0600 Subject: [PATCH 098/113] Updated settings.setup.py --- .bin/Scripts/settings/setup.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/.bin/Scripts/settings/setup.py b/.bin/Scripts/settings/setup.py index 232e3a0d..dd875992 100644 --- a/.bin/Scripts/settings/setup.py +++ b/.bin/Scripts/settings/setup.py @@ -1,13 +1,19 @@ -# Wizard Kit: Settings - Setup +'''Wizard Kit: Settings - Setup''' +# pylint: disable=bad-continuation,line-too-long +# vim: sts=2 sw=2 ts=2 import os -import winreg +try: + import winreg + HKU = winreg.HKEY_USERS + HKCR = winreg.HKEY_CLASSES_ROOT + HKCU = winreg.HKEY_CURRENT_USER + HKLM = winreg.HKEY_LOCAL_MACHINE +except ImportError: + if os.name != 'posix': + raise # General -HKU = winreg.HKEY_USERS -HKCR = winreg.HKEY_CLASSES_ROOT -HKCU = winreg.HKEY_CURRENT_USER -HKLM = winreg.HKEY_LOCAL_MACHINE OTHER_RESULTS = { 'Error': { 'CalledProcessError': 'Unknown Error', @@ -92,6 +98,15 @@ SETTINGS_EXPLORER_SYSTEM = { }, } SETTINGS_EXPLORER_USER = { + # Desktop theme + r'Software\Microsoft\Windows\CurrentVersion\Themes\Personalize': { + 'Invalid modes': ['Cur'], + 'DWORD Items': { + # <= v1809 default + 'AppsUseLightTheme': 1, + 'SystemUsesLightTheme': 0, + }, + }, # Disable features r'Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager': { 'DWORD Items': { @@ -104,6 +119,7 @@ SETTINGS_EXPLORER_USER = { }, # File Explorer r'Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced': { + 'Invalid modes': ['Cur'], 'DWORD Items': { # Change default Explorer view to "Computer" 'LaunchTo': 1, @@ -157,5 +173,3 @@ SETTINGS_WINDOWS_UPDATES = { if __name__ == '__main__': print("This file is not meant to be called directly.") - -# vim: sts=2 sw=2 ts=2 From 6a821de0b56c5b4fc8b1a0c10c56ba2a6a993273 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 18:58:24 -0600 Subject: [PATCH 099/113] Added LibreOffice settings --- .bin/Scripts/settings/setup.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.bin/Scripts/settings/setup.py b/.bin/Scripts/settings/setup.py index dd875992..215f56e2 100644 --- a/.bin/Scripts/settings/setup.py +++ b/.bin/Scripts/settings/setup.py @@ -135,6 +135,16 @@ SETTINGS_EXPLORER_USER = { }, } +# LibreOffice +LIBREOFFICE_XCU_DATA = ''' + +Impress MS PowerPoint 2007 XML +Calc MS Excel 2007 XML +MS Word 2007 XML +false + +''' + # Visual C++ Runtimes VCR_REDISTS = [ {'Name': 'Visual C++ 2010 x32...', From 434bb977655e145253f775b7cac90a99e9ba530a Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 19:01:21 -0600 Subject: [PATCH 100/113] Updated sw_diags.py --- .bin/Scripts/functions/sw_diags.py | 62 ++++++++++++++++-------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/.bin/Scripts/functions/sw_diags.py b/.bin/Scripts/functions/sw_diags.py index b122528a..1c5b943f 100644 --- a/.bin/Scripts/functions/sw_diags.py +++ b/.bin/Scripts/functions/sw_diags.py @@ -48,6 +48,37 @@ def check_connection(): abort() +def check_os_support_status(): + """Check if current OS is supported.""" + msg = '' + outdated = False + unsupported = False + + # Check OS version/notes + os_info = global_vars['OS'].copy() + if os_info['Notes'] == 'unsupported': + msg = 'The installed version of Windows is no longer supported' + unsupported = True + elif os_info['Notes'] == 'preview build': + msg = 'Preview builds are not officially supported' + unsupported = True + elif os_info['Version'] == '10' and os_info['Notes'] == 'outdated': + msg = 'The installed version of Windows is outdated' + outdated = True + if 'Preview' not in msg: + msg += '\n\nPlease consider upgrading before continuing setup.' + + # Show alert + if outdated or unsupported: + show_alert_box(msg) + + # Raise exception if necessary + if outdated: + raise WindowsOutdatedError + if unsupported: + raise WindowsUnsupportedError + + def check_secure_boot_status(show_alert=False): """Checks UEFI Secure Boot status via PowerShell.""" boot_mode = get_boot_mode() @@ -110,33 +141,6 @@ def get_boot_mode(): return type_str -def os_is_unsupported(show_alert=False): - """Checks if the current OS is unsupported, returns bool.""" - msg = '' - unsupported = False - - # Check OS version/notes - os_info = global_vars['OS'].copy() - if os_info['Notes'] == 'unsupported': - msg = 'The installed version of Windows is no longer supported' - unsupported = True - elif os_info['Notes'] == 'preview build': - msg = 'Preview builds are not officially supported' - unsupported = True - elif os_info['Version'] == '10' and os_info['Notes'] == 'outdated': - msg = 'The installed version of Windows is outdated' - unsupported = True - if 'Preview' not in msg: - msg += '\n\nPlease consider upgrading before continuing setup.' - - # Show alert - if unsupported and show_alert: - show_alert_box(msg) - - # Done - return unsupported - - def run_autoruns(): """Run AutoRuns in the background with VirusTotal checks enabled.""" extract_item('Autoruns', filter='autoruns*', silent=True) @@ -226,8 +230,10 @@ def run_rkill(): shutil.move(item.path, dest) -def show_alert_box(message, title='Wizard Kit Warning'): +def show_alert_box(message, title=None): """Show Windows alert box with message.""" + if not title: + title = '{} Warning'.format(KIT_NAME_FULL) message_box = ctypes.windll.user32.MessageBoxW message_box(None, message, title, 0x00001030) From 7a67e683085c36f403d7ae6adea7acd3e68624fe Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 19:07:37 -0600 Subject: [PATCH 101/113] Updated install_sw_bundle --- .bin/Scripts/install_sw_bundle.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.bin/Scripts/install_sw_bundle.py b/.bin/Scripts/install_sw_bundle.py index b536fd64..2979362e 100644 --- a/.bin/Scripts/install_sw_bundle.py +++ b/.bin/Scripts/install_sw_bundle.py @@ -25,7 +25,6 @@ if __name__ == '__main__': 'UnsupportedOSError': 'Unsupported OS', }} answer_extensions = ask('Install Extensions?') - answer_adobe_reader = ask('Install Adobe Reader?') answer_vcr = ask('Install Visual C++ Runtimes?') answer_ninite = ask('Install Ninite Bundle?') if answer_ninite and global_vars['OS']['Version'] in ['7']: @@ -35,9 +34,6 @@ if __name__ == '__main__': answer_mse = False print_info('Installing Programs') - if answer_adobe_reader: - try_and_print(message='Adobe Reader DC...', - function=install_adobe_reader, other_results=other_results) if answer_vcr: install_vcredists() if answer_ninite: From c4ad9055d4a0b4f44a2c66e05d5d27f3e4ac79ce Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 19:14:36 -0600 Subject: [PATCH 102/113] Launch Explorer windows in separate process --- .bin/Scripts/settings/setup.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.bin/Scripts/settings/setup.py b/.bin/Scripts/settings/setup.py index 215f56e2..c11073ec 100644 --- a/.bin/Scripts/settings/setup.py +++ b/.bin/Scripts/settings/setup.py @@ -125,6 +125,13 @@ SETTINGS_EXPLORER_USER = { 'LaunchTo': 1, }, }, + r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced': { + # Dup path so it Will be applied to all modes + 'DWORD Items': { + # Launch Folder Windows in a Separate Process + 'SeparateProcess': 1, + }, + }, # Hide People bar r'Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People': { 'DWORD Items': {'PeopleBand': 0}, From 248e321438619899a65a999b7e17dfdac8b1530b Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 19:16:25 -0600 Subject: [PATCH 103/113] Updated windows_builds --- .bin/Scripts/settings/windows_builds.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.bin/Scripts/settings/windows_builds.py b/.bin/Scripts/settings/windows_builds.py index db538bf2..f7481294 100644 --- a/.bin/Scripts/settings/windows_builds.py +++ b/.bin/Scripts/settings/windows_builds.py @@ -1,8 +1,10 @@ -# Wizard Kit: Settings - Windows Builds +'''Wizard Kit: Settings - Windows Builds''' +# pylint: disable=bad-continuation,bad-whitespace +# vim: sts=2 sw=2 ts=2 +## NOTE: Data from here: https://en.wikipedia.org/wiki/Windows_10_version_history WINDOWS_BUILDS = { # Build, Version, Release, Codename, Marketing Name, Notes - '6000': ('Vista', 'RTM', 'Longhorn', None, 'unsupported'), '6000': ('Vista', 'RTM', 'Longhorn', None, 'unsupported'), '6001': ('Vista', 'SP1', 'Longhorn', None, 'unsupported'), '6002': ('Vista', 'SP2', 'Longhorn', None, 'unsupported'), @@ -202,15 +204,22 @@ WINDOWS_BUILDS = { '18356': ('10', None, '19H1', None, 'preview build'), '18358': ('10', None, '19H1', None, 'preview build'), '18361': ('10', None, '19H1', None, 'preview build'), + '18362': ('10', 'v1903', '19H1', 'May 2019 Update', None), '18836': ('10', None, '20H1', None, 'preview build'), '18841': ('10', None, '20H1', None, 'preview build'), '18845': ('10', None, '20H1', None, 'preview build'), '18850': ('10', None, '20H1', None, 'preview build'), '18855': ('10', None, '20H1', None, 'preview build'), + '18860': ('10', None, '20H1', None, 'preview build'), + '18865': ('10', None, '20H1', None, 'preview build'), + '18875': ('10', None, '20H1', None, 'preview build'), + '18885': ('10', None, '20H1', None, 'preview build'), + '18890': ('10', None, '20H1', None, 'preview build'), + '18894': ('10', None, '20H1', None, 'preview build'), + '18895': ('10', None, '20H1', None, 'preview build'), + '18898': ('10', None, '20H1', None, 'preview build'), } if __name__ == '__main__': print("This file is not meant to be called directly.") - -# vim: sts=2 sw=2 ts=2 From 52e4415b438a8a82c9c61c0aa83d3f0386c7cb8b Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 20:00:11 -0600 Subject: [PATCH 104/113] Updated ddrescue sections --- .bin/Scripts/functions/ddrescue.py | 534 ++++++++++++++++------------- .bin/Scripts/settings/ddrescue.py | 8 + 2 files changed, 303 insertions(+), 239 deletions(-) diff --git a/.bin/Scripts/functions/ddrescue.py b/.bin/Scripts/functions/ddrescue.py index 4e6f7809..463adf4d 100644 --- a/.bin/Scripts/functions/ddrescue.py +++ b/.bin/Scripts/functions/ddrescue.py @@ -1,25 +1,25 @@ -# Wizard Kit: Functions - ddrescue-tui +# pylint: disable=no-name-in-module,too-many-lines,wildcard-import +# vim: sts=2 sw=2 ts=2 +'''Wizard Kit: Functions - ddrescue-tui''' import datetime import pathlib -import psutil -import pytz import re -import signal import stat import time +from operator import itemgetter -from collections import OrderedDict +import pytz from functions.data import * from functions.hw_diags import * from functions.json import * from functions.tmux import * -from operator import itemgetter from settings.ddrescue import * # Clases class BaseObj(): + # pylint: disable=missing-docstring """Base object used by DevObj, DirObj, and ImageObj.""" def __init__(self, path): self.type = 'base' @@ -44,6 +44,7 @@ class BaseObj(): class BlockPair(): + # pylint: disable=too-many-instance-attributes """Object to track data and methods together for source and dest.""" def __init__(self, mode, source, dest): self.mode = mode @@ -60,9 +61,10 @@ class BlockPair(): if self.mode == 'clone': # Cloning self.dest_path = dest.path - self.map_path = '{pwd}/Clone_{prefix}.map'.format( - pwd=os.path.realpath(global_vars['Env']['PWD']), - prefix=source.prefix) + self.map_path = '{cwd}/Clone_{prefix}.map'.format( + cwd=os.path.realpath(os.getcwd()), + prefix=source.prefix, + ) else: # Imaging self.dest_path = '{path}/{prefix}.dd'.format( @@ -105,19 +107,19 @@ class BlockPair(): def load_map_data(self): """Load data from map file and set progress.""" map_data = read_map_file(self.map_path) - self.rescued_percent = map_data['rescued'] - self.rescued = (self.rescued_percent * self.size) / 100 + self.rescued = map_data.get('rescued', 0) + self.rescued_percent = (self.rescued / self.size) * 100 if map_data['full recovery']: self.pass_done = [True, True, True] self.rescued = self.size self.status = ['Skipped', 'Skipped', 'Skipped'] - elif map_data['non-tried'] > 0: + elif map_data.get('non-tried', 0) > 0: # Initial pass incomplete pass - elif map_data['non-trimmed'] > 0: + elif map_data.get('non-trimmed', 0) > 0: self.pass_done = [True, False, False] self.status = ['Skipped', 'Pending', 'Pending'] - elif map_data['non-scraped'] > 0: + elif map_data.get('non-scraped', 0) > 0: self.pass_done = [True, True, False] self.status = ['Skipped', 'Skipped', 'Pending'] else: @@ -145,14 +147,15 @@ class BlockPair(): """Update progress using map file.""" if os.path.exists(self.map_path): map_data = read_map_file(self.map_path) - self.rescued_percent = map_data.get('rescued', 0) - self.rescued = (self.rescued_percent * self.size) / 100 + self.rescued = map_data.get('rescued', 0) + self.rescued_percent = (self.rescued / self.size) * 100 self.status[pass_num] = get_formatted_status( label='Pass {}'.format(pass_num+1), data=(self.rescued/self.size)*100) class DevObj(BaseObj): + # pylint: disable=too-many-instance-attributes """Block device object.""" def self_check(self): """Verify that self.path points to a block device.""" @@ -186,6 +189,7 @@ class DevObj(BaseObj): self.update_filename_prefix() def update_filename_prefix(self): + # pylint: disable=attribute-defined-outside-init """Set filename prefix based on details.""" self.prefix = '{m_size}_{model}'.format( m_size=self.model_size, @@ -205,6 +209,7 @@ class DevObj(BaseObj): class DirObj(BaseObj): + """Directory object.""" def self_check(self): """Verify that self.path points to a directory.""" if not pathlib.Path(self.path).is_dir(): @@ -222,6 +227,7 @@ class DirObj(BaseObj): class ImageObj(BaseObj): + """Image file object.""" def self_check(self): """Verify that self.path points to a file.""" if not pathlib.Path(self.path).is_file(): @@ -243,10 +249,11 @@ class ImageObj(BaseObj): self.report = get_device_report(self.loop_dev) self.report = self.report.replace( self.loop_dev[self.loop_dev.rfind('/')+1:], '(Img)') - run_program(['losetup', '--detach', self.loop_dev], check=False) + run_program(['sudo', 'losetup', '--detach', self.loop_dev], check=False) class RecoveryState(): + # pylint: disable=too-many-instance-attributes """Object to track BlockPair objects and overall state.""" def __init__(self, mode, source, dest): self.mode = mode.lower() @@ -270,6 +277,7 @@ class RecoveryState(): if mode not in ('clone', 'image'): raise GenericError('Unsupported mode') self.get_smart_source() + self.set_working_dir() def add_block_pair(self, source, dest): """Run safety checks and append new BlockPair to internal list.""" @@ -314,20 +322,134 @@ class RecoveryState(): # Safety checks passed self.block_pairs.append(BlockPair(self.mode, source, dest)) + def build_outer_panes(self): + """Build top and side panes.""" + clear_screen() + + # Top + self.panes['Source'] = tmux_split_window( + behind=True, vertical=True, lines=2, + text='{BLUE}Source{CLEAR}'.format(**COLORS)) + + # Started + self.panes['Started'] = tmux_split_window( + lines=SIDE_PANE_WIDTH, target_pane=self.panes['Source'], + text='{BLUE}Started{CLEAR}\n{s}'.format( + s=time.strftime("%Y-%m-%d %H:%M %Z"), + **COLORS)) + + # Destination + self.panes['Destination'] = tmux_split_window( + percent=50, target_pane=self.panes['Source'], + text='{BLUE}Destination{CLEAR}'.format(**COLORS)) + + # Progress + update_sidepane(self) + self.panes['Progress'] = tmux_split_window( + lines=SIDE_PANE_WIDTH, watch=self.progress_out) + def current_pass_done(self): """Checks if pass is done for all block-pairs, returns bool.""" done = True - for bp in self.block_pairs: - done = done and bp.pass_done[self.current_pass] + for b_pair in self.block_pairs: + done = done and b_pair.pass_done[self.current_pass] return done def current_pass_min(self): """Gets minimum pass rescued percentage, returns float.""" min_percent = 100 - for bp in self.block_pairs: - min_percent = min(min_percent, bp.rescued_percent) + for b_pair in self.block_pairs: + min_percent = min(min_percent, b_pair.rescued_percent) return min_percent + def fix_tmux_panes(self, forced=False): + # pylint: disable=too-many-branches,too-many-locals + """Fix pane sizes if the winodw has been resized.""" + needs_fixed = False + + # Check layout + for pane, pane_data in TMUX_LAYOUT.items(): + if not pane_data.get('Check'): + # Not concerned with the size of this pane + continue + # Get target + target = None + if pane != 'Current': + if pane not in self.panes: + # Skip missing panes + continue + else: + target = self.panes[pane] + + # Check pane size + size_x, size_y = tmux_get_pane_size(pane_id=target) + if pane_data.get('x', False) and pane_data['x'] != size_x: + needs_fixed = True + if pane_data.get('y', False) and pane_data['y'] != size_y: + needs_fixed = True + + # Bail? + if not needs_fixed and not forced: + return + + # Remove Destination pane (temporarily) + tmux_kill_pane(self.panes['Destination']) + + # Update layout + for pane, pane_data in TMUX_LAYOUT.items(): + # Get target + target = None + if pane != 'Current': + if pane not in self.panes: + # Skip missing panes + continue + else: + target = self.panes[pane] + + # Resize pane + tmux_resize_pane(pane_id=target, **pane_data) + + # Calc Source/Destination pane sizes + width, height = tmux_get_pane_size() + width = int(width / 2) - 1 + + # Update Source string + source_str = self.source.name + if len(source_str) > width: + source_str = '{}...'.format(source_str[:width-3]) + + # Update Destination string + dest_str = self.dest.name + if len(dest_str) > width: + if self.mode == 'clone': + dest_str = '{}...'.format(dest_str[:width-3]) + else: + dest_str = '...{}'.format(dest_str[-width+3:]) + + # Rebuild Source/Destination panes + tmux_update_pane( + pane_id=self.panes['Source'], + text='{BLUE}Source{CLEAR}\n{s}'.format( + s=source_str, **COLORS)) + self.panes['Destination'] = tmux_split_window( + percent=50, target_pane=self.panes['Source'], + text='{BLUE}Destination{CLEAR}\n{s}'.format( + s=dest_str, **COLORS)) + + if 'SMART' in self.panes: + # Calc SMART/ddrescue/Journal panes sizes + ratio = [12, 22, 4] + width, height = tmux_get_pane_size(pane_id=self.panes['Progress']) + height -= 2 + total = sum(ratio) + p_ratio = [int((x/total) * height) for x in ratio] + p_ratio[1] = height - p_ratio[0] - p_ratio[2] + + # Resize SMART/Journal panes + tmux_resize_pane(self.panes['SMART'], y=ratio[0]) + tmux_resize_pane(y=ratio[1]) + tmux_resize_pane(self.panes['Journal'], y=ratio[2]) + def get_smart_source(self): """Get source for SMART dispay.""" disk_path = self.source.path @@ -339,18 +461,15 @@ class RecoveryState(): def retry_all_passes(self): """Mark all passes as pending for all block-pairs.""" self.finished = False - for bp in self.block_pairs: - bp.pass_done = [False, False, False] - bp.status = ['Pending', 'Pending', 'Pending'] - bp.fix_status_strings() + for b_pair in self.block_pairs: + b_pair.pass_done = [False, False, False] + b_pair.status = ['Pending', 'Pending', 'Pending'] + b_pair.fix_status_strings() self.set_pass_num() def self_checks(self): """Run self-checks and update state values.""" cmd = ['findmnt', '--json', '--target', os.getcwd()] - map_allowed_fstypes = RECOMMENDED_FSTYPES.copy() - map_allowed_fstypes.extend(['cifs', 'ext2', 'vfat']) - map_allowed_fstypes.sort() json_data = get_json_from_command(cmd) # Abort if json_data is empty @@ -361,24 +480,24 @@ class RecoveryState(): # Avoid saving map to non-persistent filesystem fstype = json_data.get( 'filesystems', [{}])[0].get( - 'fstype', 'unknown') - if fstype not in map_allowed_fstypes: + 'fstype', 'unknown') + if fstype not in RECOMMENDED_MAP_FSTYPES: print_error( "Map isn't being saved to a recommended filesystem ({})".format( fstype.upper())) print_info('Recommended types are: {}'.format( - ' / '.join(map_allowed_fstypes).upper())) + ' / '.join(RECOMMENDED_MAP_FSTYPES).upper())) print_standard(' ') if not ask('Proceed anyways? (Strongly discouraged)'): raise GenericAbort() # Run BlockPair self checks and get total size self.total_size = 0 - for bp in self.block_pairs: - bp.self_check() - if bp.resumed: + for b_pair in self.block_pairs: + b_pair.self_check() + if b_pair.resumed: self.resumed = True - self.total_size += bp.size + self.total_size += b_pair.size def set_pass_num(self): """Set current pass based on all block-pair's progress.""" @@ -386,8 +505,8 @@ class RecoveryState(): for pass_num in (2, 1, 0): # Iterate backwards through passes pass_done = True - for bp in self.block_pairs: - pass_done = pass_done and bp.pass_done[pass_num] + for b_pair in self.block_pairs: + pass_done = pass_done and b_pair.pass_done[pass_num] if pass_done: # All block-pairs reported being done # Set to next pass, unless we're on the last pass (2) @@ -405,6 +524,34 @@ class RecoveryState(): elif self.current_pass == 2: self.current_pass_str = '3 "Scraping bad areas"' + def set_working_dir(self): + # pylint: disable=no-self-use + """Set working dir to MAP_DIR if possible. + + NOTE: This is to help ensure the map file + is saved to non-volatile storage.""" + map_dir = '{}/{}'.format(MAP_DIR, global_vars['Date-Time']) + + # Mount backup shares + mount_backup_shares(read_write=True) + + # Get MAP_DIR filesystem type + # NOTE: If the backup share fails to mount then this will + # likely be the type of / + cmd = [ + 'findmnt', + '--noheadings', + '--target', MAP_DIR, + '--output', 'FSTYPE', + ] + result = run_program(cmd, check=False, encoding='utf-8', errors='ingnore') + map_dir_type = result.stdout.strip().lower() + + # Change working dir if map_dir_type is acceptable + if map_dir_type in RECOMMENDED_MAP_FSTYPES: + os.makedirs(map_dir, exist_ok=True) + os.chdir(map_dir) + def update_etoc(self): """Search ddrescue output for the current EToC, returns str.""" now = datetime.datetime.now(tz=self.timezone) @@ -414,7 +561,7 @@ class RecoveryState(): # Just set to N/A (NOTE: this overrules the refresh rate below) self.etoc = 'N/A' return - elif 'In Progress' not in self.status: + if 'In Progress' not in self.status: # Don't update when EToC is hidden return if now.second % ETOC_REFRESH_RATE != 0: @@ -428,13 +575,14 @@ class RecoveryState(): # Capture main tmux pane try: text = tmux_capture_pane() - except Exception: + except Exception: # pylint: disable=broad-except # Ignore pass # Search for EToC delta matches = re.findall(r'remaining time:.*$', text, re.MULTILINE) if matches: + # pylint: disable=invalid-name r = REGEX_REMAINING_TIME.search(matches[-1]) if r.group('na'): self.etoc = 'N/A' @@ -451,7 +599,7 @@ class RecoveryState(): minutes=int(minutes), seconds=int(seconds), ) - except Exception: + except Exception: # pylint: disable=broad-except # Ignore and leave as raw string pass @@ -461,15 +609,16 @@ class RecoveryState(): now = datetime.datetime.now(tz=self.timezone) _etoc = now + etoc_delta self.etoc = _etoc.strftime('%Y-%m-%d %H:%M %Z') - except Exception: + except Exception: # pylint: disable=broad-except # Ignore and leave as current string pass def update_progress(self): + # pylint: disable=attribute-defined-outside-init """Update overall progress using block_pairs.""" self.rescued = 0 - for bp in self.block_pairs: - self.rescued += bp.rescued + for b_pair in self.block_pairs: + self.rescued += b_pair.rescued self.rescued_percent = (self.rescued / self.total_size) * 100 self.status_percent = get_formatted_status( label='Recovered:', data=self.rescued_percent) @@ -478,26 +627,6 @@ class RecoveryState(): # Functions -def build_outer_panes(state): - """Build top and side panes.""" - state.panes['Source'] = tmux_split_window( - behind=True, vertical=True, lines=2, - text='{BLUE}Source{CLEAR}'.format(**COLORS)) - state.panes['Started'] = tmux_split_window( - lines=SIDE_PANE_WIDTH, target_pane=state.panes['Source'], - text='{BLUE}Started{CLEAR}\n{s}'.format( - s=time.strftime("%Y-%m-%d %H:%M %Z"), - **COLORS)) - state.panes['Destination'] = tmux_split_window( - percent=50, target_pane=state.panes['Source'], - text='{BLUE}Destination{CLEAR}'.format(**COLORS)) - - # Side pane - update_sidepane(state) - state.panes['Progress'] = tmux_split_window( - lines=SIDE_PANE_WIDTH, watch=state.progress_out) - - def create_path_obj(path): """Create Dev, Dir, or Image obj based on path given.""" obj = None @@ -515,101 +644,16 @@ def create_path_obj(path): def double_confirm_clone(): """Display warning and get 2nd confirmation, returns bool.""" print_standard('\nSAFETY CHECK') - print_warning('All data will be DELETED from the ' - 'destination device and partition(s) listed above.') - print_warning('This is irreversible and will lead ' - 'to {CLEAR}{RED}DATA LOSS.'.format(**COLORS)) + print_warning( + 'All data will be DELETED from the ' + 'destination device and partition(s) listed above.' + ) + print_warning( + 'This is irreversible and will lead to {CLEAR}{RED}DATA LOSS.'.format( + **COLORS)) return ask('Asking again to confirm, is this correct?') -def fix_tmux_panes(state, forced=False): - """Fix pane sizes if the winodw has been resized.""" - needs_fixed = False - - # Check layout - for k, v in TMUX_LAYOUT.items(): - if not v.get('Check'): - # Not concerned with the size of this pane - continue - # Get target - target = None - if k != 'Current': - if k not in state.panes: - # Skip missing panes - continue - else: - target = state.panes[k] - - # Check pane size - x, y = tmux_get_pane_size(pane_id=target) - if v.get('x', False) and v['x'] != x: - needs_fixed = True - if v.get('y', False) and v['y'] != y: - needs_fixed = True - - # Bail? - if not needs_fixed and not forced: - return - - # Remove Destination pane (temporarily) - tmux_kill_pane(state.panes['Destination']) - - # Update layout - for k, v in TMUX_LAYOUT.items(): - # Get target - target = None - if k != 'Current': - if k not in state.panes: - # Skip missing panes - continue - else: - target = state.panes[k] - - # Resize pane - tmux_resize_pane(pane_id=target, **v) - - # Calc Source/Destination pane sizes - width, height = tmux_get_pane_size() - width = int(width / 2) - 1 - - # Update Source string - source_str = state.source.name - if len(source_str) > width: - source_str = '{}...'.format(source_str[:width-3]) - - # Update Destination string - dest_str = state.dest.name - if len(dest_str) > width: - if state.mode == 'clone': - dest_str = '{}...'.format(dest_str[:width-3]) - else: - dest_str = '...{}'.format(dest_str[-width+3:]) - - # Rebuild Source/Destination panes - tmux_update_pane( - pane_id=state.panes['Source'], - text='{BLUE}Source{CLEAR}\n{s}'.format( - s=source_str, **COLORS)) - state.panes['Destination'] = tmux_split_window( - percent=50, target_pane=state.panes['Source'], - text='{BLUE}Destination{CLEAR}\n{s}'.format( - s=dest_str, **COLORS)) - - if 'SMART' in state.panes: - # Calc SMART/ddrescue/Journal panes sizes - ratio = [12, 22, 4] - width, height = tmux_get_pane_size(pane_id=state.panes['Progress']) - height -= 2 - total = sum(ratio) - p_ratio = [int((x/total) * height) for x in ratio] - p_ratio[1] = height - p_ratio[0] - p_ratio[2] - - # Resize SMART/Journal panes - tmux_resize_pane(state.panes['SMART'], y=ratio[0]) - tmux_resize_pane(y=ratio[1]) - tmux_resize_pane(state.panes['Journal'], y=ratio[2]) - - def get_device_details(dev_path): """Get device details via lsblk, returns JSON dict.""" cmd = ['lsblk', '--json', '--output-all', '--paths', dev_path] @@ -678,22 +722,22 @@ def get_dir_report(dir_path): output.append('{BLUE}{label:<{width}}{line}{CLEAR}'.format( label='PATH', width=width, - line=line.replace('\n',''), + line=line.replace('\n', ''), **COLORS)) else: output.append('{path:<{width}}{line}'.format( path=dir_path, width=width, - line=line.replace('\n',''))) + line=line.replace('\n', ''))) # Done return '\n'.join(output) -def get_size_in_bytes(s): +def get_size_in_bytes(size): """Convert size string from lsblk string to bytes, returns int.""" - s = re.sub(r'(\d+\.?\d*)\s*([KMGTB])B?', r'\1 \2B', s, re.IGNORECASE) - return convert_to_bytes(s) + size = re.sub(r'(\d+\.?\d*)\s*([KMGTB])B?', r'\1 \2B', size, re.IGNORECASE) + return convert_to_bytes(size) def get_formatted_status(label, data): @@ -701,13 +745,15 @@ def get_formatted_status(label, data): data_width = SIDE_PANE_WIDTH - len(label) try: data_str = '{data:>{data_width}.2f} %'.format( - data=data, - data_width=data_width-2) + data=data, + data_width=data_width-2, + ) except ValueError: # Assuming non-numeric data data_str = '{data:>{data_width}}'.format( - data=data, - data_width=data_width) + data=data, + data_width=data_width, + ) status = '{label}{s_color}{data_str}{CLEAR}'.format( label=label, s_color=get_status_color(data), @@ -716,19 +762,19 @@ def get_formatted_status(label, data): return status -def get_status_color(s, t_success=99, t_warn=90): +def get_status_color(status, t_success=99, t_warn=90): """Get color based on status, returns str.""" color = COLORS['CLEAR'] p_recovered = -1 try: - p_recovered = float(s) + p_recovered = float(status) except ValueError: # Status is either in lists below or will default to red pass - if s in ('Pending',) or str(s)[-2:] in (' b', 'Kb', 'Mb', 'Gb', 'Tb'): + if status == 'Pending' or str(status)[-2:] in (' b', 'Kb', 'Mb', 'Gb', 'Tb'): color = COLORS['CLEAR'] - elif s in ('Skipped', 'Unknown'): + elif status in ('Skipped', 'Unknown'): color = COLORS['YELLOW'] elif p_recovered >= t_success: color = COLORS['GREEN'] @@ -755,6 +801,7 @@ def is_writable_filesystem(dir_obj): def menu_ddrescue(source_path, dest_path, run_mode): + # pylint: disable=too-many-branches """ddrescue menu.""" source = None dest = None @@ -798,9 +845,8 @@ def menu_ddrescue(source_path, dest_path, run_mode): raise GenericAbort() # Main menu - clear_screen() - build_outer_panes(state) - fix_tmux_panes(state, forced=True) + state.build_outer_panes() + state.fix_tmux_panes(forced=True) menu_main(state) # Done @@ -809,6 +855,7 @@ def menu_ddrescue(source_path, dest_path, run_mode): def menu_main(state): + # pylint: disable=too-many-branches,too-many-statements """Main menu is used to set ddrescue settings.""" checkmark = '*' if 'DISPLAY' in global_vars['Env']: @@ -819,16 +866,15 @@ def menu_main(state): # Build menu main_options = [ {'Base Name': 'Auto continue (if recovery % over threshold)', - 'Enabled': True}, + 'Enabled': True}, {'Base Name': 'Retry (mark non-rescued sectors "non-tried")', - 'Enabled': False}, + 'Enabled': False}, {'Base Name': 'Reverse direction', 'Enabled': False}, ] actions = [ {'Name': 'Start', 'Letter': 'S'}, - {'Name': 'Change settings {YELLOW}(experts only){CLEAR}'.format( - **COLORS), - 'Letter': 'C'}, + {'Name': 'Change settings {YELLOW}(experts only){CLEAR}'.format(**COLORS), + 'Letter': 'C'}, {'Name': 'Quit', 'Letter': 'Q', 'CRLF': True}, ] @@ -859,13 +905,13 @@ def menu_main(state): elif selection == 'S': # Set settings for pass pass_settings = [] - for k, v in state.settings.items(): - if not v['Enabled']: + for option, option_data in state.settings.items(): + if not option_data['Enabled']: continue - if 'Value' in v: - pass_settings.append('{}={}'.format(k, v['Value'])) + if 'Value' in option_data: + pass_settings.append('{}={}'.format(option, option_data['Value'])) else: - pass_settings.append(k) + pass_settings.append(option) for opt in main_options: if 'Auto' in opt['Base Name']: auto_run = opt['Enabled'] @@ -888,7 +934,7 @@ def menu_main(state): state.current_pass_min() < AUTO_PASS_1_THRESHOLD): auto_run = False elif (state.current_pass == 1 and - state.current_pass_min() < AUTO_PASS_2_THRESHOLD): + state.current_pass_min() < AUTO_PASS_2_THRESHOLD): auto_run = False else: auto_run = False @@ -917,13 +963,15 @@ def menu_settings(state): # Build menu settings = [] - for k, v in sorted(state.settings.items()): - if not v.get('Hidden', False): - settings.append({'Base Name': k, 'Flag': k}) + for option, option_data in sorted(state.settings.items()): + if not option_data.get('Hidden', False): + settings.append({'Base Name': option, 'Flag': option}) actions = [{'Name': 'Main Menu', 'Letter': 'M'}] # Show menu while True: + # pylint: disable=invalid-name + # TODO: Clean up and/or replace with new menu-select function for s in settings: s['Name'] = '{}{}{}'.format( s['Base Name'], @@ -960,25 +1008,27 @@ def menu_settings(state): def read_map_file(map_path): """Read map file with ddrescuelog and return data as dict.""" - map_data = {'full recovery': False} + cmd = [ + 'ddrescuelog', + '--binary-prefixes', + '--show-status', + map_path, + ] + map_data = {'full recovery': False, 'pass completed': False} try: - result = run_program(['ddrescuelog', '-t', map_path]) + result = run_program(cmd, encoding='utf-8', errors='ignore') except CalledProcessError: # (Grossly) assuming map_data hasn't been saved yet, return empty dict return map_data # Parse output - for line in result.stdout.decode().splitlines(): - m = re.match( - r'^\s*(?P\S+):.*\(\s*(?P\d+\.?\d*)%.*', line.strip()) - if m: - try: - map_data[m.group('key')] = float(m.group('value')) - except ValueError: - raise GenericError('Failed to read map data') - m = re.match(r'.*current status:\s+(?P.*)', line.strip()) - if m: - map_data['pass completed'] = bool(m.group('status') == 'finished') + for line in result.stdout.splitlines(): + line = line.strip() + _r = REGEX_DDRESCUE_LOG.search(line) + if _r: + map_data[_r.group('key')] = convert_to_bytes('{size} {unit}B'.format( + **_r.groupdict())) + map_data['pass completed'] = 'current status: finished' in line # Check if 100% done try: @@ -992,6 +1042,7 @@ def read_map_file(map_path): def run_ddrescue(state, pass_settings): + # pylint: disable=too-many-branches,too-many-statements """Run ddrescue pass.""" return_code = -1 aborted = False @@ -1006,8 +1057,8 @@ def run_ddrescue(state, pass_settings): # Create SMART monitor pane state.smart_out = '{}/smart_{}.out'.format( global_vars['TmpDir'], state.smart_source.name) - with open(state.smart_out, 'w') as f: - f.write('Initializing...') + with open(state.smart_out, 'w') as _f: + _f.write('Initializing...') state.panes['SMART'] = tmux_split_window( behind=True, lines=12, vertical=True, watch=state.smart_out) @@ -1017,19 +1068,19 @@ def run_ddrescue(state, pass_settings): command=['sudo', 'journalctl', '-f']) # Fix layout - fix_tmux_panes(state, forced=True) + state.fix_tmux_panes(forced=True) # Run pass for each block-pair - for bp in state.block_pairs: - if bp.pass_done[state.current_pass]: + for b_pair in state.block_pairs: + if b_pair.pass_done[state.current_pass]: # Skip to next block-pair continue update_sidepane(state) # Set ddrescue cmd cmd = [ - 'ddrescue', *pass_settings, - bp.source_path, bp.dest_path, bp.map_path] + 'sudo', 'ddrescue', *pass_settings, + b_pair.source_path, b_pair.dest_path, b_pair.map_path] if state.mode == 'clone': cmd.append('--force') if state.current_pass == 0: @@ -1044,36 +1095,36 @@ def run_ddrescue(state, pass_settings): # Start ddrescue try: clear_screen() - print_info('Current dev: {}'.format(bp.source_path)) + print_info('Current dev: {}'.format(b_pair.source_path)) ddrescue_proc = popen_program(cmd) i = 0 while True: # Update SMART display (every 30 seconds) if i % 30 == 0: state.smart_source.get_smart_details() - with open(state.smart_out, 'w') as f: + with open(state.smart_out, 'w') as _f: report = state.smart_source.generate_attribute_report( - timestamp=True) + timestamp=True) for line in report: - f.write('{}\n'.format(line)) + _f.write('{}\n'.format(line)) i += 1 # Update progress - bp.update_progress(state.current_pass) + b_pair.update_progress(state.current_pass) update_sidepane(state) # Fix panes - fix_tmux_panes(state) + state.fix_tmux_panes() # Check if ddrescue has finished try: ddrescue_proc.wait(timeout=1) sleep(2) - bp.update_progress(state.current_pass) + b_pair.update_progress(state.current_pass) update_sidepane(state) break except subprocess.TimeoutExpired: - # Catch to update smart/bp/sidepane + # Catch to update smart/b_pair/sidepane pass except KeyboardInterrupt: @@ -1082,7 +1133,7 @@ def run_ddrescue(state, pass_settings): ddrescue_proc.wait(timeout=10) # Update progress/sidepane again - bp.update_progress(state.current_pass) + b_pair.update_progress(state.current_pass) update_sidepane(state) # Was ddrescue aborted? @@ -1104,7 +1155,7 @@ def run_ddrescue(state, pass_settings): break else: # Mark pass finished - bp.finish_pass(state.current_pass) + b_pair.finish_pass(state.current_pass) update_sidepane(state) # Done @@ -1120,6 +1171,8 @@ def run_ddrescue(state, pass_settings): def select_parts(source_device): + # pylint: disable=too-many-branches + # TODO: Clean up and/or replace with new menu-select function """Select partition(s) or whole device, returns list of DevObj()s.""" selected_parts = [] children = source_device.details.get('children', []) @@ -1181,24 +1234,26 @@ def select_parts(source_device): raise GenericAbort() # Build list of selected parts - for d in dev_options: - if d['Selected']: - d['Dev'].model = source_device.model - d['Dev'].model_size = source_device.model_size - d['Dev'].update_filename_prefix() - selected_parts.append(d['Dev']) + for _d in dev_options: + if _d['Selected']: + _d['Dev'].model = source_device.model + _d['Dev'].model_size = source_device.model_size + _d['Dev'].update_filename_prefix() + selected_parts.append(_d['Dev']) return selected_parts def select_path(skip_device=None): + # pylint: disable=too-many-branches,too-many-locals + # TODO: Clean up and/or replace with new menu-select function """Optionally mount local dev and select path, returns DirObj.""" - wd = os.path.realpath(global_vars['Env']['PWD']) + work_dir = os.path.realpath(global_vars['Env']['PWD']) selected_path = None # Build menu path_options = [ - {'Name': 'Current directory: {}'.format(wd), 'Path': wd}, + {'Name': 'Current directory: {}'.format(work_dir), 'Path': work_dir}, {'Name': 'Local device', 'Path': None}, {'Name': 'Enter manually', 'Path': None}] actions = [{'Name': 'Quit', 'Letter': 'Q'}] @@ -1213,9 +1268,9 @@ def select_path(skip_device=None): raise GenericAbort() elif selection.isnumeric(): index = int(selection) - 1 - if path_options[index]['Path'] == wd: + if path_options[index]['Path'] == work_dir: # Current directory - selected_path = DirObj(wd) + selected_path = DirObj(work_dir) elif path_options[index]['Name'] == 'Local device': # Local device @@ -1231,15 +1286,15 @@ def select_path(skip_device=None): # Select volume vol_options = [] - for k, v in sorted(report.items()): - disabled = v['show_data']['data'] == 'Failed to mount' + for _k, _v in sorted(report.items()): + disabled = _v['show_data']['data'] == 'Failed to mount' if disabled: - name = '{name} (Failed to mount)'.format(**v) + name = '{name} (Failed to mount)'.format(**_v) else: - name = '{name} (mounted on "{mount_point}")'.format(**v) + name = '{name} (mounted on "{mount_point}")'.format(**_v) vol_options.append({ 'Name': name, - 'Path': v['mount_point'], + 'Path': _v['mount_point'], 'Disabled': disabled}) selection = menu_select( title='Please select a volume', @@ -1314,15 +1369,17 @@ def select_device(description='device', skip_device=None): action_entries=actions, disabled_label='ALREADY SELECTED') + if selection == 'Q': + raise GenericAbort() + if selection.isnumeric(): return dev_options[int(selection)-1]['Dev'] - elif selection == 'Q': - raise GenericAbort() def setup_loopback_device(source_path): """Setup loopback device for source_path, returns dev_path as str.""" cmd = ( + 'sudo', 'losetup', '--find', '--partscan', @@ -1356,6 +1413,7 @@ def show_selection_details(state): def show_usage(script_name): + """Show usage.""" print_info('Usage:') print_standard(USAGE.format(script_name=script_name)) pause() @@ -1379,14 +1437,14 @@ def update_sidepane(state): output.append('─────────────────────') # Source(s) progress - for bp in state.block_pairs: + for b_pair in state.block_pairs: if state.source.is_image(): output.append('{BLUE}Image File{CLEAR}'.format(**COLORS)) else: output.append('{BLUE}{source}{CLEAR}'.format( - source=bp.source_path, + source=b_pair.source_path, **COLORS)) - output.extend(bp.status) + output.extend(b_pair.status) output.append(' ') # EToC @@ -1405,11 +1463,9 @@ def update_sidepane(state): # Add line-endings output = ['{}\n'.format(line) for line in output] - with open(state.progress_out, 'w') as f: - f.writelines(output) + with open(state.progress_out, 'w') as _f: + _f.writelines(output) if __name__ == '__main__': print("This file is not meant to be called directly.") - -# vim: sts=2 sw=2 ts=2 diff --git a/.bin/Scripts/settings/ddrescue.py b/.bin/Scripts/settings/ddrescue.py index 675019ca..ffe6e215 100644 --- a/.bin/Scripts/settings/ddrescue.py +++ b/.bin/Scripts/settings/ddrescue.py @@ -5,7 +5,9 @@ import re from collections import OrderedDict # General +MAP_DIR = '/Backups/ddrescue-tui' RECOMMENDED_FSTYPES = ['ext3', 'ext4', 'xfs'] +RECOMMENDED_MAP_FSTYPES = ['cifs', 'ext2', 'ext3', 'ext4', 'vfat', 'xfs'] USAGE = """ {script_name} clone [source [destination]] {script_name} image [source [destination]] (e.g. {script_name} clone /dev/sda /dev/sdb) @@ -36,6 +38,12 @@ DDRESCUE_SETTINGS = { '-vvvv': {'Enabled': True, 'Hidden': True, }, } ETOC_REFRESH_RATE = 30 # in seconds +REGEX_DDRESCUE_LOG = re.compile( + r'^\s*(?P\S+):\s+' + r'(?P\d+)\s+' + r'(?P[PTGMKB])i?B?', + re.IGNORECASE, + ) REGEX_REMAINING_TIME = re.compile( r'remaining time:' r'\s*((?P\d+)d)?' From 28bedc0873ac973817ed40ca9c912e0a0197f015 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 20:01:26 -0600 Subject: [PATCH 105/113] Run ddrescue-tui as current user --- .linux_items/include/airootfs/etc/skel/.aliases | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.linux_items/include/airootfs/etc/skel/.aliases b/.linux_items/include/airootfs/etc/skel/.aliases index d6486258..b0068be3 100644 --- a/.linux_items/include/airootfs/etc/skel/.aliases +++ b/.linux_items/include/airootfs/etc/skel/.aliases @@ -34,5 +34,5 @@ alias srsz='sudo rsync -avhzPS --stats --exclude-from="$HOME/.rsync_exclusions"' alias testdisk='sudo testdisk' alias umount='sudo umount' alias unmount='sudo umount' -alias wkclone='sudo ddrescue-tui clone' -alias wkimage='sudo ddrescue-tui image' +alias wkclone='ddrescue-tui clone' +alias wkimage='ddrescue-tui image' From 606efac3fe96b05de7993506d2347605aa7c1a2b Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 20:09:56 -0600 Subject: [PATCH 106/113] Updated mounting sections --- .bin/Scripts/functions/data.py | 51 ++++++++++++++++++++++++++------ .bin/Scripts/mount-backup-shares | 3 -- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/.bin/Scripts/functions/data.py b/.bin/Scripts/functions/data.py index fa0bb20c..c359ab6c 100644 --- a/.bin/Scripts/functions/data.py +++ b/.bin/Scripts/functions/data.py @@ -151,12 +151,16 @@ def is_valid_wim_file(item): def get_mounted_volumes(): """Get mounted volumes, returns dict.""" cmd = [ - 'findmnt', '-J', '-b', '-i', - '-t', ( + 'findmnt', + '--list', + '--json', + '--bytes', + '--invert', + '--types', ( 'autofs,binfmt_misc,bpf,cgroup,cgroup2,configfs,debugfs,devpts,' 'devtmpfs,hugetlbfs,mqueue,proc,pstore,securityfs,sysfs,tmpfs' ), - '-o', 'SOURCE,TARGET,FSTYPE,LABEL,SIZE,AVAIL,USED'] + '--output', 'SOURCE,TARGET,FSTYPE,LABEL,SIZE,AVAIL,USED'] json_data = get_json_from_command(cmd) mounted_volumes = [] for item in json_data.get('filesystems', []): @@ -195,6 +199,8 @@ def mount_volumes( volumes.update({child['name']: child}) for grandchild in child.get('children', []): volumes.update({grandchild['name']: grandchild}) + for great_grandchild in grandchild.get('children', []): + volumes.update({great_grandchild['name']: great_grandchild}) # Get list of mounted volumes mounted_volumes = get_mounted_volumes() @@ -237,6 +243,7 @@ def mount_volumes( if vol_data['show_data']['data'] == 'Failed to mount': vol_data['mount_point'] = None else: + fstype = vol_data.get('fstype', 'UNKNOWN FS') size_used = human_readable_size( mounted_volumes[vol_path]['used'], decimals=1, @@ -250,8 +257,9 @@ def mount_volumes( vol_data['mount_point'] = mounted_volumes[vol_path]['target'] vol_data['show_data']['data'] = 'Mounted on {}'.format( mounted_volumes[vol_path]['target']) - vol_data['show_data']['data'] = '{:40} ({} used, {} free)'.format( + vol_data['show_data']['data'] = '{:40} ({}, {} used, {} free)'.format( vol_data['show_data']['data'], + fstype, size_used, size_avail) @@ -285,6 +293,14 @@ def mount_backup_shares(read_write=False): def mount_network_share(server, read_write=False): """Mount a network share defined by server.""" + uid = '1000' + + # Get UID + cmd = ['id', '--user', 'tech'] + result = run_program(cmd, check=False, encoding='utf-8', errors='ignore') + if result.stdout.strip().isnumeric(): + uid = result.stdout.strip() + if read_write: username = server['RW-User'] password = server['RW-Pass'] @@ -300,18 +316,35 @@ def mount_network_share(server, read_write=False): error = r'Failed to mount \\{Name}\{Share} ({IP})'.format(**server) success = 'Mounted {Name}'.format(**server) elif psutil.LINUX: + # Make mountpoint cmd = [ 'sudo', 'mkdir', '-p', '/Backups/{Name}'.format(**server)] run_program(cmd) + + # Set mount options + cmd_options = [ + # Assuming GID matches UID + 'gid={}'.format(uid), + 'uid={}'.format(uid), + ] + cmd_options.append('rw' if read_write else 'ro') + cmd_options.append('username={}'.format(username)) + if password: + cmd_options.append('password={}'.format(password)) + else: + # Skip password check + cmd_options.append('guest') + + # Set mount command cmd = [ 'sudo', 'mount', - '//{IP}/{Share}'.format(**server), + '//{IP}/{Share}'.format(**server).replace('\\', '/'), '/Backups/{Name}'.format(**server), - '-o', '{}username={},password={}'.format( - '' if read_write else 'ro,', - username, - password)] + '-o', ','.join(cmd_options), + ] + + # Set result messages warning = 'Failed to mount /Backups/{Name}, {IP} unreachable.'.format( **server) error = 'Failed to mount /Backups/{Name}'.format(**server) diff --git a/.bin/Scripts/mount-backup-shares b/.bin/Scripts/mount-backup-shares index 6a1e88d7..0d8b7fd3 100755 --- a/.bin/Scripts/mount-backup-shares +++ b/.bin/Scripts/mount-backup-shares @@ -16,9 +16,6 @@ if __name__ == '__main__': # Prep clear_screen() - # Connect - connect_to_network() - # Mount if is_connected(): mount_backup_shares(read_write=True) From ec5591453e12543d4921ebb25e8d5fbddfe01b37 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 20:16:09 -0600 Subject: [PATCH 107/113] Updated data.py --- .bin/Scripts/functions/data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/functions/data.py b/.bin/Scripts/functions/data.py index c359ab6c..bf091b37 100644 --- a/.bin/Scripts/functions/data.py +++ b/.bin/Scripts/functions/data.py @@ -218,7 +218,7 @@ def mount_volumes( report[vol_path] = vol_data elif 'children' in vol_data: # Skip LVM/RAID partitions (the real volume is mounted separately) - vol_data['show_data']['data'] = vol_data.get('fstype', 'UNKNOWN') + vol_data['show_data']['data'] = vol_data.get('fstype', 'Unknown') if vol_data.get('label', None): vol_data['show_data']['data'] += ' "{}"'.format(vol_data['label']) vol_data['show_data']['info'] = True @@ -243,7 +243,7 @@ def mount_volumes( if vol_data['show_data']['data'] == 'Failed to mount': vol_data['mount_point'] = None else: - fstype = vol_data.get('fstype', 'UNKNOWN FS') + fstype = vol_data.get('fstype', 'Unknown FS') size_used = human_readable_size( mounted_volumes[vol_path]['used'], decimals=1, From 70823d2cd80c123932fcce862fc6c3e3d3c50be6 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 4 Jun 2019 20:53:34 -0600 Subject: [PATCH 108/113] Updated HW-Diags and sensor sections --- .bin/Scripts/debug/hw_diags.py | 9 +- .bin/Scripts/functions/hw_diags.py | 294 +++++++++++++++++------------ .bin/Scripts/functions/sensors.py | 89 ++++----- .bin/Scripts/hw-diags-menu | 2 +- 4 files changed, 226 insertions(+), 168 deletions(-) diff --git a/.bin/Scripts/debug/hw_diags.py b/.bin/Scripts/debug/hw_diags.py index 87a35990..44517fb4 100644 --- a/.bin/Scripts/debug/hw_diags.py +++ b/.bin/Scripts/debug/hw_diags.py @@ -149,11 +149,14 @@ def save_debug_reports(state, global_vars): f.write('{}\n'.format(line)) -def upload_logdir(global_vars): +def upload_logdir(global_vars, reason='Crash'): """Upload compressed LogDir to CRASH_SERVER.""" source = global_vars['LogDir'] source = source[source.rfind('/')+1:] - dest = '{}.txz'.format(source) + dest = 'HW-Diags_{reason}_{Date-Time}.txz'.format( + reason=reason, + **global_vars, + ) data = None # Compress LogDir @@ -166,7 +169,7 @@ def upload_logdir(global_vars): data = f.read() # Upload data - url = '{}/Crash_{}.txz'.format(CRASH_SERVER['Url'], source) + url = '{}/{}'.format(CRASH_SERVER['Url'], dest) r = requests.put( url, data=data, diff --git a/.bin/Scripts/functions/hw_diags.py b/.bin/Scripts/functions/hw_diags.py index 36be4a30..db5d01ca 100644 --- a/.bin/Scripts/functions/hw_diags.py +++ b/.bin/Scripts/functions/hw_diags.py @@ -36,6 +36,7 @@ class CpuObj(): self.tests = OrderedDict() self.get_details() self.name = self.lscpu.get('Model name', 'Unknown CPU') + self.description = self.name def get_details(self): """Get CPU details from lscpu.""" @@ -57,6 +58,13 @@ class CpuObj(): report.append('{BLUE}Device{CLEAR}'.format(**COLORS)) report.append(' {}'.format(self.name)) + # Include RAM details + ram_details = get_ram_details() + ram_total = human_readable_size(ram_details.pop('Total', 0)).strip() + ram_dimms = ['{}x {}'.format(v, k) for k, v in sorted(ram_details.items())] + report.append('{BLUE}RAM{CLEAR}'.format(**COLORS)) + report.append(' {} ({})'.format(ram_total, ', '.join(ram_dimms))) + # Tests for test in self.tests.values(): report.extend(test.report) @@ -220,11 +228,12 @@ class DiskObj(): # Done return test_running - def disable_test(self, name, status): + def disable_test(self, name, status, test_failed=False): """Disable test by name and update status.""" if name in self.tests: self.tests[name].update_status(status) self.tests[name].disabled = True + self.tests[name].failed = test_failed def generate_attribute_report( self, description=False, timestamp=False): @@ -487,7 +496,7 @@ class DiskObj(): for t in ['badblocks', 'I/O Benchmark']: self.disable_test(t, 'Denied') elif not disk_ok: - self.disable_test('NVMe / SMART', 'NS') + self.disable_test('NVMe / SMART', 'NS', test_failed=True) for t in ['badblocks', 'I/O Benchmark']: self.disable_test(t, 'Denied') @@ -495,6 +504,7 @@ class DiskObj(): class State(): """Object to track device objects and overall state.""" def __init__(self): + self.args = None self.cpu = None self.disks = [] self.panes = {} @@ -522,6 +532,83 @@ class State(): }, }) + def build_outer_panes(self): + """Build top and side panes.""" + clear_screen() + + # Top + self.panes['Top'] = tmux_split_window( + behind=True, lines=2, vertical=True, + text=TOP_PANE_TEXT) + + # Started + self.panes['Started'] = tmux_split_window( + lines=SIDE_PANE_WIDTH, target_pane=self.panes['Top'], + text='{BLUE}Started{CLEAR}\n{s}'.format( + s=time.strftime("%Y-%m-%d %H:%M %Z"), + **COLORS)) + + # Progress + self.panes['Progress'] = tmux_split_window( + lines=SIDE_PANE_WIDTH, + watch=self.progress_out) + + def fix_tmux_panes(self): + """Fix pane sizes if the window has been resized.""" + needs_fixed = False + + # Bail? + if not self.panes: + return + + # Check layout + for k, v in self.tmux_layout.items(): + if not v.get('Check'): + # Not concerned with the size of this pane + continue + # Get target + target = None + if k != 'Current': + if k not in self.panes: + # Skip missing panes + continue + else: + target = self.panes[k] + + # Check pane size + x, y = tmux_get_pane_size(pane_id=target) + if v.get('x', False) and v['x'] != x: + needs_fixed = True + if v.get('y', False) and v['y'] != y: + needs_fixed = True + + # Bail? + if not needs_fixed: + return + + # Update layout + for k, v in self.tmux_layout.items(): + # Get target + target = None + if k != 'Current': + if k not in self.panes: + # Skip missing panes + continue + else: + target = self.panes[k] + + # Resize pane + tmux_resize_pane(pane_id=target, **v) + + def fix_tmux_panes_loop(self): + while True: + try: + self.fix_tmux_panes() + sleep(1) + except RuntimeError: + # Assuming layout definitions changes mid-run, ignoring + pass + def init(self): """Remove test objects, set log, and add devices.""" self.disks = [] @@ -529,14 +616,18 @@ class State(): v['Objects'] = [] # Update LogDir - if not self.quick_mode: + if self.quick_mode: + global_vars['LogDir'] = '{}/Logs/{}'.format( + global_vars['Env']['HOME'], + time.strftime('%Y-%m-%d_%H%M_%z')) + else: global_vars['LogDir'] = '{}/Logs/{}_{}'.format( global_vars['Env']['HOME'], get_ticket_number(), time.strftime('%Y-%m-%d_%H%M_%z')) - os.makedirs(global_vars['LogDir'], exist_ok=True) - global_vars['LogFile'] = '{}/Hardware Diagnostics.log'.format( - global_vars['LogDir']) + os.makedirs(global_vars['LogDir'], exist_ok=True) + global_vars['LogFile'] = '{}/Hardware Diagnostics.log'.format( + global_vars['LogDir']) self.progress_out = '{}/progress.out'.format(global_vars['LogDir']) # Add CPU @@ -565,7 +656,13 @@ class State(): # Start tmux thread self.tmux_layout = TMUX_LAYOUT.copy() - start_thread(fix_tmux_panes_loop, args=[self]) + start_thread(self.fix_tmux_panes_loop) + + def set_top_pane_text(self, text): + """Set top pane text using TOP_PANE_TEXT and provided text.""" + tmux_update_pane( + self.panes['Top'], + text='{}\n{}'.format(TOP_PANE_TEXT, text)) class TestObj(): @@ -600,28 +697,6 @@ class TestObj(): # Functions -def build_outer_panes(state): - """Build top and side panes.""" - clear_screen() - - # Top - state.panes['Top'] = tmux_split_window( - behind=True, lines=2, vertical=True, - text=TOP_PANE_TEXT) - - # Started - state.panes['Started'] = tmux_split_window( - lines=SIDE_PANE_WIDTH, target_pane=state.panes['Top'], - text='{BLUE}Started{CLEAR}\n{s}'.format( - s=time.strftime("%Y-%m-%d %H:%M %Z"), - **COLORS)) - - # Progress - state.panes['Progress'] = tmux_split_window( - lines=SIDE_PANE_WIDTH, - watch=state.progress_out) - - def build_status_string(label, status, info_label=False): """Build status string with appropriate colors.""" status_color = COLORS['CLEAR'] @@ -638,64 +713,6 @@ def build_status_string(label, status, info_label=False): **COLORS) -def fix_tmux_panes_loop(state): - while True: - try: - fix_tmux_panes(state) - sleep(1) - except RuntimeError: - # Assuming layout definitions changes mid-run, ignoring - pass - - -def fix_tmux_panes(state): - """Fix pane sizes if the window has been resized.""" - needs_fixed = False - - # Bail? - if not state.panes: - return - - # Check layout - for k, v in state.tmux_layout.items(): - if not v.get('Check'): - # Not concerned with the size of this pane - continue - # Get target - target = None - if k != 'Current': - if k not in state.panes: - # Skip missing panes - continue - else: - target = state.panes[k] - - # Check pane size - x, y = tmux_get_pane_size(pane_id=target) - if v.get('x', False) and v['x'] != x: - needs_fixed = True - if v.get('y', False) and v['y'] != y: - needs_fixed = True - - # Bail? - if not needs_fixed: - return - - # Update layout - for k, v in state.tmux_layout.items(): - # Get target - target = None - if k != 'Current': - if k not in state.panes: - # Skip missing panes - continue - else: - target = state.panes[k] - - # Resize pane - tmux_resize_pane(pane_id=target, **v) - - def generate_horizontal_graph(rates, oneline=False): """Generate horizontal graph from rates, returns list.""" graph = ['', '', '', ''] @@ -755,6 +772,44 @@ def get_graph_step(rate, scale=16): return step +def get_ram_details(): + """Get RAM details via dmidecode, returns dict.""" + cmd = ['sudo', 'dmidecode', '--type', 'memory'] + manufacturer = 'UNKNOWN' + ram_details = {'Total': 0} + size = 0 + + # Get DMI data + result = run_program(cmd, encoding='utf-8', errors='ignore') + dmi_data = result.stdout.splitlines() + + # Parse data + for line in dmi_data: + line = line.strip() + if line == 'Memory Device': + # Reset vars + manufacturer = 'UNKNOWN' + size = 0 + elif line.startswith('Size:'): + size = convert_to_bytes(line.replace('Size: ', '')) + elif line.startswith('Manufacturer:'): + manufacturer = line.replace('Manufacturer: ', '') + if size > 0: + # Add RAM to list if slot populated + ram_str = '{} {}'.format( + human_readable_size(size).strip(), + manufacturer, + ) + ram_details['Total'] += size + if ram_str in ram_details: + ram_details[ram_str] += 1 + else: + ram_details[ram_str] = 1 + + # Done + return ram_details + + def get_read_rate(s): """Get read rate in bytes/s from dd progress output.""" real_rate = None @@ -767,6 +822,7 @@ def get_read_rate(s): def menu_diags(state, args): """Main menu to select and run HW tests.""" args = [a.lower() for a in args] + state.args = args checkmark = '*' if 'DISPLAY' in global_vars['Env']: checkmark = '✓' @@ -908,10 +964,7 @@ def run_badblocks_test(state, test): update_progress_pane(state) # Update tmux layout - tmux_update_pane( - state.panes['Top'], - text='{}\n{}'.format( - TOP_PANE_TEXT, dev.description)) + state.set_top_pane_text(dev.description) # Create monitor pane test.badblocks_out = '{}/badblocks_{}.out'.format( @@ -994,10 +1047,11 @@ def run_hw_tests(state): """Run enabled hardware tests.""" print_standard('Scanning devices...') state.init() + tests_enabled = False # Build Panes update_progress_pane(state) - build_outer_panes(state) + state.build_outer_panes() # Show selected tests and create TestObj()s print_info('Selected Tests:') @@ -1009,6 +1063,8 @@ def run_hw_tests(state): COLORS['CLEAR'], QUICK_LABEL if state.quick_mode and 'NVMe' in k else '')) if v['Enabled']: + tests_enabled = True + # Create TestObj and track under both CpuObj/DiskObj and State if k in TESTS_CPU: test_obj = TestObj( @@ -1022,6 +1078,11 @@ def run_hw_tests(state): v['Objects'].append(test_obj) print_standard('') + # Bail if no tests selected + if not tests_enabled: + tmux_kill_pane(*state.panes.values()) + return + # Run disk safety checks (if necessary) _disk_tests_enabled = False for k in TESTS_DISK: @@ -1064,7 +1125,7 @@ def run_hw_tests(state): # Rebuild panes update_progress_pane(state) - build_outer_panes(state) + state.build_outer_panes() # Mark unfinished tests as aborted for k, v in state.tests.items(): @@ -1076,8 +1137,22 @@ def run_hw_tests(state): # Update side pane update_progress_pane(state) - # Done + # Show results show_results(state) + + # Upload for review + if ENABLED_UPLOAD_DATA and ask('Upload results for review?'): + try_and_print( + message='Saving debug reports...', + function=save_debug_reports, + state=state, global_vars=global_vars) + try_and_print( + message='Uploading Data...', + function=upload_logdir, + global_vars=global_vars, + reason='Review') + + # Done sleep(1) if state.quick_mode: pause('Press Enter to exit... ') @@ -1104,10 +1179,7 @@ def run_io_benchmark(state, test): update_progress_pane(state) # Update tmux layout - tmux_update_pane( - state.panes['Top'], - text='{}\n{}'.format( - TOP_PANE_TEXT, dev.description)) + state.set_top_pane_text(dev.description) state.tmux_layout['Current'] = {'y': 15, 'Check': True} # Create monitor pane @@ -1266,9 +1338,7 @@ def run_mprime_test(state, test): test.thermal_abort = False # Update tmux layout - tmux_update_pane( - state.panes['Top'], - text='{}\n{}'.format(TOP_PANE_TEXT, dev.name)) + state.set_top_pane_text(dev.name) # Start live sensor monitor test.sensors_out = '{}/sensors.out'.format(global_vars['TmpDir']) @@ -1431,7 +1501,7 @@ def run_mprime_test(state, test): # Add temps to report test.report.append('{BLUE}Temps{CLEAR}'.format(**COLORS)) for line in generate_sensor_report( - test.sensor_data, 'Idle', 'Max', 'Cooldown', core_only=True): + test.sensor_data, 'Idle', 'Max', 'Cooldown', cpu_only=True): test.report.append(' {}'.format(line)) # Add abort message(s) @@ -1481,10 +1551,7 @@ def run_nvme_smart_tests(state, test, update_mode=False): update_progress_pane(state) # Update tmux layout - tmux_update_pane( - state.panes['Top'], - text='{}\n{}'.format( - TOP_PANE_TEXT, dev.description)) + state.set_top_pane_text(dev.description) # SMART short self-test if dev.smart_attributes and not (state.quick_mode or update_mode): @@ -1629,9 +1696,7 @@ def show_report(report, log_report=False): def show_results(state): """Show results for all tests.""" clear_screen() - tmux_update_pane( - state.panes['Top'], - text='{}\nResults'.format(TOP_PANE_TEXT)) + state.set_top_pane_text('Results') # CPU tests _enabled = False @@ -1661,17 +1726,6 @@ def show_results(state): # Update progress update_progress_pane(state) - # Ask for review - if ENABLED_UPLOAD_DATA and ask('Upload results for review?'): - try_and_print( - message='Saving debug reports...', - function=save_debug_reports, - state=state, global_vars=global_vars) - try_and_print( - message='Uploading Data...', - function=upload_logdir, - global_vars=global_vars) - def update_main_options(state, selection, main_options): """Update menu and state based on selection.""" diff --git a/.bin/Scripts/functions/sensors.py b/.bin/Scripts/functions/sensors.py index 993306bd..49a7472c 100644 --- a/.bin/Scripts/functions/sensors.py +++ b/.bin/Scripts/functions/sensors.py @@ -1,4 +1,6 @@ -# Wizard Kit: Functions - Sensors +'''Wizard Kit: Functions - Sensors''' +# pylint: disable=no-name-in-module,wildcard-import +# vim: sts=2 sw=2 ts=2 import json import re @@ -9,7 +11,7 @@ from settings.sensors import * # Error Classes class ThermalLimitReachedError(Exception): - pass + '''Thermal limit reached error.''' def clear_temps(sensor_data): @@ -20,28 +22,30 @@ def clear_temps(sensor_data): _data['Temps'] = [] -def fix_sensor_str(s): +def fix_sensor_str(_s): """Cleanup string and return str.""" - s = re.sub(r'^(\w+)-(\w+)-(\w+)', r'\1 (\2 \3)', s, re.IGNORECASE) - s = s.title() - s = s.replace('Coretemp', 'CoreTemp') - s = s.replace('Acpi', 'ACPI') - s = s.replace('ACPItz', 'ACPI TZ') - s = s.replace('Isa ', 'ISA ') - s = s.replace('Id ', 'ID ') - s = re.sub(r'(\D+)(\d+)', r'\1 \2', s, re.IGNORECASE) - s = s.replace(' ', ' ') - return s + _s = re.sub(r'^(\w+)-(\w+)-(\w+)', r'\1 (\2 \3)', _s, re.IGNORECASE) + _s = _s.title() + _s = _s.replace('Coretemp', 'CPUTemp') + _s = _s.replace('Acpi', 'ACPI') + _s = _s.replace('ACPItz', 'ACPI TZ') + _s = _s.replace('Isa ', 'ISA ') + _s = _s.replace('Pci ', 'PCI ') + _s = _s.replace('Id ', 'ID ') + _s = re.sub(r'(\D+)(\d+)', r'\1 \2', _s, re.IGNORECASE) + _s = re.sub(r'^K (\d+)Temp', r'AMD K\1 Temps', _s, re.IGNORECASE) + _s = re.sub(r'T(ctl|die)', r'CPU (T\1)', _s, re.IGNORECASE) + return _s def generate_sensor_report( sensor_data, *temp_labels, - colors=True, core_only=False): + colors=True, cpu_only=False): """Generate report based on temp_labels, returns list if str.""" report = [] for _section, _adapters in sorted(sensor_data.items()): - # CoreTemps then Other temps - if core_only and 'Core' not in _section: + # CPU temps then Other temps + if cpu_only and 'CPU' not in _section: continue for _adapter, _sources in sorted(_adapters.items()): # Adapter @@ -56,7 +60,7 @@ def generate_sensor_report( ': ' if _label != 'Current' else '', get_temp_str(_data.get(_label, '???'), colors=colors)) report.append(_line) - if not core_only: + if not cpu_only: report.append(' ') # Handle empty reports (i.e. no sensors detected) @@ -91,17 +95,17 @@ def get_colored_temp_str(temp): else: color = COLORS['CLEAR'] return '{color}{prefix}{temp:2.0f}°C{CLEAR}'.format( - color = color, - prefix = '-' if temp < 0 else '', - temp = temp, + color=color, + prefix='-' if temp < 0 else '', + temp=temp, **COLORS) def get_raw_sensor_data(): """Read sensor data and return dict.""" - data = {} + json_data = {} cmd = ['sensors', '-j'] - + # Get raw data try: result = run_program(cmd) @@ -122,8 +126,8 @@ def get_raw_sensor_data(): try: json_data = json.loads('\n'.join(raw_data)) except json.JSONDecodeError: - # Still broken, just set to empty dict - json_data = {} + # Still broken, just return the empty dict + pass # Done return json_data @@ -132,10 +136,10 @@ def get_raw_sensor_data(): def get_sensor_data(): """Parse raw sensor data and return new dict.""" json_data = get_raw_sensor_data() - sensor_data = {'CoreTemps': {}, 'Other': {}} + sensor_data = {'CPUTemps': {}, 'Other': {}} for _adapter, _sources in json_data.items(): - if 'coretemp' in _adapter: - _section = 'CoreTemps' + if is_cpu_adapter(_adapter): + _section = 'CPUTemps' else: _section = 'Other' sensor_data[_section][_adapter] = {} @@ -157,8 +161,8 @@ def get_sensor_data(): } # Remove empty sections - for k, v in sensor_data.items(): - v = {k2: v2 for k2, v2 in v.items() if v2} + for _k, _v in sensor_data.items(): + _v = {_k2: _v2 for _k2, _v2 in _v.items() if _v2} # Done return sensor_data @@ -178,14 +182,20 @@ def get_temp_str(temp, colors=True): temp) +def is_cpu_adapter(adapter): + """Checks if adapter is a known CPU adapter, returns bool.""" + is_cpu = re.search(r'(core|k\d+)temp', adapter, re.IGNORECASE) + return bool(is_cpu) + + def monitor_sensors(monitor_pane, monitor_file): """Continually update sensor data and report to screen.""" sensor_data = get_sensor_data() while True: update_sensor_data(sensor_data) - with open(monitor_file, 'w') as f: + with open(monitor_file, 'w') as _f: report = generate_sensor_report(sensor_data, 'Current', 'Max') - f.write('\n'.join(report)) + _f.write('\n'.join(report)) sleep(1) if monitor_pane and not tmux_poll_pane(monitor_pane): break @@ -196,7 +206,7 @@ def save_average_temp(sensor_data, temp_label, seconds=10): clear_temps(sensor_data) # Get temps - for i in range(seconds): + for _i in range(seconds): # pylint: disable=unused-variable update_sensor_data(sensor_data) sleep(1) @@ -219,24 +229,15 @@ def update_sensor_data(sensor_data, thermal_limit=None): _data['Current'] = _temp _data['Max'] = max(_temp, _data['Max']) _data['Temps'].append(_temp) - except Exception: + except Exception: # pylint: disable=broad-except # Dumb workound for Dell sensors with changing source names pass # Check if thermal limit reached - if thermal_limit and _section == 'CoreTemps': + if thermal_limit and _section == 'CPUTemps': if max(_data['Current'], _data['Max']) >= thermal_limit: - raise ThermalLimitReachedError('CoreTemps reached limit') - - -def join_columns(column1, column2, width=55): - return '{:<{}}{}'.format( - column1, - 55+len(column1)-len(REGEX_COLORS.sub('', column1)), - column2) + raise ThermalLimitReachedError('CPU temps reached limit') if __name__ == '__main__': print("This file is not meant to be called directly.") - -# vim: sts=2 sw=2 ts=2 diff --git a/.bin/Scripts/hw-diags-menu b/.bin/Scripts/hw-diags-menu index 1c241bf9..fc95e04a 100755 --- a/.bin/Scripts/hw-diags-menu +++ b/.bin/Scripts/hw-diags-menu @@ -49,7 +49,7 @@ if __name__ == '__main__': global_vars=global_vars) # Done - sleep(10) + sleep(1) pause('Press Enter to exit...') exit_script(1) From 86f17757dbd4ac3f67d1f3ba8001919e335226c1 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 11 Jun 2019 17:49:10 -0600 Subject: [PATCH 109/113] Updated cleanup sections --- .bin/Scripts/functions/cleanup.py | 22 ++++++++++++------ .bin/Scripts/settings/cleanup.py | 37 +++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 .bin/Scripts/settings/cleanup.py diff --git a/.bin/Scripts/functions/cleanup.py b/.bin/Scripts/functions/cleanup.py index 5ee20be1..744ee048 100644 --- a/.bin/Scripts/functions/cleanup.py +++ b/.bin/Scripts/functions/cleanup.py @@ -1,7 +1,9 @@ -# Wizard Kit: Functions - Cleanup - -from functions.common import * +'''Wizard Kit: Functions - Cleanup''' +# pylint: disable=no-name-in-module,wildcard-import +# vim: sts=2 sw=2 ts=2 +from functions.setup import * +from settings.cleanup import * def cleanup_adwcleaner(): """Move AdwCleaner folders into the ClientDir.""" @@ -75,8 +77,7 @@ def cleanup_desktop(): desktop_path = r'{USERPROFILE}\Desktop'.format(**global_vars['Env']) for entry in os.scandir(desktop_path): - # JRT, RKill, Shortcut cleaner - if re.search(r'^(JRT|RKill|sc-cleaner)', entry.name, re.IGNORECASE): + if DESKTOP_ITEMS.search(entry.name): dest_name = r'{}\{}'.format(dest_folder, entry.name) dest_name = non_clobber_rename(dest_name) shutil.move(entry.path, dest_name) @@ -130,7 +131,14 @@ def delete_registry_value(hive, key, value): winreg.DeleteValue(k, value) +def restore_default_uac(): + """Restores default UAC settings via the registry.""" + if global_vars['OS']['Version'] == '10': + write_registry_settings(UAC_DEFAULTS_WIN10, all_users=True) + else: + # Haven't checked Win8 settings, only applying minimum set + write_registry_settings(UAC_DEFAULTS_WIN7, all_users=True) + + if __name__ == '__main__': print("This file is not meant to be called directly.") - -# vim: sts=2 sw=2 ts=2 diff --git a/.bin/Scripts/settings/cleanup.py b/.bin/Scripts/settings/cleanup.py new file mode 100644 index 00000000..2188fc6b --- /dev/null +++ b/.bin/Scripts/settings/cleanup.py @@ -0,0 +1,37 @@ +'''Wizard Kit: Settings - Cleanup''' +# vim: sts=2 sw=2 ts=2 + +import re + +# Regex +DESKTOP_ITEMS = re.compile( + r'^(JRT|RKill|sc-cleaner)', + re.IGNORECASE, + ) + +# Registry +UAC_DEFAULTS_WIN7 = { + r'Software\Microsoft\Windows\CurrentVersion\Policies\System': { + 'DWORD Items': { + 'ConsentPromptBehaviorAdmin': 5, + 'EnableLUA': 1, + 'PromptOnSecureDesktop': 1, + }, + }, + } +UAC_DEFAULTS_WIN10 = { + r'Software\Microsoft\Windows\CurrentVersion\Policies\System': { + 'DWORD Items': { + 'ConsentPromptBehaviorAdmin': 5, + 'ConsentPromptBehaviorUser': 3, + 'EnableInstallerDetection': 1, + 'EnableLUA': 1, + 'EnableVirtualization': 1, + 'PromptOnSecureDesktop': 1, + }, + }, + } + + +if __name__ == '__main__': + print("This file is not meant to be called directly.") From c537a01fbf16d6f85dada1dd30b3c6f2b09654ad Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 11 Jun 2019 17:55:50 -0600 Subject: [PATCH 110/113] Updated info.py --- .bin/Scripts/functions/info.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.bin/Scripts/functions/info.py b/.bin/Scripts/functions/info.py index 84d92663..b1959090 100644 --- a/.bin/Scripts/functions/info.py +++ b/.bin/Scripts/functions/info.py @@ -95,7 +95,7 @@ def get_installed_antivirus(): out = out.stdout.decode().strip() state = out.split('=')[1] state = hex(int(state)) - if str(state)[3:5] != '10': + if str(state)[3:5] not in ['10', '11']: programs.append('[Disabled] {}'.format(prod)) else: programs.append(prod) @@ -446,16 +446,19 @@ def show_os_name(): def show_temp_files_size(): """Show total size of temp files identified by BleachBit.""" - size = None + size_str = None + total = 0 with open(r'{LogDir}\Tools\BleachBit.log'.format(**global_vars), 'r') as f: for line in f.readlines(): - if re.search(r'^disk space to be recovered:', line, re.IGNORECASE): + if re.search(r'^Disk space (to be |)recovered:', line, re.IGNORECASE): size = re.sub(r'.*: ', '', line.strip()) size = re.sub(r'(\w)iB$', r' \1b', size) - if size is None: - print_warning(size, timestamp=False) + total += convert_to_bytes(size) + size_str = human_readable_size(total, decimals=1) + if size_str is None: + print_warning('UNKNOWN', timestamp=False) else: - print_standard(size, timestamp=False) + print_standard(size_str, timestamp=False) def show_user_data_summary(indent=8, width=32): From f30d195cc444eb493d057b40b91e020ab2274f92 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 11 Jun 2019 18:08:50 -0600 Subject: [PATCH 111/113] Updated Explorer registry entries --- .bin/Scripts/settings/setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bin/Scripts/settings/setup.py b/.bin/Scripts/settings/setup.py index c11073ec..ec3219a2 100644 --- a/.bin/Scripts/settings/setup.py +++ b/.bin/Scripts/settings/setup.py @@ -134,10 +134,12 @@ SETTINGS_EXPLORER_USER = { }, # Hide People bar r'Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People': { + 'Invalid modes': ['Cur'], 'DWORD Items': {'PeopleBand': 0}, }, # Hide Search button / box r'Software\Microsoft\Windows\CurrentVersion\Search': { + 'Invalid modes': ['Cur'], 'DWORD Items': {'SearchboxTaskbarMode': 0}, }, } From 3007c22c41d0c2fd1d2657938a753ffd5fb7a60f Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 11 Jun 2019 18:40:25 -0600 Subject: [PATCH 112/113] Added Windows Update sections --- .bin/Scripts/functions/windows_updates.py | 143 ++++++++++++++++++++++ .bin/Scripts/windows_updates.py | 46 +++++++ 2 files changed, 189 insertions(+) create mode 100644 .bin/Scripts/functions/windows_updates.py create mode 100644 .bin/Scripts/windows_updates.py diff --git a/.bin/Scripts/functions/windows_updates.py b/.bin/Scripts/functions/windows_updates.py new file mode 100644 index 00000000..3618fbb2 --- /dev/null +++ b/.bin/Scripts/functions/windows_updates.py @@ -0,0 +1,143 @@ +# Wizard Kit: Functions - Windows updates + +from functions.common import * + + +# Functions +def delete_folder(folder_path): + """Near-useless wrapper for shutil.rmtree.""" + shutil.rmtree(folder_path) + + +def disable_service(service_name): + """Set service startup to disabled.""" + run_program(['sc', 'config', service_name, 'start=', 'disabled']) + + # Verify service was disabled + start_type = get_service_start_type(service_name) + if not start_type.lower().startswith('disabled'): + raise GenericError('Failed to disable service {}'.format(service_name)) + + +def disable_windows_updates(): + """Disable windows updates and clear SoftwareDistribution folder.""" + indent=2 + width=52 + update_folders = [ + r'{WINDIR}\SoftwareDistribution'.format(**global_vars['Env']), + r'{SYSTEMDRIVE}\$WINDOWS.~BT'.format(**global_vars['Env']), + ] + + for service in ('wuauserv', 'bits'): + # Stop service + result = try_and_print( + 'Stopping service {}...'.format(service), + indent=indent, width=width, + function=stop_service, service_name=service) + if not result['CS']: + result = try_and_print( + 'Stopping service {}...'.format(service), + indent=indent, width=width, + function=stop_service, service_name=service) + if not result['CS']: + raise GenericError('Service {} could not be stopped.'.format(service)) + + # Disable service + result = try_and_print( + 'Disabling service {}...'.format(service), + indent=indent, width=width, + function=disable_service, service_name=service) + if not result['CS']: + result = try_and_print( + 'Disabling service {}...'.format(service), + indent=indent, width=width, + function=disable_service, service_name=service) + if not result['CS']: + raise GenericError('Service {} could not be disabled.'.format(service)) + + # Delete update folders + for folder_path in update_folders: + if os.path.exists(folder_path): + result = try_and_print( + 'Deleting folder {}...'.format(folder_path), + indent=indent, width=width, + function=delete_folder, folder_path=folder_path) + if not result['CS']: + raise GenericError('Failed to remove folder {}'.format(folder_path)) + + +def enable_service(service_name, start_type='auto'): + """Enable service by setting start type.""" + run_program(['sc', 'config', service_name, 'start=', start_type]) + + +def enable_windows_updates(silent=False): + """Enable windows updates""" + indent=2 + width=52 + + for service in ('bits', 'wuauserv'): + # Enable service + start_type = 'auto' + if service == 'wuauserv': + start_type = 'demand' + if silent: + try: + enable_service(service, start_type=start_type) + except Exception: + # Try again + enable_service(service, start_type=start_type) + else: + result = try_and_print( + 'Enabling service {}...'.format(service), + indent=indent, width=width, + function=enable_service, service_name=service, start_type=start_type) + if not result['CS']: + result = try_and_print( + 'Enabling service {}...'.format(service), + indent=indent, width=width, + function=enable_service, service_name=service, start_type=start_type) + if not result['CS']: + raise GenericError('Service {} could not be enabled.'.format(service)) + + +def get_service_status(service_name): + """Get service status using psutil, returns str.""" + status = 'Unknown' + try: + service = psutil.win_service_get(service_name) + status = service.status() + except psutil.NoSuchProcess: + # Ignore and return 'Unknown' below + pass + + return status + + +def get_service_start_type(service_name): + """Get service startup type using psutil, returns str.""" + start_type = 'Unknown' + try: + service = psutil.win_service_get(service_name) + start_type = service.start_type() + except psutil.NoSuchProcess: + # Ignore and return 'Unknown' below + pass + + return start_type + + +def stop_service(service_name): + """Stop service.""" + run_program(['net', 'stop', service_name], check=False) + + # Verify service was stopped + status = get_service_status(service_name) + if not status.lower().startswith('stopped'): + raise GenericError('Failed to stop service {}'.format(service_name)) + + +if __name__ == '__main__': + print("This file is not meant to be called directly.") + +# vim: sts=2 sw=2 ts=2 diff --git a/.bin/Scripts/windows_updates.py b/.bin/Scripts/windows_updates.py new file mode 100644 index 00000000..e29f8c48 --- /dev/null +++ b/.bin/Scripts/windows_updates.py @@ -0,0 +1,46 @@ +# Wizard Kit: Windows updates + +import os +import sys + +# Init +sys.path.append(os.path.dirname(os.path.realpath(__file__))) +from functions.windows_updates import * +init_global_vars() +os.system('title {}: Windows Updates Tool'.format(KIT_NAME_FULL)) +set_log_file('Windows Updates Tool.log') + +if __name__ == '__main__': + try: + clear_screen() + print_info('{}: Windows Updates Tool\n'.format(KIT_NAME_FULL)) + + # Check args + if '--disable' in sys.argv: + disable_windows_updates() + elif '--enable' in sys.argv: + enable_windows_updates() + else: + print_error('Bad mode.') + abort() + + # Done + exit_script() + except GenericError as err: + # Failed to complete request, show error(s) and prompt tech + print_standard(' ') + for line in str(err).splitlines(): + print_warning(line) + print_standard(' ') + print_error('Error(s) encountered, see above.') + print_standard(' ') + if '--disable' in sys.argv: + print_standard('Please reboot and try again.') + pause('Press Enter to exit... ') + exit_script(1) + except SystemExit as sys_exit: + exit_script(sys_exit.code) + except: + major_exception() + +# vim: sts=2 sw=2 ts=2 From b95586a590cc63949efa7ad9d34954a11f08c381 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 11 Jun 2019 18:42:31 -0600 Subject: [PATCH 113/113] Moved to a unified system setup script * Replaces: * Install SW Bundle * New System Setup * User Checklist * System Checklist --- .bin/Scripts/functions/common.py | 6 + .bin/Scripts/functions/setup.py | 4 + .bin/Scripts/new_system_setup.py | 160 ------------- .bin/Scripts/settings/launchers.py | 62 ++--- .bin/Scripts/system_checklist.py | 133 ----------- .bin/Scripts/system_setup.py | 354 +++++++++++++++++++++++++++++ .bin/Scripts/user_checklist.py | 90 -------- 7 files changed, 397 insertions(+), 412 deletions(-) delete mode 100644 .bin/Scripts/new_system_setup.py delete mode 100644 .bin/Scripts/system_checklist.py create mode 100644 .bin/Scripts/system_setup.py delete mode 100644 .bin/Scripts/user_checklist.py diff --git a/.bin/Scripts/functions/common.py b/.bin/Scripts/functions/common.py index 2828bcb4..689cc85f 100644 --- a/.bin/Scripts/functions/common.py +++ b/.bin/Scripts/functions/common.py @@ -91,6 +91,12 @@ class SecureBootNotAvailError(Exception): class SecureBootUnknownError(Exception): pass +class WindowsOutdatedError(Exception): + pass + +class WindowsUnsupportedError(Exception): + pass + # General functions def abort(show_prompt=True): diff --git a/.bin/Scripts/functions/setup.py b/.bin/Scripts/functions/setup.py index ad575f75..f9f864e9 100644 --- a/.bin/Scripts/functions/setup.py +++ b/.bin/Scripts/functions/setup.py @@ -334,6 +334,10 @@ def open_device_manager(): popen_program(['mmc', 'devmgmt.msc']) +def open_speedtest(): + popen_program(['start', '', 'https://fast.com'], shell=True) + + def open_windows_activation(): popen_program(['slui']) diff --git a/.bin/Scripts/new_system_setup.py b/.bin/Scripts/new_system_setup.py deleted file mode 100644 index 68e508d2..00000000 --- a/.bin/Scripts/new_system_setup.py +++ /dev/null @@ -1,160 +0,0 @@ -# Wizard Kit: New system setup - -import os -import sys - -# Init -sys.path.append(os.path.dirname(os.path.realpath(__file__))) -from functions.activation import * -from functions.browsers import * -from functions.cleanup import * -from functions.info import * -from functions.product_keys import * -from functions.setup import * -from functions.sw_diags import * -init_global_vars() -os.system('title {}: New System Setup'.format(KIT_NAME_FULL)) -set_log_file('New System Setup.log') - -if __name__ == '__main__': - other_results = { - 'Error': { - 'BIOSKeyNotFoundError': 'BIOS key not found', - 'CalledProcessError': 'Unknown Error', - 'FileNotFoundError': 'File not found', - 'GenericError': 'Unknown Error', - 'SecureBootDisabledError': 'Disabled', - }, - 'Warning': { - 'GenericRepair': 'Repaired', - 'NoProfilesError': 'No profiles found', - 'NotInstalledError': 'Not installed', - 'OSInstalledLegacyError': 'OS installed Legacy', - 'SecureBootNotAvailError': 'Not available', - 'SecureBootUnknownError': 'Unknown', - 'UnsupportedOSError': 'Unsupported OS', - }} - try: - stay_awake() - clear_screen() - - # Check installed OS - if os_is_unsupported(show_alert=False): - print_warning('OS version not supported by this script') - if not ask('Continue anyway? (NOT RECOMMENDED)'): - abort() - - # Install Adobe Reader? - answer_adobe_reader = ask('Install Adobe Reader?') - - # Install LibreOffice? - answer_libreoffice = ask('Install LibreOffice?') - - # Install MSE? - if global_vars['OS']['Version'] == '7': - answer_mse = ask('Install MSE?') - else: - answer_mse = False - - # Install software - print_info('Installing Programs') - install_vcredists() - if answer_adobe_reader: - try_and_print(message='Adobe Reader DC...', - function=install_adobe_reader, other_results=other_results) - result = try_and_print( - message='Ninite bundle...', - function=install_ninite_bundle, cs='Started', - mse=answer_mse, libreoffice=answer_libreoffice, - other_results=other_results) - for proc in result['Out']: - # Wait for all processes to finish - proc.wait() - - # Scan for supported browsers - print_info('Scanning for browsers') - scan_for_browsers() - - # Install extensions - print_info('Installing Extensions') - try_and_print(message='Classic Shell skin...', - function=install_classicstart_skin, - other_results=other_results) - try_and_print(message='Google Chrome extensions...', - function=install_chrome_extensions) - try_and_print(message='Mozilla Firefox extensions...', - function=install_firefox_extensions, - other_results=other_results) - - # Configure software - print_info('Configuring programs') - install_adblock() - if global_vars['OS']['Version'] == '10': - try_and_print(message='ClassicStart...', - function=config_classicstart, cs='Done') - try_and_print(message='Explorer (user)...', - function=config_explorer_user, cs='Done') - - # Configure system - print_info('Configuring system') - if global_vars['OS']['Version'] == '10': - try_and_print(message='Explorer (system)...', - function=config_explorer_system, cs='Done') - try_and_print(message='Windows Updates...', - function=config_windows_updates, cs='Done') - try_and_print(message='Updating Clock...', - function=update_clock, cs='Done') - - # Restart Explorer - try_and_print(message='Restarting Explorer...', - function=restart_explorer, cs='Done') - - # Summary - print_info('Summary') - try_and_print(message='Operating System:', - function=show_os_name, ns='Unknown', silent_function=False) - try_and_print(message='Activation:', - function=show_os_activation, ns='Unknown', silent_function=False) - if (not windows_is_activated() - and global_vars['OS']['Version'] in ('8', '8.1', '10')): - try_and_print(message='BIOS Activation:', - function=activate_with_bios, - other_results=other_results) - try_and_print(message='Secure Boot Status:', - function=check_secure_boot_status, other_results=other_results) - try_and_print(message='Installed RAM:', - function=show_installed_ram, ns='Unknown', silent_function=False) - show_free_space() - try_and_print(message='Installed Antivirus:', - function=get_installed_antivirus, ns='Unknown', - other_results=other_results, print_return=True) - - # Play audio, show devices, open Windows updates, and open Activation - try_and_print(message='Opening Device Manager...', - function=open_device_manager, cs='Started') - try_and_print(message='Opening HWiNFO (Sensors)...', - function=run_hwinfo_sensors, cs='Started', other_results=other_results) - try_and_print(message='Opening Windows Updates...', - function=open_windows_updates, cs='Started') - if not windows_is_activated(): - try_and_print(message='Opening Windows Activation...', - function=open_windows_activation, cs='Started') - sleep(3) - try_and_print(message='Running XMPlay...', - function=run_xmplay, cs='Started', other_results=other_results) - try: - check_secure_boot_status(show_alert=True) - except: - # Only trying to open alert message boxes - pass - - # Done - print_standard('\nDone.') - pause('Press Enter to exit...') - exit_script() - except SystemExit as sys_exit: - exit_script(sys_exit.code) - except: - major_exception() - -# vim: sts=2 sw=2 ts=2 diff --git a/.bin/Scripts/settings/launchers.py b/.bin/Scripts/settings/launchers.py index 73a70923..7161c98e 100644 --- a/.bin/Scripts/settings/launchers.py +++ b/.bin/Scripts/settings/launchers.py @@ -1,35 +1,20 @@ -# Wizard Kit: Settings - Launchers +'''Wizard Kit: Settings - Launchers''' +# pylint: disable=line-too-long +# vim: sts=2 sw=2 ts=2 LAUNCHERS = { r'(Root)': { - 'Activate Windows': { - 'L_TYPE': 'PyScript', - 'L_PATH': 'Scripts', - 'L_ITEM': 'activate.py', - 'L_ELEV': 'True', - }, - 'New System Setup': { - 'L_TYPE': 'PyScript', - 'L_PATH': 'Scripts', - 'L_ITEM': 'new_system_setup.py', - 'L_ELEV': 'True', - }, - 'System Checklist': { - 'L_TYPE': 'PyScript', - 'L_PATH': 'Scripts', - 'L_ITEM': 'system_checklist.py', - 'L_ELEV': 'True', - }, 'System Diagnostics': { 'L_TYPE': 'PyScript', 'L_PATH': 'Scripts', 'L_ITEM': 'system_diagnostics.py', 'L_ELEV': 'True', }, - 'User Checklist': { + 'System Setup': { 'L_TYPE': 'PyScript', 'L_PATH': 'Scripts', - 'L_ITEM': 'user_checklist.py', + 'L_ITEM': 'system_setup.py', + 'L_ELEV': 'True', }, }, r'Data Recovery': { @@ -55,6 +40,7 @@ LAUNCHERS = { }, }, r'Data Transfers': { + # pylint: disable=bad-continuation 'FastCopy (as ADMIN)': { 'L_TYPE': 'Executable', 'L_PATH': 'FastCopy', @@ -257,7 +243,7 @@ LAUNCHERS = { 'L_TYPE': 'Executable', 'L_PATH': 'erunt', 'L_ITEM': 'ERUNT.EXE', - 'L_ARGS': '%client_dir%\Backups\Registry\%iso_date% sysreg curuser otherusers', + 'L_ARGS': r'%client_dir%\Backups\Registry\%iso_date% sysreg curuser otherusers', 'L_ELEV': 'True', 'Extra Code': [ r'call "%bin%\Scripts\init_client_dir.cmd" /Logs', @@ -287,13 +273,13 @@ LAUNCHERS = { r'Drivers': { 'Intel RST (Current Release)': { 'L_TYPE': 'Executable', - 'L_PATH': '_Drivers\Intel RST', + 'L_PATH': r'_Drivers\Intel RST', 'L_ITEM': 'SetupRST_17.2.exe', 'L_7ZIP': 'SetupRST_17.2.exe', }, 'Intel RST (Previous Releases)': { 'L_TYPE': 'Folder', - 'L_PATH': '_Drivers\Intel RST', + 'L_PATH': r'_Drivers\Intel RST', 'L_ITEM': '.', 'L_NCMD': 'True', }, @@ -309,7 +295,7 @@ LAUNCHERS = { }, 'Snappy Driver Installer Origin': { 'L_TYPE': 'Executable', - 'L_PATH': '_Drivers\SDIO', + 'L_PATH': r'_Drivers\SDIO', 'L_ITEM': 'SDIO.exe', }, }, @@ -435,6 +421,12 @@ LAUNCHERS = { }, }, r'Misc': { + 'Activate Windows': { + 'L_TYPE': 'PyScript', + 'L_PATH': 'Scripts', + 'L_ITEM': 'activate.py', + 'L_ELEV': 'True', + }, 'Cleanup CBS Temp Files': { 'L_TYPE': 'PyScript', 'L_PATH': 'Scripts', @@ -452,6 +444,20 @@ LAUNCHERS = { 'L_PATH': 'ConEmu', 'L_ITEM': 'ConEmu.exe', }, + 'Disable Windows Updates': { + 'L_TYPE': 'PyScript', + 'L_PATH': 'Scripts', + 'L_ITEM': 'windows_updates.py', + 'L_ARGS': '--disable', + 'L_ELEV': 'True', + }, + 'Enable Windows Updates': { + 'L_TYPE': 'PyScript', + 'L_PATH': 'Scripts', + 'L_ITEM': 'windows_updates.py', + 'L_ARGS': '--enable', + 'L_ELEV': 'True', + }, 'Enter SafeMode': { 'L_TYPE': 'PyScript', 'L_PATH': 'Scripts', @@ -491,7 +497,7 @@ LAUNCHERS = { 'L_TYPE': 'Executable', 'L_PATH': 'XMPlay', 'L_ITEM': 'xmplay.exe', - 'L_ARGS': '"%bin%\XMPlay\music.7z"', + 'L_ARGS': r'"%bin%\XMPlay\music.7z"', }, }, r'Repairs': { @@ -551,7 +557,7 @@ LAUNCHERS = { 'L_TYPE': 'Executable', 'L_PATH': 'RKill', 'L_ITEM': 'RKill.exe', - 'L_ARGS': '-s -l %log_dir%\Tools\RKill.log', + 'L_ARGS': r'-s -l %log_dir%\Tools\RKill.log', 'L_ELEV': 'True', 'Extra Code': [ r'call "%bin%\Scripts\init_client_dir.cmd" /Logs', @@ -594,5 +600,3 @@ LAUNCHERS = { if __name__ == '__main__': print("This file is not meant to be called directly.") - -# vim: sts=2 sw=2 ts=2 diff --git a/.bin/Scripts/system_checklist.py b/.bin/Scripts/system_checklist.py deleted file mode 100644 index a5b86e1e..00000000 --- a/.bin/Scripts/system_checklist.py +++ /dev/null @@ -1,133 +0,0 @@ -# Wizard Kit: System Checklist - -import os -import sys - -# Init -sys.path.append(os.path.dirname(os.path.realpath(__file__))) -from functions.activation import * -from functions.cleanup import * -from functions.info import * -from functions.product_keys import * -from functions.setup import * -from functions.sw_diags import * -init_global_vars() -os.system('title {}: System Checklist Tool'.format(KIT_NAME_FULL)) -set_log_file('System Checklist.log') - -if __name__ == '__main__': - try: - stay_awake() - clear_screen() - print_info('{}: System Checklist Tool\n'.format(KIT_NAME_FULL)) - ticket_number = get_ticket_number() - other_results = { - 'Error': { - 'BIOSKeyNotFoundError': 'BIOS key not found', - 'CalledProcessError': 'Unknown Error', - 'FileNotFoundError': 'File not found', - 'GenericError': 'Unknown Error', - 'SecureBootDisabledError': 'Disabled', - }, - 'Warning': { - 'OSInstalledLegacyError': 'OS installed Legacy', - 'SecureBootNotAvailError': 'Not available', - 'SecureBootUnknownError': 'Unknown', - }} - if ENABLED_TICKET_NUMBERS: - print_info('Starting System Checklist for Ticket #{}\n'.format( - ticket_number)) - - # Configure - print_info('Configure') - if global_vars['OS']['Version'] == '10': - try_and_print(message='Explorer...', - function=config_explorer_system, cs='Done') - try_and_print(message='Windows Updates...', - function=config_windows_updates, cs='Done') - try_and_print(message='Updating Clock...', - function=update_clock, cs='Done') - - # Restart Explorer - try_and_print(message='Restarting Explorer...', - function=restart_explorer, cs='Done') - - # Cleanup - print_info('Cleanup') - try_and_print(message='AdwCleaner...', - function=cleanup_adwcleaner, cs='Done', other_results=other_results) - try_and_print(message='Desktop...', - function=cleanup_desktop, cs='Done') - try_and_print(message='{}...'.format(KIT_NAME_FULL), - function=delete_empty_folders, cs='Done', - folder_path=global_vars['ClientDir']) - - # Export system info - print_info('Backup System Information') - try_and_print(message='AIDA64 reports...', - function=run_aida64, cs='Done', other_results=other_results) - try_and_print(message='File listing...', - function=backup_file_list, cs='Done', other_results=other_results) - try_and_print(message='Power plans...', - function=backup_power_plans, cs='Done') - try_and_print(message='Product Keys...', other_results=other_results, - function=run_produkey, cs='Done') - try_and_print(message='Registry...', - function=backup_registry, cs='Done', other_results=other_results) - - # User data - print_info('User Data') - show_user_data_summary() - - # Summary - print_info('Summary') - try_and_print(message='Operating System:', - function=show_os_name, ns='Unknown', silent_function=False) - try_and_print(message='Activation:', - function=show_os_activation, ns='Unknown', silent_function=False) - if (not windows_is_activated() - and global_vars['OS']['Version'] in ('8', '8.1', '10')): - try_and_print(message='BIOS Activation:', - function=activate_with_bios, - other_results=other_results) - try_and_print(message='Secure Boot Status:', - function=check_secure_boot_status, other_results=other_results) - try_and_print(message='Installed RAM:', - function=show_installed_ram, ns='Unknown', silent_function=False) - show_free_space() - try_and_print(message='Installed Antivirus:', - function=get_installed_antivirus, ns='Unknown', - other_results=other_results, print_return=True) - try_and_print(message='Installed Office:', - function=get_installed_office, ns='Unknown', - other_results=other_results, print_return=True) - - # Play audio, show devices, open Windows updates, and open Activation - try_and_print(message='Opening Device Manager...', - function=open_device_manager, cs='Started') - try_and_print(message='Opening HWiNFO (Sensors)...', - function=run_hwinfo_sensors, cs='Started', other_results=other_results) - try_and_print(message='Opening Windows Updates...', - function=open_windows_updates, cs='Started') - if not windows_is_activated(): - try_and_print(message='Opening Windows Activation...', - function=open_windows_activation, cs='Started') - sleep(3) - try_and_print(message='Running XMPlay...', - function=run_xmplay, cs='Started', other_results=other_results) - try: - check_secure_boot_status(show_alert=True) - except: - # Only trying to open alert message boxes - pass - - # Done - print_standard('\nDone.') - pause('Press Enter exit...') - exit_script() - except SystemExit as sys_exit: - exit_script(sys_exit.code) - except: - major_exception() - -# vim: sts=2 sw=2 ts=2 diff --git a/.bin/Scripts/system_setup.py b/.bin/Scripts/system_setup.py new file mode 100644 index 00000000..5d49b26d --- /dev/null +++ b/.bin/Scripts/system_setup.py @@ -0,0 +1,354 @@ +'''Wizard Kit: System Setup''' +# pylint: disable=wildcard-import,wrong-import-position +# vim: sts=2 sw=2 ts=2 + +import os +import sys + +# Init +sys.path.append(os.path.dirname(os.path.realpath(__file__))) +from collections import OrderedDict +from functions.activation import * +from functions.browsers import * +from functions.cleanup import * +from functions.info import * +from functions.product_keys import * +from functions.setup import * +from functions.sw_diags import * +from functions.windows_updates import * +init_global_vars() +os.system('title {}: System Setup'.format(KIT_NAME_FULL)) +set_log_file('System Setup.log') + + +# STATIC VARIABLES +# pylint: disable=bad-whitespace,line-too-long +OTHER_RESULTS = { + 'Error': { + 'BIOSKeyNotFoundError': 'BIOS KEY NOT FOUND', + 'CalledProcessError': 'UNKNOWN ERROR', + 'FileNotFoundError': 'FILE NOT FOUND', + 'GenericError': 'UNKNOWN ERROR', + 'Not4KAlignedError': 'FALSE', + 'SecureBootDisabledError': 'DISABLED', + 'WindowsUnsupportedError': 'UNSUPPORTED', + }, + 'Warning': { + 'GenericRepair': 'REPAIRED', + 'NoProfilesError': 'NO PROFILES FOUND', + 'NotInstalledError': 'NOT INSTALLED', + 'OSInstalledLegacyError': 'OS INSTALLED LEGACY', + 'SecureBootNotAvailError': 'NOT AVAILABLE', + 'SecureBootUnknownError': 'UNKNOWN', + 'UnsupportedOSError': 'UNSUPPORTED OS', + 'WindowsOutdatedError': 'OUTDATED', + }, + } +SETUP_ACTIONS = OrderedDict({ + # Install software + 'Installing Programs': {'Info': True}, + 'VCR': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': install_vcredists, 'Just run': True,}, + 'LibreOffice': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': install_libreoffice, + 'If answer': 'LibreOffice', 'KWArgs': {'quickstart': False, 'register_mso_types': True, 'use_mso_formats': True, 'vcredist': False}, + }, + 'Ninite bundle': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': install_ninite_bundle, 'KWArgs': {'cs': 'STARTED'},}, + + # Browsers + 'Scanning for browsers': {'Info': True}, + 'Scan': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': scan_for_browsers, 'Just run': True, 'KWArgs': {'skip_ie': True},}, + 'Backing up browsers': {'Info': True}, + 'Backup browsers': {'New': False, 'Fab': True, 'Cur': True, 'HW': False, 'Function': backup_browsers, 'Just run': True,}, + + # Install extensions + 'Installing Extensions': {'Info': True}, + 'Classic Shell skin': {'New': True, 'Fab': True, 'Cur': False, 'HW': False, 'Function': install_classicstart_skin, 'Win10 only': True,}, + 'Chrome extensions': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': install_chrome_extensions,}, + 'Firefox extensions': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': install_firefox_extensions,}, + + # Configure software' + 'Configuring Programs': {'Info': True}, + 'Browser add-ons': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': install_adblock, 'Just run': True, + 'Pause': 'Please enable uBlock Origin for all browsers', + }, + 'Classic Start': {'New': True, 'Fab': True, 'Cur': False, 'HW': False, 'Function': config_classicstart, 'Win10 only': True,}, + 'Config Windows Updates': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': config_windows_updates, 'Win10 only': True,}, + 'Enable Windows Updates': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': enable_windows_updates, 'KWArgs': {'silent': True},}, + 'Explorer (system)': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': config_explorer_system, 'Win10 only': True,}, + 'Explorer (user)': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': config_explorer_user, 'Win10 only': True,}, + 'Restart Explorer': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': restart_explorer,}, + 'Update Clock': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': update_clock,}, + + # Cleanup + 'Cleaning up': {'Info': True}, + 'AdwCleaner': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': cleanup_adwcleaner,}, + 'Desktop': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': cleanup_desktop,}, + 'KIT_NAME_FULL': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': delete_empty_folders,}, + + # System Info + 'Exporting system info': {'Info': True}, + 'AIDA64 Report': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': run_aida64,}, + 'File listing': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': backup_file_list,}, + 'Power plans': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': backup_power_plans,}, + 'Product Keys': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': run_produkey,}, + 'Registry': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': backup_registry,}, + + # Show Summary + 'Summary': {'Info': True}, + 'Operating System': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': show_os_name, 'KWArgs': {'ns': 'UNKNOWN', 'silent_function': False},}, + 'Activation': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': show_os_activation, 'KWArgs': {'ns': 'UNKNOWN', 'silent_function': False},}, + 'BIOS Activation': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': activate_with_bios, 'If not activated': True,}, + 'Secure Boot': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': check_secure_boot_status, 'KWArgs': {'show_alert': False},}, + 'Installed RAM': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': show_installed_ram, 'KWArgs': {'ns': 'UNKNOWN', 'silent_function': False},}, + 'Temp size': {'New': False, 'Fab': False, 'Cur': True, 'HW': False, 'Function': show_temp_files_size, 'KWArgs': {'ns': 'UNKNOWN', 'silent_function': False},}, + 'Show free space': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': show_free_space, 'Just run': True,}, + 'Installed AV': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': get_installed_antivirus, 'KWArgs': {'ns': 'UNKNOWN', 'print_return': True},}, + 'Installed Office': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': get_installed_office, 'KWArgs': {'ns': 'UNKNOWN', 'print_return': True},}, + 'Partitions 4K aligned': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': check_4k_alignment, 'KWArgs': {'cs': 'TRUE', 'ns': 'FALSE'},}, + + # Open things + 'Opening Programs': {'Info': True}, + 'Device Manager': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': open_device_manager, 'KWArgs': {'cs': 'STARTED'},}, + 'HWiNFO sensors': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': run_hwinfo_sensors, 'KWArgs': {'cs': 'STARTED'},}, + 'Speed test': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': open_speedtest, 'KWArgs': {'cs': 'STARTED'},}, + 'Windows Updates': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': open_windows_updates, 'KWArgs': {'cs': 'STARTED'},}, + 'Windows Activation': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Function': open_windows_activation, 'If not activated': True, 'KWArgs': {'cs': 'STARTED'},}, + 'Sleep': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': sleep, 'Just run': True, 'KWArgs': {'seconds': 3},}, + 'XMPlay': {'New': True, 'Fab': True, 'Cur': True, 'HW': True, 'Function': run_xmplay, 'KWArgs': {'cs': 'STARTED'},}, + }) +SETUP_ACTION_KEYS = ( + 'Function', + 'If not activated', + 'Info', + 'Just run', + 'KWArgs', + 'Pause', + ) +SETUP_QUESTIONS = { + # AV + 'MSE': {'New': None, 'Fab': None, 'Cur': None, 'HW': False, 'Ninite': True}, + + # LibreOffice + 'LibreOffice': {'New': None, 'Fab': None, 'Cur': None, 'HW': False, 'Ninite': True}, + + # Ninite + 'Base': {'New': True, 'Fab': True, 'Cur': True, 'HW': False, 'Ninite': True}, + 'Missing': {'New': False, 'Fab': True, 'Cur': False, 'HW': False, 'Ninite': True}, + 'Standard': {'New': True, 'Fab': True, 'Cur': False, 'HW': False, 'Ninite': True}, + } +# pylint: enable=bad-whitespace,line-too-long + + +# Functions +def check_os_and_abort(): + """Check OS and prompt to abort if not supported.""" + result = try_and_print( + message='OS support status...', + function=check_os_support_status, + cs='GOOD', + ) + if not result['CS'] and 'Unsupported' in result['Error']: + print_warning('OS version not supported by this script') + if not ask('Continue anyway? (NOT RECOMMENDED)'): + abort() + + +def get_actions(setup_mode, answers): + """Get actions to perform based on setup_mode, returns OrderedDict.""" + actions = OrderedDict({}) + for _key, _val in SETUP_ACTIONS.items(): + _action = {} + _if_answer = _val.get('If answer', False) + _win10_only = _val.get('Win10 only', False) + + # Set enabled status + _enabled = _val.get(setup_mode, False) + if _if_answer: + _enabled = _enabled and answers[_if_answer] + if _win10_only: + _enabled = _enabled and global_vars['OS']['Version'] == '10' + _action['Enabled'] = _enabled + + # Set other keys + for _sub_key in SETUP_ACTION_KEYS: + _action[_sub_key] = _val.get(_sub_key, None) + + # Fix KWArgs + if _action.get('KWArgs', {}) is None: + _action['KWArgs'] = {} + + # Handle "special" actions + if _key == 'KIT_NAME_FULL': + # Cleanup WK folders + _key = KIT_NAME_FULL + _action['KWArgs'] = {'folder_path': global_vars['ClientDir']} + elif _key == 'Ninite bundle': + # Add install_ninite_bundle() kwargs + _action['KWArgs'].update({ + kw.lower(): kv for kw, kv in answers.items() + if SETUP_QUESTIONS.get(kw, {}).get('Ninite', False) + }) + elif _key == 'Explorer (user)': + # Explorer settings (user) + _action['KWArgs'] = {'setup_mode': setup_mode} + + # Add to dict + actions[_key] = _action + + return actions + + +def get_answers(setup_mode): + """Get setup answers based on setup_mode and user input, returns dict.""" + answers = {k: v.get(setup_mode, False) for k, v in SETUP_QUESTIONS.items()} + + # Answer setup questions as needed + if answers['MSE'] is None and global_vars['OS']['Version'] == '7': + answers.update(get_av_selection()) + + if answers['LibreOffice'] is None: + answers['LibreOffice'] = ask('Install LibreOffice?') + + return answers + + +def get_av_selection(): + """Get AV selection.""" + av_answers = { + 'MSE': False, + } + av_options = [ + { + 'Name': 'Microsoft Security Essentials', + 'Disabled': global_vars['OS']['Version'] not in ['7'], + }, + ] + actions = [ + {'Name': 'None', 'Letter': 'N'}, + {'Name': 'Quit', 'Letter': 'Q'}, + ] + + # Show menu + selection = menu_select( + 'Please select an option to install', + main_entries=av_options, + action_entries=actions) + if selection.isnumeric(): + index = int(selection) - 1 + if 'Microsoft' in av_options[index]['Name']: + av_answers['MSE'] = True + elif selection == 'Q': + abort() + + return av_answers + + +def get_mode(): + """Get mode via menu_select, returns str.""" + setup_mode = None + mode_options = [ + {'Name': 'New', 'Display Name': 'New / Clean install (no data)'}, + {'Name': 'Data', 'Display Name': 'Clean install with data migration'}, + {'Name': 'Cur', 'Display Name': 'Original OS (post-repair or overinstall)'}, + {'Name': 'HW', 'Display Name': 'Hardware service (i.e. no software work)'}, + ] + actions = [ + {'Name': 'Quit', 'Letter': 'Q'}, + ] + + # Get selection + selection = menu_select( + 'Please select a setup mode', + main_entries=mode_options, + action_entries=actions) + if selection.isnumeric(): + index = int(selection) - 1 + setup_mode = mode_options[index]['Name'] + elif selection == 'Q': + abort() + + return setup_mode + + +def main(): + """Main function.""" + stay_awake() + clear_screen() + + # Check installed OS + check_os_and_abort() + + # Get setup mode + setup_mode = get_mode() + + # Get answers to setup questions + answers = get_answers(setup_mode) + + # Get actions to perform + actions = get_actions(setup_mode, answers) + + # Perform actions + for action, values in actions.items(): + kwargs = values.get('KWArgs', {}) + + # Print info lines + if values.get('Info', False): + print_info(action) + continue + + # Print disabled actions + if not values.get('Enabled', False): + show_data( + message='{}...'.format(action), + data='DISABLED', + warning=True, + ) + continue + + # Check Windows activation if requested + if values.get('If not activated', False) and windows_is_activated(): + # Skip + continue + + # Run function + if values.get('Just run', False): + values['Function'](**kwargs) + else: + result = try_and_print( + message='{}...'.format(action), + function=values['Function'], + other_results=OTHER_RESULTS, + **kwargs) + + # Wait for Ninite proc(s) + if action == 'Ninite bundle': + print_standard('Waiting for installations to finish...') + try: + for proc in result['Out']: + proc.wait() + except KeyboardInterrupt: + pass + + # Pause + if values.get('Pause', False): + print_standard(values['Pause']) + pause() + + # Show alert box for SecureBoot issues + try: + check_secure_boot_status(show_alert=True) + except Exception: # pylint: disable=broad-except + # Ignoring exceptions since we just want to show the popup + pass + + # Done + pause('Press Enter to exit... ') + + +if __name__ == '__main__': + try: + main() + exit_script() + except SystemExit as sys_exit: + exit_script(sys_exit.code) + except: # pylint: disable=bare-except + major_exception() diff --git a/.bin/Scripts/user_checklist.py b/.bin/Scripts/user_checklist.py deleted file mode 100644 index 0abd88f3..00000000 --- a/.bin/Scripts/user_checklist.py +++ /dev/null @@ -1,90 +0,0 @@ -# Wizard Kit: User Checklist - -import os -import sys - -# Init -sys.path.append(os.path.dirname(os.path.realpath(__file__))) -from functions.browsers import * -from functions.cleanup import * -from functions.setup import * -init_global_vars() -os.system('title {}: User Checklist Tool'.format(KIT_NAME_FULL)) -set_log_file('User Checklist ({USERNAME}).log'.format(**global_vars['Env'])) - -if __name__ == '__main__': - try: - stay_awake() - clear_screen() - print_info('{}: User Checklist\n'.format(KIT_NAME_FULL)) - other_results = { - 'Warning': { - 'NotInstalledError': 'Not installed', - 'NoProfilesError': 'No profiles found', - }} - answer_config_browsers = ask('Install adblock?') - if answer_config_browsers: - answer_reset_browsers = ask( - 'Reset browsers to safe defaults first?') - if global_vars['OS']['Version'] == '10': - answer_config_classicshell = ask('Configure ClassicShell?') - answer_config_explorer_user = ask('Configure Explorer?') - - # Cleanup - print_info('Cleanup') - try_and_print(message='Desktop...', - function=cleanup_desktop, cs='Done') - - # Scan for supported browsers - print_info('Scanning for browsers') - scan_for_browsers() - - # Homepages - print_info('Current homepages') - list_homepages() - - # Backup - print_info('Backing up browsers') - backup_browsers() - - # Reset - if answer_config_browsers and answer_reset_browsers: - print_info('Resetting browsers') - reset_browsers() - - # Configure - print_info('Configuring programs') - if answer_config_browsers: - install_adblock() - if global_vars['OS']['Version'] == '10': - if answer_config_classicshell: - try_and_print(message='ClassicStart...', - function=config_classicstart, cs='Done') - if answer_config_explorer_user: - try_and_print(message='Explorer...', - function=config_explorer_user, cs='Done') - if (not answer_config_browsers - and not answer_config_classicshell - and not answer_config_explorer_user): - print_warning(' Skipped') - else: - if not answer_config_browsers: - print_warning(' Skipped') - - # Restart Explorer - try_and_print(message='Restarting Explorer...', - function=restart_explorer, cs='Done') - - # Run speedtest - popen_program(['start', '', 'https://fast.com'], shell=True) - - # Done - print_standard('\nDone.') - pause('Press Enter to exit...') - exit_script() - except SystemExit as sys_exit: - exit_script(sys_exit.code) - except: - major_exception() - -# vim: sts=2 sw=2 ts=2