Make software name available in scripts

This commit is contained in:
Manuel Thalmann 2024-09-23 02:10:42 +02:00
parent 50b4a30256
commit 5ae07886c8
15 changed files with 116 additions and 50 deletions

View file

@ -317,21 +317,25 @@ $null = New-Module {
} }
Start-Operation { Start-Operation {
if ($null -ne $Name) {
$Name = "``$Name``";
} else {
$Name = "unknown software";
}
$installHandler = { $installHandler = {
param( param(
[string] $Name,
[InstallerAction] $Action, [InstallerAction] $Action,
[hashtable] $Arguments [hashtable] $Arguments
) )
[string] $DisplayName = $null;
if ($null -ne $Name) {
$DisplayName = "``$Name``";
} else {
$DisplayName = "unknown software";
}
$Arguments ??= @{ }; $Arguments ??= @{ };
$argumentList = @{ $argumentList = @{
name = $Name;
installer = $installHandler; installer = $installHandler;
arguments = $Arguments; arguments = $Arguments;
}; };
@ -339,13 +343,13 @@ $null = New-Module {
switch ($Action) { switch ($Action) {
([InstallerAction]::Backup) { ([InstallerAction]::Backup) {
if ($Backup) { if ($Backup) {
Write-Host "Backing up $Name"; Write-Host "Backing up $DisplayName";
& $Backup @argumentList; & $Backup @argumentList;
} }
} }
([InstallerAction]::Install) { ([InstallerAction]::Install) {
if ($Installer) { if ($Installer) {
Write-Host "Installing $Name"; Write-Host "Installing $DisplayName";
& $Installer @argumentList; & $Installer @argumentList;
} }
@ -357,7 +361,7 @@ $null = New-Module {
} }
([InstallerAction]::Configure) { ([InstallerAction]::Configure) {
if ($Configurator) { if ($Configurator) {
Write-Host "Configuring $Name"; Write-Host "Configuring $DisplayName";
& $Configurator @argumentList; & $Configurator @argumentList;
} }
} }
@ -372,13 +376,13 @@ $null = New-Module {
switch ($_) { switch ($_) {
([InstallerAction]::BackupUser) { ([InstallerAction]::BackupUser) {
if ($UserBackup) { if ($UserBackup) {
Write-Host "Backing up $Name for user ``$user``"; Write-Host "Backing up $DisplayName for user ``$user``";
& $UserBackup @argumentList; & $UserBackup @argumentList;
} }
} }
([InstallerAction]::ConfigureUser) { ([InstallerAction]::ConfigureUser) {
if ($UserConfigurator) { if ($UserConfigurator) {
Write-Host "Configuring $Name for user ``$user``"; Write-Host "Configuring $DisplayName for user ``$user``";
& $UserConfigurator @argumentList; & $UserConfigurator @argumentList;
} }
} }
@ -387,7 +391,7 @@ $null = New-Module {
} }
}; };
& $installHandler -Action $Action -Arguments $Arguments; & $installHandler -Name $Name -Action $Action -Arguments $Arguments;
}; };
} }
} }

View file

@ -10,9 +10,11 @@ param (
Start-SoftwareInstaller @PSBoundParameters ` Start-SoftwareInstaller @PSBoundParameters `
-Configurator { -Configurator {
param([string] $Name)
Add-PowerShellProfileStatement ` Add-PowerShellProfileStatement `
-System ` -System `
-Category "oh-my-posh" ` -Category "$Name" `
-Script ( -Script (
@( @(
"# Oh My Posh!", "# Oh My Posh!",

View file

@ -9,6 +9,7 @@ param(
Start-SoftwareInstaller @PSBoundParameters ` Start-SoftwareInstaller @PSBoundParameters `
-Configurator { -Configurator {
param([string] $Name)
. "$PSScriptRoot/Constants.ps1"; . "$PSScriptRoot/Constants.ps1";
$pathExpression = Get-GlobalConfigExpression; $pathExpression = Get-GlobalConfigExpression;
$path = Get-GlobalConfigPath; $path = Get-GlobalConfigPath;
@ -17,7 +18,7 @@ Start-SoftwareInstaller @PSBoundParameters `
Add-PowerShellProfileStatement ` Add-PowerShellProfileStatement `
-System ` -System `
-Category "aliae" ` -Category $Name `
-Script ( -Script (
@( @(
{ {

View file

@ -8,12 +8,14 @@ param(
Start-SoftwareInstaller @PSBoundParameters ` Start-SoftwareInstaller @PSBoundParameters `
-Configurator { -Configurator {
param([string] $Name)
Add-PowerShellProfileStatement ` Add-PowerShellProfileStatement `
-System ` -System `
-Category "zoxide" ` -Category "$Name" `
-Script ( -Script (
@( @(
"# zoxide", "# $Name",
(Get-ScriptInitializer "zoxide init powershell | Out-String") (Get-ScriptInitializer "zoxide init powershell | Out-String")
) -join [System.Environment]::NewLine); ) -join [System.Environment]::NewLine);
}; };

View file

@ -63,21 +63,23 @@ param(
} ` } `
-UserBackup { -UserBackup {
param( param(
[string] $Name,
[hashtable] $Arguments [hashtable] $Arguments
) )
Edit-LGHubConfig { Edit-LGHubConfig {
Add-BackupArtifacts -User $Arguments.Name -Source $configPath -Path "LGHub" ` Add-BackupArtifacts -User $Arguments.Name -Source $configPath -Path "$Name" `
-Include @("settings.db", "icon_cache") -Include @("settings.db", "icon_cache")
}; };
} ` } `
-UserConfigurator { -UserConfigurator {
param( param(
[string] $Name,
[hashtable] $Arguments [hashtable] $Arguments
) )
Edit-LGHubConfig { Edit-LGHubConfig {
Expand-BackupArtifacts -User $Arguments.Name -Path "LGHub" -Target $configPath; Expand-BackupArtifacts -User $Arguments.Name -Path "$Name" -Target $configPath;
}; };
}; };
} $PSBoundParameters; } $PSBoundParameters;

View file

@ -17,10 +17,11 @@ param(
} ` } `
-UserBackup { -UserBackup {
param( param(
[string] $Name,
[hashtable] $Arguments [hashtable] $Arguments
) )
Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "ManiaPlanet" ` Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "$Name" `
-Include @( -Include @(
"Actions", "Actions",
"Blocks", "Blocks",
@ -36,9 +37,10 @@ param(
} ` } `
-UserConfigurator { -UserConfigurator {
param( param(
[string] $Name,
[hashtable] $Arguments [hashtable] $Arguments
) )
Expand-BackupArtifacts -User $Arguments.Name -Path "ManiaPlanet" -Target $path; Expand-BackupArtifacts -User $Arguments.Name -Path "$Name" -Target $path;
}; };
} $PSBoundParameters; } $PSBoundParameters;

View file

@ -14,18 +14,26 @@ Start-SoftwareInstaller @PSBoundParameters `
Install-ChocoPackage putty; Install-ChocoPackage putty;
} ` } `
-UserBackup { -UserBackup {
param([hashtable] $Arguments) param(
[string] $Name,
[hashtable] $Arguments
)
$dir = New-TemporaryDirectory; $dir = New-TemporaryDirectory;
$fileName = Join-Path "$dir" PuTTY.reg; $fileName = Join-Path "$dir" PuTTY.reg;
& reg export "HKCU\Software\SimonTatham\PuTTY" $fileName /y; & reg export "HKCU\Software\SimonTatham\PuTTY" $fileName /y;
Add-BackupArtifacts -User $Arguments.Name -Source $fileName -Path "PuTTY/PuTTY.reg"; Add-BackupArtifacts -User $Arguments.Name -Source $fileName -Path "$Name/$Name.reg";
Remove-Item -Recurse -Force $dir; Remove-Item -Recurse -Force $dir;
} ` } `
-UserConfigurator { -UserConfigurator {
param([hashtable] $Arguments) param(
[string] $Name,
[hashtable] $Arguments
)
$dir = New-TemporaryDirectory; $dir = New-TemporaryDirectory;
$fileName = Join-Path "$dir" PuTTY.reg; $fileName = Join-Path "$dir" PuTTY.reg;
Expand-BackupArtifacts -User $Arguments.Name -Path "PuTTY/PuTTY.reg" -Target $fileName; Expand-BackupArtifacts -User $Arguments.Name -Path "$Name/$Name.reg" -Target $fileName;
& reg import $fileName; & reg import $fileName;
Remove-Item -Recurse -Force $dir; Remove-Item -Recurse -Force $dir;
}; };

View file

@ -12,7 +12,9 @@ param(
Start-SoftwareInstaller @Parameters ` Start-SoftwareInstaller @Parameters `
-Backup { -Backup {
Add-BackupArtifacts -Path "RetroArch" -Source $path ` param([string] $Name)
Add-BackupArtifacts -Path "$Name" -Source $path `
-Include @( -Include @(
"config", "config",
"cores", "cores",
@ -29,7 +31,8 @@ param(
Install-ChocoPackage retroarch; Install-ChocoPackage retroarch;
} ` } `
-Configurator { -Configurator {
param([string] $Name)
Add-StartMenuIcon "RetroArch" "C:\tools\RetroArch-Win64\retroarch.exe"; Add-StartMenuIcon "RetroArch" "C:\tools\RetroArch-Win64\retroarch.exe";
Expand-BackupArtifacts -Path "RetroArch" -Target $path; Expand-BackupArtifacts -Path "$Name" -Target $path;
}; };
} $PSBoundParameters; } $PSBoundParameters;

View file

@ -23,10 +23,14 @@ param(
Remove-DesktopIcon "*TmNationsForever*"; Remove-DesktopIcon "*TmNationsForever*";
} ` } `
-UserBackup { -UserBackup {
param([hashtable] $Arguments) param(
[string] $Name,
[hashtable] $Arguments
)
$name = $Arguments.Name; $name = $Arguments.Name;
Add-BackupArtifacts -User $name -Source $path -Path "TmNationsForever" ` Add-BackupArtifacts -User $name -Source $path -Path "$Name" `
-Include @( -Include @(
"ChallengeMusics", "ChallengeMusics",
"MediaTracker", "MediaTracker",
@ -38,8 +42,12 @@ param(
); );
} ` } `
-UserConfigurator { -UserConfigurator {
param([hashtable] $Arguments) param(
$name = $Arguments.Name; [string] $Name,
Expand-BackupArtifacts -User $name -Path "TmNationsForever" -Target $path; [hashtable] $Arguments
)
$user = $Arguments.Name;
Expand-BackupArtifacts -User $user -Path "$Name" -Target $path;
}; };
} $PSBoundParameters; } $PSBoundParameters;

View file

@ -35,8 +35,12 @@ param(
Remove-Item -Recurse $dir; Remove-Item -Recurse $dir;
} ` } `
-UserBackup { -UserBackup {
param([hashtable] $Arguments) param(
Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "TmUnitedForever" ` [string] $Name,
[hashtable] $Arguments
)
Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "$Name" `
-Include @( -Include @(
"ChallengeMusics", "ChallengeMusics",
"MediaTracker", "MediaTracker",
@ -47,7 +51,11 @@ param(
); );
} ` } `
-UserConfigurator { -UserConfigurator {
param([hashtable] $Arguments) param(
Expand-BackupArtifacts -User $Arguments.Name -Path "TmUnitedForever" -Target $path; [string] $Name,
[hashtable] $Arguments
)
Expand-BackupArtifacts -User $Arguments.Name -Path "$Name" -Target $path;
}; };
} $PSBoundParameters; } $PSBoundParameters;

View file

@ -36,14 +36,17 @@ param(
#> #>
function Get-ConfigPath { function Get-ConfigPath {
param( param(
[string] $Name,
[string] $PackageName [string] $PackageName
) )
return Join-Path "Visual Studio" "$PackageName.vsconfig"; return Join-Path "$Name" "$PackageName.vsconfig";
} }
Start-SoftwareInstaller @parameters ` Start-SoftwareInstaller @parameters `
-Backup { -Backup {
param([string] $Name)
foreach ($version in $versions) { foreach ($version in $versions) {
if (Test-ChocoPackage $version[0]) { if (Test-ChocoPackage $version[0]) {
Write-Host "Backing up ``$($version[0])"; Write-Host "Backing up ``$($version[0])";
@ -58,17 +61,19 @@ param(
"--quiet" "--quiet"
); );
Add-BackupArtifacts -Source $configFile -Path (Get-ConfigPath $version[0]); Add-BackupArtifacts -Source $configFile -Path (Get-ConfigPath $Name $version[0]);
Remove-Item $configFile; Remove-Item $configFile;
} }
} }
} ` } `
-Installer { -Installer {
param([string] $Name)
foreach ($version in $versions) { foreach ($version in $versions) {
$packageName = $version[0]; $packageName = $version[0];
$file = New-TemporaryFile; $file = New-TemporaryFile;
Remove-Item $file; Remove-Item $file;
Expand-BackupArtifacts -Path (Get-ConfigPath $packageName) -Target $file; Expand-BackupArtifacts -Path (Get-ConfigPath $Name $packageName) -Target $file;
if (Test-Path $file) { if (Test-Path $file) {
Write-Host "Restoring ``$packageName``"; Write-Host "Restoring ``$packageName``";

View file

@ -10,6 +10,7 @@ param(
Start-SoftwareInstaller @PSBoundParameters ` Start-SoftwareInstaller @PSBoundParameters `
-Configurator { -Configurator {
param([string] $Name)
[string] $backup = $null; [string] $backup = $null;
$nativeProfile = powershell -c '$PROFILE'; $nativeProfile = powershell -c '$PROFILE';
@ -23,7 +24,7 @@ Start-SoftwareInstaller @PSBoundParameters `
Add-PowerShellProfileStatement ` Add-PowerShellProfileStatement `
-DefaultUser ` -DefaultUser `
-Category "chocolatey" ` -Category "$Name" `
-Script (Get-Content $nativeProfile | Out-String) ` -Script (Get-Content $nativeProfile | Out-String) `
-Append; -Append;

View file

@ -20,7 +20,9 @@ param(
Remove-DesktopIcon "*osu*"; Remove-DesktopIcon "*osu*";
} ` } `
-Backup { -Backup {
Add-BackupArtifacts -Source (& $getInstallPath) -Path "osu!" ` param([string] $Name)
Add-BackupArtifacts -Source (& $getInstallPath) -Path "$Name" `
-Include @( -Include @(
"Screenshots", "Screenshots",
"Skins", "Skins",
@ -30,16 +32,22 @@ param(
); );
} ` } `
-Configurator { -Configurator {
Expand-BackupArtifacts -Path "osu!" -Target (& $getInstallPath); param([string] $Name)
Expand-BackupArtifacts -Path "$Name" -Target (& $getInstallPath);
} ` } `
-UserBackup { -UserBackup {
param([hashtable] $Arguments) param(
$name = $Arguments.Name; [string] $Name,
Add-BackupArtifacts -Source "$(& $getInstallPath)/osu!.$name.cfg" -User $name -Path "osu!/osu!.cfg"; [hashtable] $Arguments
)
$user = $Arguments.Name;
Add-BackupArtifacts -Source "$(& $getInstallPath)/osu!.$user.cfg" -User $user -Path "$Name/osu!.cfg";
} ` } `
-UserConfigurator { -UserConfigurator {
param([hashtable] $Arguments) param([hashtable] $Arguments)
$name = $Arguments.Name; $name = $Arguments.Name;
Expand-BackupArtifacts -User $name -Path "osu!/osu!.cfg" -Target "$(& $getInstallPath)/osu!.$name.cfg"; Expand-BackupArtifacts -User $name -Path "$Name/osu!.cfg" -Target "$(& $getInstallPath)/osu!.$name.cfg";
}; };
} $PSBoundParameters; } $PSBoundParameters;

View file

@ -12,8 +12,12 @@ param(
Start-SoftwareInstaller @Parameters ` Start-SoftwareInstaller @Parameters `
-UserBackup { -UserBackup {
param([hashtable] $Arguments) param(
Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "osu!lazer" ` [string] $Name,
[hashtable] $Arguments
)
Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "$Name" `
-Include @( -Include @(
"files", "files",
"rulesets", "rulesets",
@ -24,6 +28,11 @@ param(
); );
} ` } `
-UserConfigurator { -UserConfigurator {
param(
[string] $Name,
[hashtable] $Arguments
)
$file = "osu!lazer.exe"; $file = "osu!lazer.exe";
$processName = "osu!"; $processName = "osu!";
$dir = New-TemporaryDirectory; $dir = New-TemporaryDirectory;
@ -42,6 +51,6 @@ param(
Remove-Item -Recurse $dir; Remove-Item -Recurse $dir;
Remove-DesktopIcon "*osu*"; Remove-DesktopIcon "*osu*";
Expand-BackupArtifacts -User $Arguments.Name -Path "osu!lazer" -Target $path; Expand-BackupArtifacts -User $Arguments.Name -Path "$Name" -Target $path;
}; };
} $PSBoundParameters; } $PSBoundParameters;

View file

@ -14,7 +14,9 @@ param(
Start-SoftwareInstaller @Parameters ` Start-SoftwareInstaller @Parameters `
-Backup { -Backup {
Add-BackupArtifacts -Path "reWASD" -Source $path ` param([string] $Name)
Add-BackupArtifacts -Path "$Name" -Source $path `
-Exclude @( -Exclude @(
"Logs", "Logs",
"Presets", "Presets",
@ -40,6 +42,7 @@ param(
Remove-DesktopIcon "*reWASD*"; Remove-DesktopIcon "*reWASD*";
} ` } `
-Configurator { -Configurator {
Expand-BackupArtifacts -Path "reWASD" -Target $path; param([string] $Name)
Expand-BackupArtifacts -Path "$Name" -Target $path;
}; };
} $PSBoundParameters; } $PSBoundParameters;