2024-08-01 16:24:26 +00:00
|
|
|
. "$PSScriptRoot/Config.ps1";
|
2024-08-05 21:09:58 +00:00
|
|
|
. "$PSScriptRoot/Operations.ps1";
|
2024-08-07 01:23:21 +00:00
|
|
|
. "$PSScriptRoot/System.ps1";
|
2024-08-01 20:52:51 +00:00
|
|
|
. "$PSScriptRoot/../Types/InstallerAction.ps1";
|
2024-08-01 16:24:26 +00:00
|
|
|
|
2024-08-01 21:34:35 +00:00
|
|
|
$null = New-Module {
|
2024-08-07 13:25:12 +00:00
|
|
|
. "$PSScriptRoot/BrowserAutomation.ps1";
|
2024-08-07 11:22:12 +00:00
|
|
|
. "$PSScriptRoot/SoftwareManagement.ps1";
|
|
|
|
. "$PSScriptRoot/../Types/InstallerAction.ps1";
|
2024-08-01 21:34:35 +00:00
|
|
|
$userArgument = "name";
|
2024-08-01 16:24:26 +00:00
|
|
|
|
2024-08-07 11:22:12 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Installs the specified packages using chocolatey.
|
|
|
|
|
|
|
|
.PARAMETER Names
|
|
|
|
The names of the packages to install.
|
|
|
|
#>
|
|
|
|
function Install-ChocoPackage {
|
|
|
|
param(
|
|
|
|
[switch] $Force,
|
2024-08-07 16:01:17 +00:00
|
|
|
[string[]] $ArgumentList,
|
|
|
|
[Parameter(Position=0)]
|
|
|
|
[string] $Name,
|
2024-08-07 11:22:12 +00:00
|
|
|
[Parameter(ValueFromRemainingArguments = $true)]
|
2024-08-07 16:01:17 +00:00
|
|
|
[string[]] $AdditionalNames = @()
|
2024-08-07 11:22:12 +00:00
|
|
|
)
|
|
|
|
|
2024-08-07 16:01:17 +00:00
|
|
|
[System.Collections.ArrayList] $Names = @();
|
|
|
|
$null = $Names.Add($Name);
|
|
|
|
$Names.AddRange($AdditionalNames);
|
2024-08-07 11:22:12 +00:00
|
|
|
|
|
|
|
if (-not ($Force.IsPresent)) {
|
|
|
|
for ($i = $Names.Count - 1; $i -ge 0; $i--) {
|
2024-08-07 21:18:23 +00:00
|
|
|
$name = $Names[$i];
|
|
|
|
|
|
|
|
if (Test-ChocoPackage $name) {
|
|
|
|
Write-Host "Package ``$name`` is already installed"
|
2024-08-07 11:22:12 +00:00
|
|
|
$Names.RemoveAt($i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($Names.Count -ge 1) {
|
2024-08-10 13:13:46 +00:00
|
|
|
choco install -y @ArgumentList @Names;
|
2024-08-07 11:22:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Installs the specified packages using `winget`.
|
|
|
|
|
|
|
|
.PARAMETER Names
|
|
|
|
The names of the packages to install.
|
|
|
|
#>
|
|
|
|
function Install-WingetPackage {
|
|
|
|
param(
|
|
|
|
[switch] $Force,
|
2024-08-08 02:29:00 +00:00
|
|
|
[string[]] $ArgumentList,
|
2024-08-08 02:28:21 +00:00
|
|
|
[Parameter(Position=0)]
|
|
|
|
[string] $Name,
|
2024-08-07 11:22:12 +00:00
|
|
|
[Parameter(ValueFromRemainingArguments = $true)]
|
2024-08-08 02:28:21 +00:00
|
|
|
[string[]] $AdditionalNames = @()
|
2024-08-07 11:22:12 +00:00
|
|
|
)
|
|
|
|
|
2024-08-08 02:28:21 +00:00
|
|
|
[System.Collections.ArrayList] $Names = @();
|
|
|
|
$null = $Names.Add($Name);
|
|
|
|
$Names.AddRange($AdditionalNames);
|
|
|
|
|
2024-08-07 11:22:12 +00:00
|
|
|
foreach ($name in $Names) {
|
2024-08-07 21:20:28 +00:00
|
|
|
if ($Force.IsPresent -or -not (Test-WingetPackage $name)) {
|
2024-08-07 20:56:42 +00:00
|
|
|
winget install `
|
|
|
|
--accept-source-agreements --accept-package-agreements `
|
|
|
|
--source winget `
|
2024-08-09 12:45:05 +00:00
|
|
|
$ArgumentList `
|
|
|
|
--exact --id $name ;
|
2024-08-07 21:18:23 +00:00
|
|
|
} else {
|
|
|
|
Write-Host "Package ``$name`` is already installed"
|
2024-08-07 11:22:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-08 02:20:11 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Installs a setup package from the specified source.
|
|
|
|
|
|
|
|
.PARAMETER Source
|
|
|
|
The location of the setup package.
|
|
|
|
|
|
|
|
.PARAMETER ArgumentList
|
|
|
|
The arguments to pass to the setup package.
|
|
|
|
|
|
|
|
.PARAMETER Local
|
|
|
|
A value indicating whether the setup package is stored locally.
|
|
|
|
#>
|
|
|
|
function Install-SetupPackage {
|
|
|
|
param(
|
|
|
|
[string] $Source,
|
|
|
|
[string[]] $ArgumentList = @("/S"),
|
|
|
|
[switch] $Local
|
|
|
|
)
|
|
|
|
|
|
|
|
[string] $dir = $null;
|
|
|
|
[string] $filePath = $null;
|
|
|
|
|
|
|
|
if (-not ($Local.IsPresent)) {
|
|
|
|
$dir = New-TemporaryDirectory;
|
|
|
|
Write-Host "Determining the file name of ``$Source``…";
|
|
|
|
$fileName = ([uri]$Source).Segments[-1];
|
|
|
|
Write-Host "Found name ``$fileName``";
|
|
|
|
$filePath = Join-Path $dir $fileName;
|
|
|
|
|
|
|
|
Write-Host "Downloading setup file from ``$Source``";
|
|
|
|
Invoke-WebRequest $Source -OutFile $filePath;
|
|
|
|
} else {
|
|
|
|
$filePath = $Source;
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host "Starting installation of ``$(Split-Path -Leaf $filePath)``";
|
|
|
|
Start-Process -Wait -WorkingDirectory (Split-Path -Parent $filePath) -FilePath $filePath -ArgumentList $ArgumentList;
|
|
|
|
|
|
|
|
if ($dir) {
|
|
|
|
Remove-Item -Recurse $dir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-07 12:40:24 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Installs a package downloaded from ASUS.
|
|
|
|
|
|
|
|
.PARAMETER URL
|
|
|
|
The URL to download the package from.
|
|
|
|
#>
|
|
|
|
function Install-AsusPackage {
|
|
|
|
param(
|
|
|
|
[string] $URL
|
|
|
|
)
|
|
|
|
|
|
|
|
$file = "AsusPackage.zip";
|
|
|
|
$dir = New-TemporaryDirectory;
|
|
|
|
$unpackDir = New-TemporaryDirectory;
|
|
|
|
|
|
|
|
$null = Push-Location $dir;
|
|
|
|
Invoke-WebRequest $URL -OutFile $file;
|
|
|
|
Expand-Archive $file $unpackDir;
|
|
|
|
$null = Pop-Location;
|
|
|
|
Remove-Item -Recurse $dir;
|
|
|
|
|
|
|
|
$null = Start-Process -Wait -WorkingDirectory $unpackDir -FilePath (Join-Path $unpackDir "AsusSetup.exe") -ArgumentList "/S";
|
|
|
|
Remove-Item -Recurse $unpackDir;
|
|
|
|
}
|
|
|
|
|
2024-08-07 13:25:12 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Downloads and installs a package from the AMD website.
|
|
|
|
|
|
|
|
.PARAMETER URL
|
|
|
|
The URL to download the package from.
|
|
|
|
#>
|
|
|
|
function Install-AmdPackage {
|
|
|
|
param(
|
|
|
|
[string] $URL
|
|
|
|
)
|
|
|
|
|
|
|
|
$dir = New-TemporaryDirectory;
|
|
|
|
$cookieBannerSelector = "#onetrust-consent-sdk";
|
|
|
|
$osSelector = "div[id$='oscategory']>div[id$='-0']";
|
|
|
|
$downloadSelector = "$osSelector div[id$='panel'] .button a";
|
|
|
|
|
|
|
|
$file = Start-CustomBrowserDownload @PSBoundParameters -OutDir $dir -Action {
|
|
|
|
param(
|
|
|
|
[OpenQA.Selenium.Firefox.FirefoxDriver] $Browser
|
|
|
|
)
|
|
|
|
|
|
|
|
$osContainer = $Browser.FindElement([OpenQA.Selenium.By]::CssSelector($osSelector));
|
|
|
|
|
|
|
|
if (-not ([bool] $osContainer.GetAttribute("cmp-expanded"))) {
|
|
|
|
$osContainer.Click();
|
|
|
|
}
|
|
|
|
|
|
|
|
$download = {
|
|
|
|
$browser.FindElement([OpenQA.Selenium.By]::CssSelector($downloadSelector)).Click();
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
& $download;
|
|
|
|
} catch {
|
2024-08-08 01:32:03 +00:00
|
|
|
$null = $Browser.ExecuteScript("document.querySelector('$cookieBannerSelector').remove()");
|
2024-08-07 13:25:12 +00:00
|
|
|
& $download;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-08-08 01:32:03 +00:00
|
|
|
Start-Process -Wait -WorkingDirectory (Split-Path -Parent "$file") -FilePath "$file" -ArgumentList "/S";
|
2024-08-07 13:25:12 +00:00
|
|
|
Remove-Item -Recurse $dir;
|
|
|
|
}
|
|
|
|
|
2024-08-01 16:24:26 +00:00
|
|
|
function Start-SoftwareInstaller {
|
|
|
|
param(
|
2024-08-04 22:07:41 +00:00
|
|
|
[string] $Name,
|
2024-08-08 20:24:41 +00:00
|
|
|
[scriptblock] $Installer = $null,
|
|
|
|
[scriptblock] $Configurator = $null,
|
|
|
|
[scriptblock] $UserConfigurator = $null,
|
2024-08-08 00:56:28 +00:00
|
|
|
[Nullable[InstallerAction]] $Action,
|
2024-08-05 20:51:29 +00:00
|
|
|
[hashtable] $Arguments
|
2024-08-01 16:24:26 +00:00
|
|
|
)
|
|
|
|
|
2024-08-08 00:56:28 +00:00
|
|
|
[InstallerAction] $Action = & {
|
|
|
|
if ($Action.HasValue) {
|
|
|
|
$Action;
|
|
|
|
} else {
|
|
|
|
[InstallerAction]::Install;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-08-06 10:21:48 +00:00
|
|
|
if (-not $Name) {
|
|
|
|
$Name = Split-Path -Leaf (Split-Path -Parent ((Get-PSCallStack)[1].ScriptName));
|
|
|
|
}
|
2024-08-01 19:06:03 +00:00
|
|
|
|
2024-08-06 10:21:48 +00:00
|
|
|
Start-Operation {
|
2024-08-05 21:09:58 +00:00
|
|
|
if ($null -ne $Name) {
|
|
|
|
$Name = "``$Name``";
|
|
|
|
} else {
|
|
|
|
$Name = "unknown software";
|
|
|
|
}
|
2024-08-01 19:06:03 +00:00
|
|
|
|
2024-08-05 21:09:58 +00:00
|
|
|
$installHandler = {
|
|
|
|
param(
|
|
|
|
[InstallerAction] $Action,
|
|
|
|
[hashtable] $Arguments
|
|
|
|
)
|
2024-08-04 22:07:41 +00:00
|
|
|
|
2024-08-05 21:09:58 +00:00
|
|
|
$Arguments ??= @{ };
|
2024-08-05 21:08:36 +00:00
|
|
|
|
2024-08-05 21:09:58 +00:00
|
|
|
$argumentList = @{
|
|
|
|
installer = $installHandler;
|
|
|
|
arguments = $Arguments;
|
|
|
|
};
|
2024-08-05 20:29:20 +00:00
|
|
|
|
2024-08-05 21:09:58 +00:00
|
|
|
if ($action -eq ([InstallerAction]::Install)) {
|
2024-08-08 20:24:41 +00:00
|
|
|
if ($Installer) {
|
|
|
|
Write-Host "Installing $Name…";
|
|
|
|
& $Installer @argumentList;
|
|
|
|
}
|
2024-08-07 21:30:29 +00:00
|
|
|
# ToDo: Automatically configure after installation
|
2024-08-05 21:09:58 +00:00
|
|
|
} elseif ($Action -eq ([InstallerAction]::Configure)) {
|
2024-08-08 20:24:41 +00:00
|
|
|
if ($Configurator) {
|
|
|
|
Write-Host "Configuring $Name…";
|
|
|
|
& $Configurator @argumentList;
|
|
|
|
}
|
2024-08-04 22:07:41 +00:00
|
|
|
|
2024-08-07 21:30:29 +00:00
|
|
|
if (-not (Test-SetupUser)) {
|
2024-08-05 21:09:58 +00:00
|
|
|
$argumentList.Add("action", [InstallerAction]::ConfigureUser);
|
|
|
|
& $installHandler @argumentList;
|
|
|
|
}
|
|
|
|
} elseif ($Action -eq ([InstallerAction]::ConfigureUser)) {
|
|
|
|
if ((-not $Arguments.ContainsKey($userArgument)) -or ($null -eq $Arguments[$userArgument])) {
|
|
|
|
$argumentList.Add($userArgument, ($env:UserName));
|
|
|
|
}
|
|
|
|
|
2024-08-08 20:24:41 +00:00
|
|
|
if ($UserConfigurator) {
|
|
|
|
Write-Host "Configuring $Name for user ``$($Arguments[$userArgument])``…";
|
|
|
|
& $UserConfigurator @argumentList;
|
|
|
|
}
|
2024-08-04 22:07:41 +00:00
|
|
|
}
|
2024-08-05 21:09:58 +00:00
|
|
|
};
|
2024-08-04 22:07:41 +00:00
|
|
|
|
2024-08-05 21:09:58 +00:00
|
|
|
& $installHandler -Action $Action -Arguments $Arguments;
|
2024-08-05 20:29:20 +00:00
|
|
|
};
|
2024-08-01 16:24:26 +00:00
|
|
|
}
|
|
|
|
}
|