2024-08-07 20:55:25 +00:00
|
|
|
. "$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.
|
2024-08-22 21:55:00 +00:00
|
|
|
|
|
|
|
.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.
|
2024-08-07 20:55:25 +00:00
|
|
|
#>
|
|
|
|
function Get-ModuleInstallerComponents {
|
|
|
|
param(
|
2024-08-08 00:28:23 +00:00
|
|
|
[string] $Name,
|
2024-08-22 21:55:00 +00:00
|
|
|
[switch] $NativeOnly,
|
|
|
|
[switch] $NoProfile
|
2024-08-07 20:55:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@{
|
2024-10-06 19:25:34 +00:00
|
|
|
context = @{
|
|
|
|
name = $Name;
|
2024-08-08 00:28:23 +00:00
|
|
|
nativeOnly = $NativeOnly;
|
2024-08-07 20:55:25 +00:00
|
|
|
};
|
2024-10-06 19:25:34 +00:00
|
|
|
installer = {
|
2024-08-07 20:55:25 +00:00
|
|
|
param(
|
2024-09-29 15:12:44 +00:00
|
|
|
[hashtable] $Context
|
2024-08-07 20:55:25 +00:00
|
|
|
)
|
|
|
|
|
2024-09-29 15:12:44 +00:00
|
|
|
$env:PENDING_MODULE_NAME = $Context.Name;
|
2024-08-26 23:57:46 +00:00
|
|
|
|
|
|
|
$installAction = {
|
|
|
|
$module = $env:PENDING_MODULE_NAME;
|
|
|
|
|
|
|
|
if (-not (Get-Module -ListAvailable $module -ErrorAction SilentlyContinue)) {
|
|
|
|
Install-Module -Scope AllUsers -Force $module @args;
|
|
|
|
}
|
|
|
|
};
|
2024-08-08 00:28:23 +00:00
|
|
|
|
2024-09-29 15:12:44 +00:00
|
|
|
if (-not $Context.NativeOnly) {
|
2024-08-08 00:28:23 +00:00
|
|
|
& $installAction -AcceptLicense;
|
|
|
|
}
|
2024-08-07 20:55:25 +00:00
|
|
|
|
|
|
|
if (Test-Command powershell) {
|
|
|
|
powershell -c ($installAction.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
Remove-Item Env:\PENDING_MODULE_NAME;
|
|
|
|
};
|
|
|
|
|
2024-08-27 00:09:04 +00:00
|
|
|
configurator = ($NoProfile.IsPresent) ? { } : {
|
2024-08-07 20:55:25 +00:00
|
|
|
param(
|
2024-09-29 15:12:44 +00:00
|
|
|
[hashtable] $Context
|
2024-08-07 20:55:25 +00:00
|
|
|
)
|
|
|
|
|
2024-09-29 15:12:44 +00:00
|
|
|
$name = $Context.Name;
|
2024-08-07 20:55:25 +00:00
|
|
|
|
2024-08-27 00:09:04 +00:00
|
|
|
Add-PowerShellProfileStatement `
|
2024-09-19 20:25:48 +00:00
|
|
|
-System `
|
2024-08-27 00:09:04 +00:00
|
|
|
-Category $name `
|
|
|
|
-Script "Import-Module `"$name`";";
|
2024-08-07 20:55:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|