58 lines
2 KiB
PowerShell
58 lines
2 KiB
PowerShell
. "$PSScriptRoot/Config.ps1";
|
|
. "$PSScriptRoot/../Types/InstallerAction.ps1";
|
|
|
|
$null = New-Module {
|
|
. "$PSScriptRoot/../Types/InstallerAction.ps1";
|
|
$userArgument = "name";
|
|
|
|
function Start-SoftwareInstaller {
|
|
param(
|
|
[string] $Name,
|
|
[scriptblock] $Installer = { },
|
|
[scriptblock] $Configurator = { },
|
|
[scriptblock] $UserConfigurator = { },
|
|
[InstallerAction] $Action = [InstallerAction]::Install,
|
|
[hashtable] $Arguments
|
|
)
|
|
|
|
if (-not $Name) {
|
|
$Name = Split-Path -Leaf (Split-Path -Parent ((Get-PSCallStack)[1].ScriptName));
|
|
}
|
|
|
|
if ($null -ne $Name) {
|
|
$Name = "``$Name``";
|
|
} else {
|
|
$Name = "unknown software";
|
|
}
|
|
|
|
function Invoke-SoftwareInstaller {
|
|
param(
|
|
[InstallerAction] $Action,
|
|
[hashtable] $Arguments
|
|
)
|
|
|
|
if ($action -eq ([InstallerAction]::Install)) {
|
|
Write-Host "Installing $Name…";
|
|
& $Installer @Arguments;
|
|
} elseif ($Action -eq ([InstallerAction]::Configure)) {
|
|
Write-Host "Configuring $Name…";
|
|
& $Configurator @Arguments;
|
|
|
|
foreach ($user in Get-Users) {
|
|
$Arguments.Add($userArgument, $user);
|
|
Invoke-SoftwareInstaller -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));
|
|
}
|
|
|
|
Write-Host "Configuring $Name for user ``$($Arguments[$userArgument])``…";
|
|
& $UserConfigurator @Arguments;
|
|
}
|
|
}
|
|
|
|
Invoke-SoftwareInstaller -Action $Action -Arguments $Arguments;
|
|
}
|
|
}
|