From 7ae59c021a5ab9e9b416812c9e87bd3b71f04fe8 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 b1268aa1..b94e724b 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -59,6 +59,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;