Allow running further installer actions within an installer

This commit is contained in:
Manuel Thalmann 2024-08-05 22:29:20 +02:00
parent 64c1f6e6e6
commit 53ac1902ac
3 changed files with 20 additions and 9 deletions

View file

@ -25,33 +25,38 @@ $null = New-Module {
$Name = "unknown software"; $Name = "unknown software";
} }
function Invoke-SoftwareInstaller { $installHandler = {
param( param(
[InstallerAction] $Action, [InstallerAction] $Action,
[hashtable] $Arguments [hashtable] $Arguments
) )
$argumentList = {
installer = $installHandler;
arguments = $Arguments;
};
if ($action -eq ([InstallerAction]::Install)) { if ($action -eq ([InstallerAction]::Install)) {
Write-Host "Installing $Name"; Write-Host "Installing $Name";
& $Installer @Arguments; & $Installer @argumentList;
} elseif ($Action -eq ([InstallerAction]::Configure)) { } elseif ($Action -eq ([InstallerAction]::Configure)) {
Write-Host "Configuring $Name"; Write-Host "Configuring $Name";
& $Configurator @Arguments; & $Configurator @argumentList;
foreach ($user in Get-Users) { foreach ($user in Get-Users) {
$Arguments.Add($userArgument, $user); $Arguments.Add($userArgument, $user);
Invoke-SoftwareInstaller -Action ([InstallerAction]::ConfigureUser) -Arguments $Arguments; & $installHandler -Action ([InstallerAction]::ConfigureUser) -Arguments $Arguments;
} }
} elseif ($Action -eq ([InstallerAction]::ConfigureUser)) { } elseif ($Action -eq ([InstallerAction]::ConfigureUser)) {
if ((-not $Arguments.ContainsKey($userArgument)) -or ($null -eq $Arguments[$userArgument])) { 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])``"; Write-Host "Configuring $Name for user ``$($Arguments[$userArgument])``";
& $UserConfigurator @Arguments; & $UserConfigurator @argumentList;
} }
} };
Invoke-SoftwareInstaller -Action $Action -Arguments $Arguments; & $installHandler -Action $Action -Arguments $Arguments;
} }
} }

View file

@ -12,6 +12,13 @@ param(
. "$PSScriptRoot/../../Types/InstallerAction.ps1"; . "$PSScriptRoot/../../Types/InstallerAction.ps1";
Start-SoftwareInstaller @PSBoundParameters ` Start-SoftwareInstaller @PSBoundParameters `
-Installer {
param(
[scriptblock] $Installer
)
& $Installer -Action ([InstallerAction]::Configure)
} `
-Configurator { -Configurator {
$dir = New-TemporaryDirectory; $dir = New-TemporaryDirectory;
Push-Location $dir; Push-Location $dir;

View file

@ -8,7 +8,6 @@ param(
Start-SoftwareInstaller @PSBoundParameters ` Start-SoftwareInstaller @PSBoundParameters `
-Installer { -Installer {
$xamlDownloadLink = "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx"; $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"; $downloadLink = "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle";
$file = New-TemporaryFile; $file = New-TemporaryFile;