Allow specifying a backup action

This commit is contained in:
Manuel Thalmann 2024-08-28 00:29:33 +02:00
parent 1c3a2fe2e7
commit 5dcf809caf

View file

@ -197,6 +197,7 @@ $null = New-Module {
function Start-SoftwareInstaller { function Start-SoftwareInstaller {
param( param(
[string] $Name, [string] $Name,
[scriptblock] $Backup = $null,
[scriptblock] $Installer = $null, [scriptblock] $Installer = $null,
[scriptblock] $Configurator = $null, [scriptblock] $Configurator = $null,
[scriptblock] $UserConfigurator = $null, [scriptblock] $UserConfigurator = $null,
@ -236,7 +237,14 @@ $null = New-Module {
arguments = $Arguments; arguments = $Arguments;
}; };
if ($action -eq ([InstallerAction]::Install)) { switch ($Action) {
([InstallerAction]::Backup) {
if ($Backup) {
Write-Host "Backing up $Name";
& $Backup @argumentList;
}
}
([InstallerAction]::Install) {
if ($Installer) { if ($Installer) {
Write-Host "Installing $Name"; Write-Host "Installing $Name";
& $Installer @argumentList; & $Installer @argumentList;
@ -247,13 +255,14 @@ $null = New-Module {
if ($UserConfigurator -and (-not (Test-SetupUser))) { if ($UserConfigurator -and (-not (Test-SetupUser))) {
& $installHandler @argumentList -Action ([InstallerAction]::ConfigureUser); & $installHandler @argumentList -Action ([InstallerAction]::ConfigureUser);
} }
# ToDo: Automatically configure after installation }
} elseif ($Action -eq ([InstallerAction]::Configure)) { ([InstallerAction]::Configure) {
if ($Configurator) { if ($Configurator) {
Write-Host "Configuring $Name"; Write-Host "Configuring $Name";
& $Configurator @argumentList; & $Configurator @argumentList;
} }
} elseif ($Action -eq ([InstallerAction]::ConfigureUser)) { }
([InstallerAction]::ConfigureUser) {
if ((-not $Arguments.ContainsKey($userArgument)) -or (-not $Arguments[$userArgument])) { if ((-not $Arguments.ContainsKey($userArgument)) -or (-not $Arguments[$userArgument])) {
$Arguments.Add($userArgument, ($IsWindows ? $env:UserName : $env:USER)); $Arguments.Add($userArgument, ($IsWindows ? $env:UserName : $env:USER));
} }
@ -263,6 +272,7 @@ $null = New-Module {
& $UserConfigurator @argumentList; & $UserConfigurator @argumentList;
} }
} }
}
}; };
& $installHandler -Action $Action -Arguments $Arguments; & $installHandler -Action $Action -Arguments $Arguments;