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)