diff --git a/scripts/Common/Scripts/Software.ps1 b/scripts/Common/Scripts/Software.ps1 index 223db6ea..66a86dee 100644 --- a/scripts/Common/Scripts/Software.ps1 +++ b/scripts/Common/Scripts/Software.ps1 @@ -9,11 +9,13 @@ $null = New-Module { function Start-SoftwareInstaller { param( [string] $Name, + [scriptblock] $Base = $null, [scriptblock] $Backup = $null, [scriptblock] $Installer = $null, [scriptblock] $Configurator = $null, [scriptblock] $UserBackup = $null, [scriptblock] $UserConfigurator = $null, + [string] $Inherit, [Parameter(Position = 0)] [Nullable[InstallerAction]] $Action, [Parameter(Position = 1)] @@ -35,6 +37,14 @@ $null = New-Module { $Name = Split-Path -Leaf (Split-Path -Parent ((Get-PSCallStack)[1].ScriptName)); } + if ($Inherit) { + foreach ($script in @("Backup", "Installer", "Configurator", "UserBackup", "UserConfigurator")) { + if (-not (Get-Variable $script).Value) { + Set-Variable $script { & $Inherit -Action $Action @args }; + } + } + } + Start-Operation { $installHandler = { param( @@ -61,6 +71,7 @@ $null = New-Module { installer = $installHandler; arguments = $Arguments; context = $Context; + base = { & "$Inherit" -Action $Action $args }; }; switch ($Action) { diff --git a/scripts/Windows/Software/Oh My Posh/Manage.ps1 b/scripts/Windows/Software/Oh My Posh/Manage.ps1 index 5ca0dcc5..ead5bbe1 100644 --- a/scripts/Windows/Software/Oh My Posh/Manage.ps1 +++ b/scripts/Windows/Software/Oh My Posh/Manage.ps1 @@ -2,17 +2,8 @@ . "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; . "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1"; -& { - $base = "$PSScriptRoot/../../../Common/Software/Oh My Posh/Manage.ps1"; - - Start-SoftwareInstaller @args ` - -Installer { - Install-WingetPackage JanDeDobbeleer.OhMyPosh -ArgumentList "--scope", "machine"; - } ` - -Configurator { - . $base -Action ([InstallerAction]::Configure) @args; - } ` - -UserConfigurator { - . $base -Action ([InstallerAction]::ConfigureUser) @args; - }; -} @args; +Start-SoftwareInstaller @args ` + -Inherit "$PSScriptRoot/../../../Common/Software/Oh My Posh/Manage.ps1" ` + -Installer { + Install-WingetPackage JanDeDobbeleer.OhMyPosh -ArgumentList "--scope", "machine"; + }; diff --git a/scripts/Windows/Software/PowerShell/Manage.ps1 b/scripts/Windows/Software/PowerShell/Manage.ps1 index ba4a584c..a7971384 100644 --- a/scripts/Windows/Software/PowerShell/Manage.ps1 +++ b/scripts/Windows/Software/PowerShell/Manage.ps1 @@ -1,8 +1,4 @@ . "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; . "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1"; -Start-SoftwareInstaller @args ` - -Configurator { - . "$PSScriptRoot/../../../Common/Software/PowerShell/Manage.ps1" ` - -Action ([InstallerAction]::Configure); - }; +Start-SoftwareInstaller @args -Inherit "$PSScriptRoot/../../../Common/Software/PowerShell/Manage.ps1"; diff --git a/scripts/Windows/Software/aliae/Main.ps1 b/scripts/Windows/Software/aliae/Main.ps1 index 49643f5b..ab4b89a1 100644 --- a/scripts/Windows/Software/aliae/Main.ps1 +++ b/scripts/Windows/Software/aliae/Main.ps1 @@ -2,17 +2,8 @@ . "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; . "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1"; -& { - $base = "$PSScriptRoot/../../../Common/Software/aliae/Main.ps1"; - - Start-SoftwareInstaller @args ` - -Installer { - Install-WingetPackage JanDeDobbeleer.Aliae -ArgumentList "--scope", "machine"; - } ` - -Configurator { - . $base -Action ([InstallerAction]::Configure) @args; - } ` - -UserConfigurator { - . $base -Action ([InstallerAction]::ConfigureUser) @args; - }; -} @args; +Start-SoftwareInstaller @args ` + -Inherit "$PSScriptRoot/../../../Common/Software/aliae/Main.ps1" ` + -Installer { + Install-WingetPackage JanDeDobbeleer.Aliae -ArgumentList "--scope", "machine"; + }; diff --git a/scripts/Windows/Software/git/Manage.ps1 b/scripts/Windows/Software/git/Manage.ps1 index 8e32a4c9..edb77f0e 100644 --- a/scripts/Windows/Software/git/Manage.ps1 +++ b/scripts/Windows/Software/git/Manage.ps1 @@ -3,25 +3,15 @@ . "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; . "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1"; -& { - . "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1"; - $base = "$PSScriptRoot/../../../Common/Software/git/Manage.ps1"; +Start-SoftwareInstaller @args ` + -Inherit "$PSScriptRoot/../../../Common/Software/git/Manage.ps1" ` + -Installer { + $params = "/WindowsTerminalProfile"; + $defaultBranch = Get-OSConfig "git.defaultBranch"; - Start-SoftwareInstaller @args ` - -Installer { - $params = "/WindowsTerminalProfile"; - $defaultBranch = Get-OSConfig "git.defaultBranch"; + if ($defaultBranch) { + $params += " /DefaultBranchName:`"$defaultBranch`""; + } - if ($defaultBranch) { - $params += " /DefaultBranchName:`"$defaultBranch`""; - } - - Install-ChocoPackage git -ArgumentList "--params", $params; - } ` - -Configurator { - & $base ([InstallerAction]::Configure) @args; - } ` - -UserConfigurator { - & $base ([InstallerAction]::ConfigureUser) @args; - }; -} @args; + Install-ChocoPackage git -ArgumentList "--params", $params; + }; diff --git a/scripts/Windows/Software/vscode/Main.ps1 b/scripts/Windows/Software/vscode/Main.ps1 index b6482325..2da8b6da 100644 --- a/scripts/Windows/Software/vscode/Main.ps1 +++ b/scripts/Windows/Software/vscode/Main.ps1 @@ -1,16 +1,11 @@ -& { - . "$PSScriptRoot/../../Scripts/SoftwareManagement.ps1"; - . "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; - . "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1"; - $base = "$PSScriptRoot/../../../Common/Software/vscode/Main.ps1"; +. "$PSScriptRoot/../../Scripts/SoftwareManagement.ps1"; +. "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; +. "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1"; - Start-SoftwareInstaller @args ` - -Installer { - Install-ChocoPackage vscode -ArgumentList "--params", "/NoDesktopIcon"; - Install-ChocoPackage vscodium -ArgumentList "--params", "/NoDesktopIcon /AssociateWithFiles"; - refreshenv; - } ` - -UserConfigurator { - & $base ([InstallerAction]::ConfigureUser) @args; - }; -} @args; +Start-SoftwareInstaller @args ` + -Inherit "$PSScriptRoot/../../../Common/Software/vscode/Main.ps1" ` + -Installer { + Install-ChocoPackage vscode -ArgumentList "--params", "/NoDesktopIcon"; + Install-ChocoPackage vscodium -ArgumentList "--params", "/NoDesktopIcon /AssociateWithFiles"; + refreshenv; + }; diff --git a/scripts/Windows/Software/winget/Manage.ps1 b/scripts/Windows/Software/winget/Manage.ps1 index db5bdd69..71c871e0 100644 --- a/scripts/Windows/Software/winget/Manage.ps1 +++ b/scripts/Windows/Software/winget/Manage.ps1 @@ -1,16 +1,14 @@ . "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; -& { - Start-SoftwareInstaller @args ` - -Installer { - $xamlDownloadLink = "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx"; - $downloadLink = "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"; - $file = New-TemporaryFile; - $file = Rename-Item $file "$file.msixbundle" -PassThru; - Invoke-WebRequest "$xamlDownloadLink" -OutFile "$file"; - Add-AppxPackage "$file" -ErrorAction Continue; - Invoke-WebRequest "$downloadLink" -OutFile "$file"; - Add-AppxPackage "$file" -ErrorAction Continue; - Remove-Item $file; - }; -} @args; +Start-SoftwareInstaller @args ` + -Installer { + $xamlDownloadLink = "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx"; + $downloadLink = "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"; + $file = New-TemporaryFile; + $file = Rename-Item $file "$file.msixbundle" -PassThru; + Invoke-WebRequest "$xamlDownloadLink" -OutFile "$file"; + Add-AppxPackage "$file" -ErrorAction Continue; + Invoke-WebRequest "$downloadLink" -OutFile "$file"; + Add-AppxPackage "$file" -ErrorAction Continue; + Remove-Item $file; + }; diff --git a/scripts/Windows/Software/zoxide/Manage.ps1 b/scripts/Windows/Software/zoxide/Manage.ps1 index ce344796..64825eb5 100644 --- a/scripts/Windows/Software/zoxide/Manage.ps1 +++ b/scripts/Windows/Software/zoxide/Manage.ps1 @@ -1,16 +1,11 @@ -& { - . "$PSScriptRoot/../../Scripts/SoftwareManagement.ps1"; - . "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; - . "$PSScriptRoot/../../../Common/Software/PowerShell/Profile.ps1"; - . "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1"; - $base = "$PSScriptRoot/../../../Common/Software/zoxide/Main.ps1"; +. "$PSScriptRoot/../../Scripts/SoftwareManagement.ps1"; +. "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; +. "$PSScriptRoot/../../../Common/Software/PowerShell/Profile.ps1"; +. "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1"; - Start-SoftwareInstaller @args ` - -Installer { - Install-ChocoPackage zoxide; - Install-WingetPackage junegunn.fzf; - } ` - -Configurator { - & $base ([InstallerAction]::Configure) @args; - }; -} @args; +Start-SoftwareInstaller @args ` + -Inherit "$PSScriptRoot/../../../Common/Software/zoxide/Main.ps1" ` + -Installer { + Install-ChocoPackage zoxide; + Install-WingetPackage junegunn.fzf; + }; \ No newline at end of file