Allow inheriting PowerShell installers

This commit is contained in:
Manuel Thalmann 2024-10-12 17:14:53 +02:00
parent 4504ca85d4
commit d9d1575a19
8 changed files with 64 additions and 97 deletions

View file

@ -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) {

View file

@ -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 `
-Inherit "$PSScriptRoot/../../../Common/Software/Oh My Posh/Manage.ps1" `
-Installer {
Install-WingetPackage JanDeDobbeleer.OhMyPosh -ArgumentList "--scope", "machine";
} `
-Configurator {
. $base -Action ([InstallerAction]::Configure) @args;
} `
-UserConfigurator {
. $base -Action ([InstallerAction]::ConfigureUser) @args;
};
} @args;

View file

@ -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";

View file

@ -2,17 +2,8 @@
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
. "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1";
& {
$base = "$PSScriptRoot/../../../Common/Software/aliae/Main.ps1";
Start-SoftwareInstaller @args `
-Inherit "$PSScriptRoot/../../../Common/Software/aliae/Main.ps1" `
-Installer {
Install-WingetPackage JanDeDobbeleer.Aliae -ArgumentList "--scope", "machine";
} `
-Configurator {
. $base -Action ([InstallerAction]::Configure) @args;
} `
-UserConfigurator {
. $base -Action ([InstallerAction]::ConfigureUser) @args;
};
} @args;

View file

@ -3,11 +3,8 @@
. "$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";
@ -17,11 +14,4 @@
}
Install-ChocoPackage git -ArgumentList "--params", $params;
} `
-Configurator {
& $base ([InstallerAction]::Configure) @args;
} `
-UserConfigurator {
& $base ([InstallerAction]::ConfigureUser) @args;
};
} @args;

View file

@ -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";
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;
} `
-UserConfigurator {
& $base ([InstallerAction]::ConfigureUser) @args;
};
} @args;

View file

@ -1,6 +1,5 @@
. "$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";
@ -13,4 +12,3 @@
Add-AppxPackage "$file" -ErrorAction Continue;
Remove-Item $file;
};
} @args;

View file

@ -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";
Start-SoftwareInstaller @args `
-Inherit "$PSScriptRoot/../../../Common/Software/zoxide/Main.ps1" `
-Installer {
Install-ChocoPackage zoxide;
Install-WingetPackage junegunn.fzf;
} `
-Configurator {
& $base ([InstallerAction]::Configure) @args;
};
} @args;