Allow running further installer actions within an installer
This commit is contained in:
parent
5ba6a48eac
commit
b1544a6a60
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue