From 1dfc15b448df64ae9c445893da834678510f67bc Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 28 Aug 2024 00:29:33 +0200 Subject: [PATCH] Allow specifying a backup action --- scripts/Common/Scripts/Software.ps1 | 54 +++++++++++++++++------------ 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/scripts/Common/Scripts/Software.ps1 b/scripts/Common/Scripts/Software.ps1 index f7a3889f..15d11a33 100644 --- a/scripts/Common/Scripts/Software.ps1 +++ b/scripts/Common/Scripts/Software.ps1 @@ -197,6 +197,7 @@ $null = New-Module { function Start-SoftwareInstaller { param( [string] $Name, + [scriptblock] $Backup = $null, [scriptblock] $Installer = $null, [scriptblock] $Configurator = $null, [scriptblock] $UserConfigurator = $null, @@ -235,32 +236,41 @@ $null = New-Module { installer = $installHandler; arguments = $Arguments; }; - - if ($action -eq ([InstallerAction]::Install)) { - if ($Installer) { - Write-Host "Installing $Name…"; - & $Installer @argumentList; - } - & $installHandler @argumentList -Action ([InstallerAction]::Configure); + switch ($Action) { + ([InstallerAction]::Backup) { + if ($Backup) { + Write-Host "Backing up $Name…"; + & $Backup @argumentList; + } + } + ([InstallerAction]::Install) { + if ($Installer) { + Write-Host "Installing $Name…"; + & $Installer @argumentList; + } - if ($UserConfigurator -and (-not (Test-SetupUser))) { - & $installHandler @argumentList -Action ([InstallerAction]::ConfigureUser); + & $installHandler @argumentList -Action ([InstallerAction]::Configure); + + if ($UserConfigurator -and (-not (Test-SetupUser))) { + & $installHandler @argumentList -Action ([InstallerAction]::ConfigureUser); + } } - # ToDo: Automatically configure after installation - } elseif ($Action -eq ([InstallerAction]::Configure)) { - if ($Configurator) { - Write-Host "Configuring $Name…"; - & $Configurator @argumentList; + ([InstallerAction]::Configure) { + if ($Configurator) { + Write-Host "Configuring $Name…"; + & $Configurator @argumentList; + } } - } elseif ($Action -eq ([InstallerAction]::ConfigureUser)) { - if ((-not $Arguments.ContainsKey($userArgument)) -or (-not $Arguments[$userArgument])) { - $Arguments.Add($userArgument, ($IsWindows ? $env:UserName : $env:USER)); - } - - if ($UserConfigurator) { - Write-Host "Configuring $Name for user ``$($Arguments[$userArgument])``…"; - & $UserConfigurator @argumentList; + ([InstallerAction]::ConfigureUser) { + if ((-not $Arguments.ContainsKey($userArgument)) -or (-not $Arguments[$userArgument])) { + $Arguments.Add($userArgument, ($IsWindows ? $env:UserName : $env:USER)); + } + + if ($UserConfigurator) { + Write-Host "Configuring $Name for user ``$($Arguments[$userArgument])``…"; + & $UserConfigurator @argumentList; + } } } };