From 129b79d33c9ebd97deaed6e337df19069116e8eb Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Mon, 5 Aug 2024 22:29:20 +0200 Subject: [PATCH] Allow running further installer actions within an installer --- scripts/Windows/Scripts/Software.ps1 | 21 +++++++++++++-------- scripts/Windows/Software/Windows/Manage.ps1 | 7 +++++++ scripts/Windows/Software/winget/Manage.ps1 | 1 - 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/scripts/Windows/Scripts/Software.ps1 b/scripts/Windows/Scripts/Software.ps1 index da23f3ec..a1f16f48 100644 --- a/scripts/Windows/Scripts/Software.ps1 +++ b/scripts/Windows/Scripts/Software.ps1 @@ -25,33 +25,38 @@ $null = New-Module { $Name = "unknown software"; } - function Invoke-SoftwareInstaller { + $installHandler = { param( [InstallerAction] $Action, [hashtable] $Arguments ) + $argumentList = { + installer = $installHandler; + arguments = $Arguments; + }; + if ($action -eq ([InstallerAction]::Install)) { Write-Host "Installing $Name…"; - & $Installer @Arguments; + & $Installer @argumentList; } elseif ($Action -eq ([InstallerAction]::Configure)) { Write-Host "Configuring $Name…"; - & $Configurator @Arguments; + & $Configurator @argumentList; foreach ($user in Get-Users) { $Arguments.Add($userArgument, $user); - Invoke-SoftwareInstaller -Action ([InstallerAction]::ConfigureUser) -Arguments $Arguments; + & $installHandler -Action ([InstallerAction]::ConfigureUser) -Arguments $Arguments; } } elseif ($Action -eq ([InstallerAction]::ConfigureUser)) { if ((-not $Arguments.ContainsKey($userArgument)) -or ($null -eq $Arguments[$userArgument])) { - $Arguments.Add($userArgument, ($env:UserName)); + $argumentList.Add($userArgument, ($env:UserName)); } Write-Host "Configuring $Name for user ``$($Arguments[$userArgument])``…"; - & $UserConfigurator @Arguments; + & $UserConfigurator @argumentList; } - } + }; - Invoke-SoftwareInstaller -Action $Action -Arguments $Arguments; + & $installHandler -Action $Action -Arguments $Arguments; } } diff --git a/scripts/Windows/Software/Windows/Manage.ps1 b/scripts/Windows/Software/Windows/Manage.ps1 index 96bc684e..c2a1773c 100644 --- a/scripts/Windows/Software/Windows/Manage.ps1 +++ b/scripts/Windows/Software/Windows/Manage.ps1 @@ -12,6 +12,13 @@ param( . "$PSScriptRoot/../../Types/InstallerAction.ps1"; Start-SoftwareInstaller @PSBoundParameters ` + -Installer { + param( + [scriptblock] $Installer + ) + + & $Installer -Action ([InstallerAction]::Configure) + } ` -Configurator { $dir = New-TemporaryDirectory; Push-Location $dir; diff --git a/scripts/Windows/Software/winget/Manage.ps1 b/scripts/Windows/Software/winget/Manage.ps1 index 134e0b0b..897da9d5 100644 --- a/scripts/Windows/Software/winget/Manage.ps1 +++ b/scripts/Windows/Software/winget/Manage.ps1 @@ -8,7 +8,6 @@ param( Start-SoftwareInstaller @PSBoundParameters ` -Installer { - $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;