Normalize software names

This commit is contained in:
Manuel Thalmann 2024-10-13 15:35:24 +02:00
commit 95d079bcaf
70 changed files with 59 additions and 59 deletions
scripts/Common/Software/powershell

View file

@ -0,0 +1,39 @@
. "$PSScriptRoot/../../Scripts/Software.ps1";
. "$PSScriptRoot/../../Software/powershell/Profile.ps1";
. "$PSScriptRoot/../../Types/InstallerAction.ps1";
Start-SoftwareInstaller @args `
-Configurator {
[string] $globalDir = $null;
$indicator = "# Profile Files";
if (-not $IsWindows) {
$globalDir = '"/etc/powershell/conf.d"';
}
else {
$globalDir = '"$env:ProgramData/PowerShell/conf.d"';
}
if (-not ((Test-Path -PathType Leaf $PROFILE) -and ((Get-Content $PROFILE) -contains $indicator))) {
Add-PowerShellProfileStatement `
-DefaultUser `
-Script (@(
$indicator,
"`$globalDir = $globalDir",
({
$profileRoot = Split-Path -Parent $PROFILE;
$profilePaths = @(
"$profileRoot/conf.d/*.ps1",
"$globalDir/*.ps1"
)
foreach ($profilePath in $profilePaths) {
if (Test-Path $profilePath) {
Get-Item $profilePath | ForEach-Object { . $_; };
}
}
}).ToString()) -join "`n") `
-Append;
}
};

View file

@ -0,0 +1,71 @@
. "$PSScriptRoot/../../Types/InstallerAction.ps1";
$null = New-Module {
. "$PSScriptRoot/../../Software/powershell/Profile.ps1";
<#
.SYNOPSIS
Generates the components for creating a module installer.
.PARAMETER Name
The name of the module to install.
.PARAMETER NativeOnly
A value indicating whether the module is installed in Windows PowerShell only.
.PARAMETER NoProfile
A value indicating whether the module is not added to the profile script of users.
#>
function Get-ModuleInstallerComponents {
param(
[string] $Name,
[switch] $NativeOnly,
[switch] $NoProfile
)
@{
context = @{
name = $Name;
nativeOnly = $NativeOnly;
};
installer = {
param(
[hashtable] $Context
)
$env:PENDING_MODULE_NAME = $Context.Name;
$installAction = {
$module = $env:PENDING_MODULE_NAME;
if (-not (Get-Module -ListAvailable $module -ErrorAction SilentlyContinue)) {
Install-Module -Scope AllUsers -Force $module @args;
}
};
if (-not $Context.NativeOnly) {
& $installAction -AcceptLicense;
}
if (Test-Command powershell) {
powershell -c ($installAction.ToString());
}
Remove-Item Env:\PENDING_MODULE_NAME;
};
configurator = ($NoProfile.IsPresent) ? { } : {
param(
[hashtable] $Context
)
$name = $Context.Name;
Add-PowerShellProfileStatement `
-System `
-Category $name `
-Script "Import-Module `"$name`";";
};
}
}
};

View file

@ -0,0 +1,126 @@
$null = New-Module {
. "$PSScriptRoot/../../Scripts/Scripting.ps1";
. "$PSScriptRoot/../../Scripts/Software.ps1";
<#
.SYNOPSIS
Adds an initialization script to the profile.
.PARAMETER System
A value indicating whether the script should be installed globally.
.PARAMETER DefaultUser
A value indicating whether the script should be installed to users by default.
.PARAMETER HomeDir
The path to the home directory of the user to install the script to.
.PARAMETER Category
The category name of the script to install.
.PARAMETER Script
The script to install.
.PARAMETER Replace
A value indicating whether the script should be replaced if it already exists.
.PARAMETER Append
A value indicating whether the content should be appended to the script if it already exists.
#>
function Add-PowerShellProfileStatement {
param(
[Parameter(ParameterSetName = "Global", Mandatory)]
[switch] $System,
[Parameter(ParameterSetName = "DefaultUser", Mandatory)]
[switch] $DefaultUser,
[Parameter(ParameterSetName = "Home")]
[string] $HomeDir = "~",
[Parameter(ParameterSetName = "Global", Mandatory)]
[Parameter(ParameterSetName = "DefaultUser")]
[Parameter(ParameterSetName = "Home")]
[string] $Category = $null,
[Parameter(Position = 0, Mandatory)]
[string] $Script,
[switch] $Replace,
[switch] $Append
)
[System.Collections.ArrayList] $profiles = @();
if ($System) {
[string] $configRoot = $null;
if ($IsWindows) {
# ToDo Change to "PowerShell"
$configRoot = "$env:ProgramData";
}
else {
$configRoot = "/etc";
}
$profiles = @("$configRoot/powershell/.");
}
else {
if ($DefaultUser) {
if (-not $IsWindows) {
$HomeDir = "/etc/skel";
}
else {
$HomeDir = "C:/Users/Default";
}
}
foreach ($shell in @("pwsh", "powershell")) {
if (Test-Command $shell) {
$null = $profiles.Add((& $shell -NoProfile -c '$PROFILE'));
}
}
Push-Location ~;
$profiles = @(
$profiles |
ForEach-Object { [System.IO.Path]::GetRelativePath((Get-Location), $_) } |
ForEach-Object { "$HomeDir/$_" }
);
Pop-Location;
}
if ($Category) {
$profiles = @($profiles | ForEach-Object { Join-Path (Split-Path -Parent $_) "conf.d" "$Category.ps1" });
}
$profiles | ForEach-Object {
$arguments = @{ };
if ($Replace.IsPresent) {
$null = $arguments.Add("Replace", $Replace);
}
if ($Append.IsPresent) {
$null = $arguments.Add("Append", $Append);
}
Write-PSScript @arguments `
-FileName $_ `
-Script $Script;
};
}
<#
.SYNOPSIS
Creates an eval-script using the `[scriptblock]::Create` method.
.PARAMETER Initializer
The code to evaluate.
#>
function Get-ScriptInitializer {
param (
[Parameter(Position = 0, Mandatory = $true)]
$Initializer
)
return ". ([scriptblock]::Create(($Initializer) -join `"``n`"))";
}
};

View file

@ -0,0 +1,11 @@
#!/bin/env fish
begin
set -l dir (status dirname)
source "$dir/../../Scripts/software.fish"
function configureSW -V dir
sudo -HE pwsh "$dir/Main.ps1" Configure
end
runInstaller $argv
end