Refactor software script environment
This commit is contained in:
parent
b37815498a
commit
8564396d86
|
@ -1,82 +1,57 @@
|
||||||
. "$PSScriptRoot/Config.ps1";
|
. "$PSScriptRoot/Config.ps1";
|
||||||
. "$PSScriptRoot/../Types/InstallerAction.ps1";
|
. "$PSScriptRoot/../Types/InstallerAction.ps1";
|
||||||
|
|
||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Gets the name of the software.
|
|
||||||
#>
|
|
||||||
function Get-SoftwareName {
|
|
||||||
$path = ${Function:Install-Software}.File;
|
|
||||||
|
|
||||||
if ($path -ne "$PSCommandPath") {
|
|
||||||
Split-Path -Leaf (Split-Path -Parent $path);
|
|
||||||
} else {
|
|
||||||
$null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Installs the software.
|
|
||||||
#>
|
|
||||||
function Install-Software { }
|
|
||||||
|
|
||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Configures the system for the software.
|
|
||||||
#>
|
|
||||||
function Set-SoftwareConfiguration { }
|
|
||||||
|
|
||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Configures a user for the software.
|
|
||||||
|
|
||||||
.PARAMETER Name
|
|
||||||
The name of the user to configure.
|
|
||||||
#>
|
|
||||||
function Set-SoftwareUserConfiguration {
|
|
||||||
param(
|
|
||||||
[Parameter(Mandatory = $true)]
|
|
||||||
[string] $Name
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
$null = New-Module {
|
$null = New-Module {
|
||||||
. "$PSScriptRoot/../Types/InstallerAction.ps1";
|
. "$PSScriptRoot/../Types/InstallerAction.ps1";
|
||||||
$userArgument = "name";
|
$userArgument = "name";
|
||||||
|
|
||||||
function Start-SoftwareInstaller {
|
function Start-SoftwareInstaller {
|
||||||
param(
|
param(
|
||||||
[InstallerAction] $Action,
|
[string] $Name,
|
||||||
|
[scriptblock] $Installer = { },
|
||||||
|
[scriptblock] $Configurator = { },
|
||||||
|
[scriptblock] $UserConfigurator = { },
|
||||||
|
[InstallerAction] $Action = [InstallerAction]::Install,
|
||||||
[hashtable] $Arguments
|
[hashtable] $Arguments
|
||||||
)
|
)
|
||||||
|
|
||||||
$null = $softwareName;
|
if (-not $Name) {
|
||||||
|
$Name = Split-Path -Leaf (Split-Path -Parent ((Get-PSCallStack)[1].ScriptName));
|
||||||
|
}
|
||||||
|
|
||||||
if ($null -ne (Get-SoftwareName)) {
|
if ($null -ne $Name) {
|
||||||
$softwareName = "``$(Get-SoftwareName)``";
|
$Name = "``$Name``";
|
||||||
} else {
|
} else {
|
||||||
$softwareName = "unknown software";
|
$Name = "unknown software";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($null -eq $Action) -or ($action -eq ([InstallerAction]::Install))) {
|
function Invoke-SoftwareInstaller {
|
||||||
Write-Host "Installing $softwareName…";
|
param(
|
||||||
Install-Software @Arguments;
|
[InstallerAction] $Action,
|
||||||
} elseif ($action -eq ([InstallerAction]::Configure)) {
|
[hashtable] $Arguments
|
||||||
Write-Host "Configuring $softwareName…";
|
)
|
||||||
Set-SoftwareConfiguration @Arguments;
|
|
||||||
|
|
||||||
foreach ($user in Get-Users) {
|
if ($action -eq ([InstallerAction]::Install)) {
|
||||||
$Arguments.Add($userArgument, $user);
|
Write-Host "Installing $Name…";
|
||||||
Start-SoftwareInstaller -Action ([InstallerAction]::ConfigureUser) @Arguments;
|
& $Installer @Arguments;
|
||||||
}
|
} elseif ($Action -eq ([InstallerAction]::Configure)) {
|
||||||
} elseif ($action -eq ([InstallerAction]::ConfigureUser)) {
|
Write-Host "Configuring $Name…";
|
||||||
if ((-not $Arguments.Contains($userArgument)) -or ($null -eq $Arguments[$userArgument])) {
|
& $Configurator @Arguments;
|
||||||
$Arguments.Add($userArgument, ($env:UserName));
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Configuring $softwareName for user ``$($Arguments[$userArgument])``…";
|
foreach ($user in Get-Users) {
|
||||||
Set-SoftwareUserConfiguration @Arguments;
|
$Arguments.Add($userArgument, $user);
|
||||||
|
Invoke-SoftwareInstaller -Action ([InstallerAction]::ConfigureUser) -Arguments $Arguments;
|
||||||
|
}
|
||||||
|
} elseif ($Action -eq ([InstallerAction]::ConfigureUser)) {
|
||||||
|
if ((-not $Arguments.ContainsKey($userArgument)) -or ($null -eq $Arguments[$userArgument])) {
|
||||||
|
$Arguments.Add($userArgument, ($env:UserName));
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Configuring $Name for user ``$($Arguments[$userArgument])``…";
|
||||||
|
& $UserConfigurator @Arguments;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Invoke-SoftwareInstaller -Action $Action -Arguments $Arguments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,28 +3,21 @@ param(
|
||||||
[hashtable] $Arguments
|
[hashtable] $Arguments
|
||||||
)
|
)
|
||||||
|
|
||||||
. "$PSScriptRoot/../../Scripts/Software.ps1";
|
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
|
||||||
. "$PSScriptRoot/../../Types/InstallerAction.ps1";
|
|
||||||
|
|
||||||
function Install-Winget {
|
& {
|
||||||
param(
|
param($Parameters)
|
||||||
[InstallerAction] $Action = [InstallerAction]::Install,
|
|
||||||
[hashtable] $Arguments
|
|
||||||
)
|
|
||||||
|
|
||||||
Start-SoftwareInstaller -Action $Action -Arguments $Arguments;
|
Start-SoftwareInstaller @Parameters `
|
||||||
}
|
-Installer {
|
||||||
|
$xamlDownloadLink = "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx";
|
||||||
function Install-Software {
|
$downloadLink = "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle";
|
||||||
$xamlDownloadLink = "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx";
|
$file = New-TemporaryFile;
|
||||||
$downloadLink = "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle";
|
$file = Rename-Item $file "$file.msixbundle" -PassThru;
|
||||||
$file = New-TemporaryFile;
|
Invoke-WebRequest "$xamlDownloadLink" -OutFile "$file";
|
||||||
$file = Rename-Item $file "$file.msixbundle" -PassThru;
|
Add-AppxPackage "$file";
|
||||||
Invoke-WebRequest "$xamlDownloadLink" -OutFile "$file";
|
Invoke-WebRequest "$downloadLink" -OutFile "$file";
|
||||||
Add-AppxPackage "$file";
|
Add-AppxPackage "$file";
|
||||||
Invoke-WebRequest "$downloadLink" -OutFile "$file";
|
Remove-Item $file;
|
||||||
Add-AppxPackage "$file";
|
};
|
||||||
Remove-Item $file;
|
} $PSBoundParameters;
|
||||||
}
|
|
||||||
|
|
||||||
Install-Winget @PSBoundParameters;
|
|
||||||
|
|
Loading…
Reference in a new issue