PortValhalla/scripts/Windows/Scripts/Software.ps1

58 lines
2 KiB
PowerShell
Raw Normal View History

2024-08-01 16:24:26 +00:00
. "$PSScriptRoot/Config.ps1";
. "$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-01 16:24:26 +00:00
[hashtable] $Arguments
)
2024-08-04 22:07:41 +00:00
if (-not $Name) {
$Name = Split-Path -Leaf (Split-Path -Parent ((Get-PSCallStack)[1].ScriptName));
}
2024-08-04 22:07:41 +00:00
if ($null -ne $Name) {
$Name = "``$Name``";
} else {
2024-08-04 22:07:41 +00:00
$Name = "unknown software";
}
2024-08-04 22:07:41 +00:00
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;
2024-08-01 16:24:26 +00:00
2024-08-04 22:07:41 +00:00
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;
2024-08-01 16:24:26 +00:00
}
}
2024-08-04 22:07:41 +00:00
Invoke-SoftwareInstaller -Action $Action -Arguments $Arguments;
2024-08-01 16:24:26 +00:00
}
}