From 5bb1a19a1f6fd574d4f53817da477eff4e27712f Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 1 Aug 2024 18:58:33 +0200 Subject: [PATCH] Install `winget` if nonexistent --- scripts/Windows/OS/Install.ps1 | 5 +++++ scripts/Windows/Software/winget/Manage.ps1 | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 scripts/Windows/Software/winget/Manage.ps1 diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index 52c8ec14..5866787c 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -60,6 +60,11 @@ function Start-InstallationLoop { continue; } + if (-not (Test-Command winget)) { + . "$PSScriptRoot/../Software/winget/Manage.ps1"; + continue; + } + if (-not (& { wsl --status; $?; })) { wsl --install --no-launch; Restart-Intermediate; diff --git a/scripts/Windows/Software/winget/Manage.ps1 b/scripts/Windows/Software/winget/Manage.ps1 new file mode 100644 index 00000000..734f4583 --- /dev/null +++ b/scripts/Windows/Software/winget/Manage.ps1 @@ -0,0 +1,20 @@ +param( + [string] $Action = ([InstallerAction]::Install), + [hashtable] $Arguments +) + +. "$PSScriptRoot/../../Scripts/Software.ps1"; + +function Install-Software { + $xamlDownloadLink = "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx"; + $downloadLink = "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"; + $file = New-TemporaryFile; + $file = Rename-Item $file "$file.msixbundle" -PassThru; + Invoke-WebRequest "$xamlDownloadLink" -OutFile "$file"; + Add-AppxPackage "$file"; + Invoke-WebRequest "$downloadLink" -OutFile "$file"; + Add-AppxPackage "$file"; + Remove-Item $file; +} + +Start-SoftwareInstaller -Action $Action -Arguments $Arguments;