Merge remote-tracking branch 'upstream/dev' into dev

This commit is contained in:
2Shirt 2021-05-13 21:37:56 -06:00
commit aff124dd8c
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
9 changed files with 73 additions and 72 deletions

View file

@ -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',

View file

@ -26,10 +26,10 @@ BOOT_ENTRIES = {
'/sources/boot.wim': 'UFD-WINPE',
}
BOOT_FILES = {
# Directory: extension
'/arch/boot/syslinux': 'cfg',
'/boot/grub': 'cfg',
'/EFI/boot': 'conf',
# Directory: extension
'/syslinux': 'cfg',
'/boot/grub': 'cfg',
'/EFI/boot': 'conf',
}
# Definitions: Sources and Destinations
@ -37,45 +37,44 @@ BOOT_FILES = {
## Sources use rsync's trailing slash syntax
ITEMS = {
'ESET SysRescue': (
('/boot/grub/', '/boot/grub/'),
('/casper/', '/casper/'),
('/EFI/boot/', '/EFI/ESET/'),
('/boot/grub/', '/boot/grub/'),
('/casper/', '/casper/'),
('/EFI/boot/', '/EFI/ESET/'),
),
'Extra Dir': (
('/', '/'),
('/', '/'),
),
'HDClone': (
('/bootenv', '/'),
('/kernel.map', '/'),
('/EFI/boot/', '/EFI/HDClone/'),
('/hdclone.iso', '/sources/'),
('/bootenv', '/'),
('/kernel.map', '/'),
('/EFI/boot/', '/EFI/HDClone/'),
('/hdclone.iso', '/sources/'),
),
'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 = (
@ -88,7 +87,7 @@ ITEMS_HIDDEN = (
'arch',
'arch_minimal',
'EFI',
'isolinux',
'syslinux',
# Main Kit
f'{KIT_NAME_FULL}/.bin',
f'{KIT_NAME_FULL}/.cbin',

View file

@ -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():

View file

@ -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]
@ -38,6 +39,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!
@ -52,9 +54,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
@ -97,12 +101,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,
)
@ -117,6 +122,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),
@ -138,7 +147,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
@ -162,7 +171,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,
)
@ -235,11 +244,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',
@ -251,7 +256,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
@ -285,17 +290,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):
@ -318,7 +322,7 @@ def install_syslinux_to_partition(partition):
'syslinux',
'--install',
'--directory',
'/arch/boot/syslinux/',
'/syslinux/',
partition,
]
run_program(cmd)

View file

@ -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()

View file

@ -228,7 +228,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',
@ -294,8 +294,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(

View file

@ -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:

View file

@ -122,7 +122,7 @@ function update_live_env() {
# Boot config (legacy)
mkdir -p "$PROFILE_DIR/arch"
cp "$ROOT_DIR/images/Syslinux.jpg" "$PROFILE_DIR/arch/syslinux.jpg"
cp "$ROOT_DIR/images/Syslinux.jpg" "$PROFILE_DIR/syslinux/syslinux.jpg"
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"

View file

@ -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