2024-08-01 16:24:26 +00:00
|
|
|
. "$PSScriptRoot/Config.ps1";
|
2024-08-01 20:52:51 +00:00
|
|
|
. "$PSScriptRoot/../Types/InstallerAction.ps1";
|
2024-08-01 16:24:26 +00:00
|
|
|
|
2024-08-01 21:34:35 +00:00
|
|
|
$null = New-Module {
|
|
|
|
. "$PSScriptRoot/../Types/InstallerAction.ps1";
|
|
|
|
$userArgument = "name";
|
2024-08-01 16:24:26 +00:00
|
|
|
|
|
|
|
function Start-SoftwareInstaller {
|
|
|
|
param(
|
2024-08-04 22:07:41 +00:00
|
|
|
[string] $Name,
|
|
|
|
[scriptblock] $Installer = { },
|
|
|
|
[scriptblock] $Configurator = { },
|
|
|
|
[scriptblock] $UserConfigurator = { },
|
|
|
|
[InstallerAction] $Action = [InstallerAction]::Install,
|
2024-08-05 20:51:29 +00:00
|
|
|
[hashtable] $Arguments
|
2024-08-01 16:24:26 +00:00
|
|
|
)
|
|
|
|
|
2024-08-04 22:07:41 +00:00
|
|
|
if (-not $Name) {
|
|
|
|
$Name = Split-Path -Leaf (Split-Path -Parent ((Get-PSCallStack)[1].ScriptName));
|
|
|
|
}
|
2024-08-01 19:06:03 +00:00
|
|
|
|
2024-08-04 22:07:41 +00:00
|
|
|
if ($null -ne $Name) {
|
|
|
|
$Name = "``$Name``";
|
2024-08-01 19:06:03 +00:00
|
|
|
} else {
|
2024-08-04 22:07:41 +00:00
|
|
|
$Name = "unknown software";
|
2024-08-01 19:06:03 +00:00
|
|
|
}
|
|
|
|
|
2024-08-05 20:29:20 +00:00
|
|
|
$installHandler = {
|
2024-08-04 22:07:41 +00:00
|
|
|
param(
|
|
|
|
[InstallerAction] $Action,
|
|
|
|
[hashtable] $Arguments
|
|
|
|
)
|
|
|
|
|
2024-08-05 21:08:36 +00:00
|
|
|
$Arguments ??= @{ };
|
|
|
|
|
2024-08-05 20:45:17 +00:00
|
|
|
$argumentList = @{
|
2024-08-05 20:29:20 +00:00
|
|
|
installer = $installHandler;
|
|
|
|
arguments = $Arguments;
|
|
|
|
};
|
|
|
|
|
2024-08-04 22:07:41 +00:00
|
|
|
if ($action -eq ([InstallerAction]::Install)) {
|
|
|
|
Write-Host "Installing $Name…";
|
2024-08-05 20:29:20 +00:00
|
|
|
& $Installer @argumentList;
|
2024-08-04 22:07:41 +00:00
|
|
|
} elseif ($Action -eq ([InstallerAction]::Configure)) {
|
|
|
|
Write-Host "Configuring $Name…";
|
2024-08-05 20:29:20 +00:00
|
|
|
& $Configurator @argumentList;
|
2024-08-04 22:07:41 +00:00
|
|
|
|
|
|
|
foreach ($user in Get-Users) {
|
|
|
|
$Arguments.Add($userArgument, $user);
|
2024-08-05 20:49:44 +00:00
|
|
|
$argumentList.Add("action", [InstallerAction]::ConfigureUser);
|
|
|
|
& $installHandler @argumentList;
|
2024-08-04 22:07:41 +00:00
|
|
|
}
|
|
|
|
} elseif ($Action -eq ([InstallerAction]::ConfigureUser)) {
|
|
|
|
if ((-not $Arguments.ContainsKey($userArgument)) -or ($null -eq $Arguments[$userArgument])) {
|
2024-08-05 20:29:20 +00:00
|
|
|
$argumentList.Add($userArgument, ($env:UserName));
|
2024-08-04 22:07:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host "Configuring $Name for user ``$($Arguments[$userArgument])``…";
|
2024-08-05 20:29:20 +00:00
|
|
|
& $UserConfigurator @argumentList;
|
2024-08-01 16:24:26 +00:00
|
|
|
}
|
2024-08-05 20:29:20 +00:00
|
|
|
};
|
2024-08-04 22:07:41 +00:00
|
|
|
|
2024-08-05 20:29:20 +00:00
|
|
|
& $installHandler -Action $Action -Arguments $Arguments;
|
2024-08-01 16:24:26 +00:00
|
|
|
}
|
|
|
|
}
|