From e83bcb864c8492a126b2792e488c578ae25ec85b Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 13 May 2021 21:04:39 -0600 Subject: [PATCH 1/5] Fix Autologon sections --- scripts/wk/cfg/tools.py | 2 ++ scripts/wk/repairs/win.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/wk/cfg/tools.py b/scripts/wk/cfg/tools.py index 289fd8b7..03eca518 100644 --- a/scripts/wk/cfg/tools.py +++ b/scripts/wk/cfg/tools.py @@ -13,6 +13,8 @@ SOURCES = { 'AdwCleaner': 'https://downloads.malwarebytes.com/file/adwcleaner', 'AIDA64': 'https://download.aida64.com/aida64engineer633.zip', 'aria2': 'https://github.com/aria2/aria2/releases/download/release-1.35.0/aria2-1.35.0-win-32bit-build1.zip', + 'Autologon32': 'http://live.sysinternals.com/Autologon.exe', + 'Autologon64': 'http://live.sysinternals.com/Autologon64.exe', 'Autoruns': 'https://download.sysinternals.com/files/Autoruns.zip', 'AVRemover32': 'https://download.eset.com/com/eset/tools/installers/av_remover/latest/avremover_nt32_enu.exe', 'AVRemover64': 'https://download.eset.com/com/eset/tools/installers/av_remover/latest/avremover_nt64_enu.exe', diff --git a/scripts/wk/repairs/win.py b/scripts/wk/repairs/win.py index 8e54dd63..5dd87a03 100644 --- a/scripts/wk/repairs/win.py +++ b/scripts/wk/repairs/win.py @@ -215,7 +215,7 @@ def end_session(): # Disable Autologon if is_autologon_enabled(): - run_tool('Sysinternals', 'Autologon') + run_tool('Sysinternals', 'Autologon', download=True) reg_set_value( 'HKLM', r'Software\Microsoft\Windows NT\CurrentVersion\Winlogon', 'AutoAdminLogon', '0', 'SZ', @@ -281,8 +281,8 @@ def init_run(options): if options['Use Autologon']['Selected'] and not is_autologon_enabled(): TRY_PRINT.run( 'Running Autologon...', run_tool, - 'Autologon', 'Autologon', - cbin=True, msg_good='DONE', + 'Sysinternals', 'Autologon', + download=True, msg_good='DONE', ) if options['Sync Clock']['Selected']: TRY_PRINT.run( From a5b0758d30331641c655d691044ce9b768f6fb4c Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 13 May 2021 21:08:38 -0600 Subject: [PATCH 2/5] Adjust exception formatting in TryAndPrint() --- scripts/wk/std.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/scripts/wk/std.py b/scripts/wk/std.py index 359d660b..eb75154b 100644 --- a/scripts/wk/std.py +++ b/scripts/wk/std.py @@ -419,37 +419,33 @@ class TryAndPrint(): def _format_exception_message(self, _exception): """Format using the exception's args or name, returns str.""" LOG.debug( - 'Formatting exception: %s', + 'Formatting exception: %s, %s', _exception.__class__.__name__, + _exception, ) - message = None + message = '' - # Use known argument index or first string found + # Format message string from _exception try: if isinstance(_exception, subprocess.CalledProcessError): message = _exception.stderr if not isinstance(message, str): message = message.decode('utf-8') message = message.strip() - elif isinstance(_exception, FileNotFoundError): - message = _exception.args[1] elif isinstance(_exception, ZeroDivisionError): - message = 'ZeroDivisionError' + # Skip and just use exception name below + pass else: - for arg in _exception.args: - if isinstance(arg, str): - message = arg - break + message = str(_exception) except Exception: # pylint: disable=broad-except # Just use the exception name instead pass - # Safety check - if not message: - try: - message = _exception.__class__.__name__ - except Exception: # pylint: disable=broad-except - message = 'UNKNOWN ERROR' + # Prepend exception name + try: + message = f'{_exception.__class__.__name__}: {message}' + except Exception: # pylint: disable=broad-except + message = f'UNKNOWN ERROR: {message}' # Fix multi-line messages if '\n' in message: From f3e3483b46ce9746fa2a88aa68396e4a01f45385 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 13 May 2021 21:21:34 -0600 Subject: [PATCH 3/5] Support new Archiso layout in UFD sections --- scripts/wk/cfg/ufd.py | 47 ++++++++++----------- scripts/wk/kit/ufd.py | 36 +++++++++------- setup/build_linux | 4 +- setup/linux/profile_base/syslinux/winpe.cfg | 2 +- 4 files changed, 46 insertions(+), 43 deletions(-) diff --git a/scripts/wk/cfg/ufd.py b/scripts/wk/cfg/ufd.py index d583b97a..c1c6b155 100644 --- a/scripts/wk/cfg/ufd.py +++ b/scripts/wk/cfg/ufd.py @@ -22,9 +22,9 @@ BOOT_ENTRIES = { '/sources/boot.wim': 'UFD-WINPE', } BOOT_FILES = { - # Directory: extension - '/arch/boot/syslinux': 'cfg', - '/EFI/boot': 'conf', + # Directory: extension + '/syslinux': 'cfg', + '/EFI/boot': 'conf', } # Definitions: Sources and Destinations @@ -32,34 +32,33 @@ BOOT_FILES = { ## Sources use rsync's trailing slash syntax ITEMS = { 'Extra Dir': ( - ('/', '/'), + ('/', '/'), ), 'Linux': ( - ('/arch', '/'), - ('/isolinux', '/'), - ('/EFI/boot', '/EFI/'), - ('/EFI/memtest86', '/EFI/'), + ('/arch', '/'), + ('/EFI/boot', '/EFI/'), + ('/syslinux', '/'), ), 'Linux (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/'), + ('/arch/boot/x86_64/initramfs-linux.img', '/arch_minimal/'), + ('/arch/boot/x86_64/vmlinuz-linux', '/arch_minimal/'), + ('/arch/pkglist.x86_64.txt', '/arch_minimal/'), + ('/arch/x86_64', '/arch_minimal/'), ), 'Main Kit': ( - ('/', f'/{KIT_NAME_FULL}/'), + ('/', f'/{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 = ( @@ -67,7 +66,7 @@ ITEMS_HIDDEN = ( 'arch', 'arch_minimal', 'EFI', - 'isolinux', + 'syslinux', # Main Kit f'{KIT_NAME_FULL}/.bin', f'{KIT_NAME_FULL}/.cbin', diff --git a/scripts/wk/kit/ufd.py b/scripts/wk/kit/ufd.py index 93d5b7ca..3236877e 100644 --- a/scripts/wk/kit/ufd.py +++ b/scripts/wk/kit/ufd.py @@ -19,7 +19,8 @@ from wk.os import linux DOCSTRING = '''WizardKit: Build UFD Usage: - build-ufd [options] --ufd-device PATH --linux PATH + build-ufd [options] --ufd-device PATH + [--linux PATH] [--linux-minimal PATH] [--main-kit PATH] [--winpe PATH] @@ -34,6 +35,7 @@ Options: -u PATH, --ufd-device PATH -w PATH, --winpe PATH + -d --debug Enable debug mode -h --help Show this page -M --use-mbr Use real MBR instead of GPT w/ Protective MBR -F --force Bypass all confirmation messages. USE WITH EXTREME CAUTION! @@ -48,9 +50,11 @@ UFD_LABEL = f'{KIT_NAME_SHORT}_UFD' def build_ufd(): """Build UFD using selected sources.""" args = docopt(DOCSTRING) + if args['--debug']: + log.enable_debug_mode() log.update_log_path(dest_name='build-ufd', timestamp=True) try_print = std.TryAndPrint() - try_print.add_error(FileNotFoundError) + try_print.add_error('FileNotFoundError') try_print.catch_all = False try_print.verbose = True try_print.indent = 2 @@ -93,12 +97,13 @@ def build_ufd(): dev_path=ufd_dev, label=UFD_LABEL, ) + ufd_dev_first_partition = find_first_partition(ufd_dev) # Mount UFD try_print.run( message='Mounting UFD...', function=linux.mount, - source=find_first_partition(ufd_dev), + source=ufd_dev_first_partition, mount_point='/mnt/UFD', read_write=True, ) @@ -113,6 +118,10 @@ def build_ufd(): # Copy sources std.print_standard(' ') std.print_info('Copy Sources') + try_print.run( + 'Copying Memtest86...', io.recursive_copy, + '/usr/share/memtest86-efi/', '/mnt/UFD/EFI/Memtest86/', overwrite=True, + ) for s_label, s_path in sources.items(): try_print.run( message='Copying {}...'.format(s_label), @@ -134,7 +143,7 @@ def build_ufd(): try_print.run( message='Syslinux (partition)...', function=install_syslinux_to_partition, - partition=find_first_partition(ufd_dev), + partition=ufd_dev_first_partition, ) # Unmount UFD @@ -158,7 +167,7 @@ def build_ufd(): try_print.run( message='Hiding items...', function=hide_items, - ufd_dev=ufd_dev, + ufd_dev_first_partition=ufd_dev_first_partition, items=ITEMS_HIDDEN, ) @@ -231,11 +240,7 @@ def create_table(dev_path, use_mbr=False): def find_first_partition(dev_path): - """Find path to first partition of dev, returns str. - - NOTE: This assumes the dev was just partitioned with - a single partition. - """ + """Find path to first partition of dev, returns str.""" cmd = [ 'lsblk', '--list', @@ -247,7 +252,7 @@ def find_first_partition(dev_path): # Run cmd proc = run_program(cmd) - part_path = proc.stdout.splitlines()[-1].strip() + part_path = proc.stdout.splitlines()[1].strip() # Done return part_path @@ -281,17 +286,16 @@ def get_uuid(path): return proc.stdout.strip() -def hide_items(ufd_dev, items): +def hide_items(ufd_dev_first_partition, items): """Set FAT32 hidden flag for items.""" - first_partition = find_first_partition(ufd_dev) with open('/root/.mtoolsrc', 'w') as _f: - _f.write(f'drive U: file="{first_partition}"\n') + _f.write(f'drive U: file="{ufd_dev_first_partition}"\n') _f.write('mtools_skip_check=1\n') # Hide items for item in items: cmd = [f'yes | sudo mattrib +h "U:/{item}"'] - run_program(cmd, shell=True) + run_program(cmd, shell=True, check=False) def install_syslinux_to_dev(ufd_dev, use_mbr): @@ -314,7 +318,7 @@ def install_syslinux_to_partition(partition): 'syslinux', '--install', '--directory', - '/arch/boot/syslinux/', + '/syslinux/', partition, ] run_program(cmd) diff --git a/setup/build_linux b/setup/build_linux index 063b0792..bafe0e8b 100755 --- a/setup/build_linux +++ b/setup/build_linux @@ -122,8 +122,8 @@ function update_live_env() { # Boot config (legacy) mkdir -p "$PROFILE_DIR/arch" - cp "$ROOT_DIR/images/Pxelinux.png" "$PROFILE_DIR/arch/pxelinux.png" - cp "$ROOT_DIR/images/Syslinux.png" "$PROFILE_DIR/arch/syslinux.png" + cp "$ROOT_DIR/images/Pxelinux.png" "$PROFILE_DIR/syslinux/pxelinux.png" + cp "$ROOT_DIR/images/Syslinux.png" "$PROFILE_DIR/syslinux/syslinux.png" sed -i -r "s/__+/$KIT_NAME_FULL/" "$PROFILE_DIR/syslinux/syslinux.cfg" mkdir -p "$TEMP_DIR" 2>/dev/null curl -Lo "$TEMP_DIR/wimboot.zip" "http://git.ipxe.org/releases/wimboot/wimboot-latest.zip" diff --git a/setup/linux/profile_base/syslinux/winpe.cfg b/setup/linux/profile_base/syslinux/winpe.cfg index 3cc4d5a5..601c07d1 100644 --- a/setup/linux/profile_base/syslinux/winpe.cfg +++ b/setup/linux/profile_base/syslinux/winpe.cfg @@ -5,4 +5,4 @@ A live Windows environment ENDTEXT MENU LABEL Windows PE COM32 linux.c32 -APPEND /%INSTALL_DIR%/boot/wimboot gui initrdfile=/sources/bootmgr,/sources/BCD,/sources/boot.sdi,/sources/boot.wim +APPEND wimboot gui initrdfile=/sources/bootmgr,/sources/BCD,/sources/boot.sdi,/sources/boot.wim From 32b25f912d6d438b3b796964c7e5dc7002a687db Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 13 May 2021 21:30:52 -0600 Subject: [PATCH 4/5] Remove with_stem() usage to support Python 3.8 --- scripts/wk/kit/tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/wk/kit/tools.py b/scripts/wk/kit/tools.py index 895c9470..bed41823 100644 --- a/scripts/wk/kit/tools.py +++ b/scripts/wk/kit/tools.py @@ -81,7 +81,7 @@ def download_tool(folder, name): # Get ARCH specific URL if available if name_arch in SOURCES: source_url = SOURCES[name_arch] - out_path = out_path.with_stem(name_arch) + out_path = out_path.with_name(f'{name_arch}{out_path.suffix}') else: source_url = SOURCES[name] @@ -153,7 +153,7 @@ def get_tool_path(folder, name, check=True): tool_path = bin_dir.joinpath(f'{folder}/{name_arch}.exe') if not (tool_path.exists() or name_arch in SOURCES): # Use "default" path instead - tool_path = tool_path.with_stem(name) + tool_path = tool_path.with_name(f'{name}.exe') # Missing? if check and not tool_path.exists(): From 527a5b2e97a0f0fbfb450a866d7396606560284b Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 13 May 2021 21:32:46 -0600 Subject: [PATCH 5/5] Avoid crash during HW Diagnostics --- scripts/wk/os/linux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/wk/os/linux.py b/scripts/wk/os/linux.py index db7212b3..73e6d85b 100644 --- a/scripts/wk/os/linux.py +++ b/scripts/wk/os/linux.py @@ -151,7 +151,7 @@ def mount_volumes(device_path=None, read_write=False, scan_corestorage=False): result += 'Failed to mount' report.append(std.color_string(result, 'RED')) continue - result += f'{"Mounted on "+vol.details.get("mountpoint", "?"):<40}' + result += f'{"Mounted on "+str(vol.details.get("mountpoint", "?")):<40}' # Add size to result vol.get_details()