From 3ff61e9948dc7cd1760c6662bffe0204c37867e4 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 25 Jun 2023 02:22:04 -0700 Subject: [PATCH] Add winget import support --- scripts/wk/cfg/sources.py | 8 ------- scripts/wk/cfg/winget/default.json | 32 ++++++++++++++++++++++++++++ scripts/wk/cfg/winget/vcredists.json | 29 +++++++++++++++++++++++++ scripts/wk/os/win.py | 24 +++++++++++++++++++++ 4 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 scripts/wk/cfg/winget/default.json create mode 100644 scripts/wk/cfg/winget/vcredists.json diff --git a/scripts/wk/cfg/sources.py b/scripts/wk/cfg/sources.py index 16235639..88730320 100644 --- a/scripts/wk/cfg/sources.py +++ b/scripts/wk/cfg/sources.py @@ -25,14 +25,6 @@ SOURCES = { 'Software Bundle': 'https://ninite.com/.net4.8-7zip-chrome-edge-vlc/ninite.exe', 'TDSSKiller': 'https://media.kaspersky.com/utilities/VirusUtilities/EN/tdsskiller.exe', - # Visual C++ Runtimes: https://docs.microsoft.com/en-US/cpp/windows/latest-supported-vc-redist - 'VCRedist_2012_x32': 'https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x86.exe', - 'VCRedist_2012_x64': 'https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe', - 'VCRedist_2013_x32': 'https://aka.ms/highdpimfc2013x86enu', - 'VCRedist_2013_x64': 'https://aka.ms/highdpimfc2013x64enu', - 'VCRedist_2022_x32': 'https://aka.ms/vs/17/release/vc_redist.x86.exe', - 'VCRedist_2022_x64': 'https://aka.ms/vs/17/release/vc_redist.x64.exe', - # Build Kit 'AIDA64': 'https://download.aida64.com/aida64engineer675.zip', 'Adobe Reader DC': 'https://ardownload2.adobe.com/pub/adobe/reader/win/AcrobatDC/2200220191/AcroRdrDC2200220191_en_US.exe', diff --git a/scripts/wk/cfg/winget/default.json b/scripts/wk/cfg/winget/default.json new file mode 100644 index 00000000..a3497a32 --- /dev/null +++ b/scripts/wk/cfg/winget/default.json @@ -0,0 +1,32 @@ +{ + "$schema": "https://aka.ms/winget-packages.schema.2.0.json", + "CreationDate": "2023-06-25T01:40:45.003-00:00", + "Sources": [ + { + "Packages": [ + { + "PackageIdentifier": "7zip.7zip" + }, + { + "PackageIdentifier": "Google.Chrome" + }, + { + "PackageIdentifier": "Microsoft.Edge" + }, + { + "PackageIdentifier": "Mozilla.Firefox" + }, + { + "PackageIdentifier": "VideoLAN.VLC" + } + ], + "SourceDetails": { + "Argument": "https://cdn.winget.microsoft.com/cache", + "Identifier": "Microsoft.Winget.Source_8wekyb3d8bbwe", + "Name": "winget", + "Type": "Microsoft.PreIndexed.Package" + } + } + ], + "WinGetVersion": "1.4.11071" +} diff --git a/scripts/wk/cfg/winget/vcredists.json b/scripts/wk/cfg/winget/vcredists.json new file mode 100644 index 00000000..b638cb4f --- /dev/null +++ b/scripts/wk/cfg/winget/vcredists.json @@ -0,0 +1,29 @@ +{ + "$schema": "https://aka.ms/winget-packages.schema.2.0.json", + "CreationDate": "2023-06-25T01:40:45.003-00:00", + "Sources": [ + { + "Packages": [ + { + "PackageIdentifier": "Microsoft.VCRedist.2013.x64" + }, + { + "PackageIdentifier": "Microsoft.VCRedist.2013.x86" + }, + { + "PackageIdentifier": "Microsoft.VCRedist.2015+.x64" + }, + { + "PackageIdentifier": "Microsoft.VCRedist.2015+.x86" + } + ], + "SourceDetails": { + "Argument": "https://cdn.winget.microsoft.com/cache", + "Identifier": "Microsoft.Winget.Source_8wekyb3d8bbwe", + "Name": "winget", + "Type": "Microsoft.PreIndexed.Package" + } + } + ], + "WinGetVersion": "1.4.11071" +} diff --git a/scripts/wk/os/win.py b/scripts/wk/os/win.py index 1e6ea48c..ad1ed272 100644 --- a/scripts/wk/os/win.py +++ b/scripts/wk/os/win.py @@ -762,6 +762,30 @@ def winget_check(raise_exceptions: bool = False) -> None: raise GenericError('Failed to install') +def winget_import(group_name: str = 'default', upgrade: bool = False) -> None: + """Use winget to import a set of applications. + + group_name should be the name of a JSON file exported from winget. + + NOTE: The path is relative to .bin/Scripts/wk/cfg/winget/ + """ + cmd = [ + 'winget', + 'import', '--import-file', + str(find_kit_dir('Scripts').joinpath(f'wk/cfg/winget/{group_name}.json')), + '' if upgrade else '--no-upgrade', + ] + tmp_file = fr'{os.environ.get("TMP")}\run_winget.cmd' + if CONEMU: + with open(tmp_file, 'w', encoding='utf-8') as _f: + _f.write('@echo off\n') + _f.write(" ".join(cmd)) + cmd = ('cmd', '/c', tmp_file, '-new_console:n', '-new_console:s33V') + run_program(cmd, check=False, pipe=False) + sleep(1) + wait_for_procs('winget.exe') + + def winget_upgrade() -> None: """Upgrade all supported programs with winget, returns subprocess.Popen.""" cmd = ['winget', 'upgrade', '--all']