From 5ceb3c205bc7d669f60f1c944770201fb7c593ba Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 7 Aug 2024 22:55:25 +0200 Subject: [PATCH] Add scripts for installing PS modules --- scripts/Common/Software/PowerShell/Module.ps1 | 53 +++++++++++++++++++ .../Common/Software/Terminal-Icons/Manage.ps1 | 15 ++++++ scripts/Common/Software/posh-git/Manage.ps1 | 15 ++++++ scripts/Windows/OS/Install.ps1 | 3 ++ 4 files changed, 86 insertions(+) create mode 100644 scripts/Common/Software/PowerShell/Module.ps1 create mode 100644 scripts/Common/Software/Terminal-Icons/Manage.ps1 create mode 100644 scripts/Common/Software/posh-git/Manage.ps1 diff --git a/scripts/Common/Software/PowerShell/Module.ps1 b/scripts/Common/Software/PowerShell/Module.ps1 new file mode 100644 index 00000000..8839277c --- /dev/null +++ b/scripts/Common/Software/PowerShell/Module.ps1 @@ -0,0 +1,53 @@ +. "$PSScriptRoot/../../Software/PowerShell/Profile.ps1"; +. "$PSScriptRoot/../../Types/InstallerAction.ps1"; + +$null = New-Module { + <# + .SYNOPSIS + Generates the components for creating a module installer. + + .PARAMETER Name + The name of the module to install. + #> + function Get-ModuleInstallerComponents { + param( + [string] $Name + ) + + @{ + arguments = @{ + name = $Name; + }; + installer = { + param( + [scriptblock] $Installer, + [hashtable] $Arguments + ) + + $env:PENDING_MODULE_NAME = $Arguments.Name; + $installAction = { Install-Module -Scope AllUsers -Force $env:PENDING_MODULE_NAME @args }; + & $installAction -AcceptLicense; + + if (Test-Command powershell) { + powershell -c ($installAction.ToString()); + } + + Remove-Item Env:\PENDING_MODULE_NAME; + & $Installer -Action ([InstallerAction]::Configure) @PSBoundParameters; + }; + + configurator = { + param( + [hashtable] $Arguments + ) + + $name = $Arguments.Name; + + Add-PowerShellProfileStatement ` + -DefaultUser ` + -Category $name ` + -Script "Import-Module `"$name`";"; + }; + } + } +}; diff --git a/scripts/Common/Software/Terminal-Icons/Manage.ps1 b/scripts/Common/Software/Terminal-Icons/Manage.ps1 new file mode 100644 index 00000000..7409ad8f --- /dev/null +++ b/scripts/Common/Software/Terminal-Icons/Manage.ps1 @@ -0,0 +1,15 @@ +param ( + $Action, + [hashtable] $Arguments +) + +. "$PSScriptRoot/../PowerShell/Module.ps1"; +. "$PSScriptRoot/../../Scripts/Software.ps1"; + +$parameters = Get-ModuleInstallerComponents "Terminal-Icons"; + +foreach ($key in $PSBoundParameters.Keys) { + $parameters.Add($key, $PSBoundParameters.TryGetValue($key)); +} + +Start-SoftwareInstaller @parameters; diff --git a/scripts/Common/Software/posh-git/Manage.ps1 b/scripts/Common/Software/posh-git/Manage.ps1 new file mode 100644 index 00000000..b7883074 --- /dev/null +++ b/scripts/Common/Software/posh-git/Manage.ps1 @@ -0,0 +1,15 @@ +param ( + $Action, + [hashtable] $Arguments +) + +. "$PSScriptRoot/../PowerShell/Module.ps1"; +. "$PSScriptRoot/../../Scripts/Software.ps1"; + +$parameters = Get-ModuleInstallerComponents "posh-git"; + +foreach ($key in $PSBoundParameters.Keys) { + $parameters.Add($key, $PSBoundParameters.TryGetValue($key)); +} + +Start-SoftwareInstaller @parameters; diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index 12422d5a..80d97754 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -177,6 +177,7 @@ $null = New-Module { $null = New-Module { # Windows Config $softwarePath = "$PSScriptRoot/../Software"; + $commonSoftware = "$PSScriptRoot/../../Common/Software"; . "$softwarePath/Windows/Manage.ps1" @arguments; if (Test-Collection "essential") { @@ -184,6 +185,8 @@ $null = New-Module { . "$softwarePath/OpenSSH/Manage.ps1" @arguments; . "$softwarePath/PowerShell/Manage.ps1" @arguments; . "$softwarePath/chocolatey/Manage.ps1" @arguments; + . "$commonSoftware/posh-git/Manage.ps1" @arguments; + . "$commonSoftware/Terminal-Icons/Manage.ps1" @arguments; } if (Test-Collection "common") {