2024-08-07 19:54:58 +00:00
|
|
|
function Install-SoftwarePackage($context, [string] $location, [string[]] $argumentList = @("/S"), [switch]$local) {
|
|
|
|
. "$PSScriptRoot/Context.ps1";
|
|
|
|
[Context]$context = $context;
|
2023-07-15 10:18:13 +00:00
|
|
|
[string]$filePath = "";
|
|
|
|
[string]$tempDir = $null;
|
|
|
|
|
|
|
|
if (-not ($local.IsPresent)) {
|
2023-07-16 00:01:31 +00:00
|
|
|
$tempDir = $context.GetTempDirectory();
|
2023-07-15 23:46:57 +00:00
|
|
|
Write-Information "Determining the file name of $location";
|
2023-07-15 23:56:51 +00:00
|
|
|
$fileName = ([uri]$location).Segments[-1];
|
2023-07-15 23:46:57 +00:00
|
|
|
Write-Information "$fileName";
|
|
|
|
$filePath = Join-Path $tempDir $fileName;
|
2023-07-15 10:18:13 +00:00
|
|
|
|
2023-07-15 10:25:42 +00:00
|
|
|
Write-Information "Downloading setup file from $location";
|
2023-07-15 23:46:57 +00:00
|
|
|
Invoke-WebRequest $location -OutFile $filePath;
|
2023-07-15 10:18:13 +00:00
|
|
|
} else {
|
|
|
|
$filePath = $location;
|
|
|
|
}
|
|
|
|
|
2023-07-15 10:25:42 +00:00
|
|
|
$fileName = [System.IO.Path]::GetFileName($filePath);
|
|
|
|
Write-Information "Starting installation of $fileName";
|
2023-07-15 10:18:13 +00:00
|
|
|
Start-Process -Wait -FilePath $filePath -ArgumentList $argumentList;
|
|
|
|
|
|
|
|
if ($tempDir) {
|
|
|
|
Remove-Item -Recurse $tempDir;
|
|
|
|
}
|
|
|
|
}
|
2024-08-01 16:35:45 +00:00
|
|
|
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Checks whether the specified package has been installed using Chocolatey.
|
|
|
|
|
|
|
|
.PARAMETER Name
|
|
|
|
The name of the package to check.
|
|
|
|
#>
|
|
|
|
function Test-ChocoPackage {
|
|
|
|
[OutputType([bool])]
|
|
|
|
param(
|
|
|
|
[string] $Name
|
|
|
|
);
|
|
|
|
|
|
|
|
-not [string]::IsNullOrEmpty((choco list --limit-output --exact $name));
|
|
|
|
}
|
|
|
|
|
2024-08-07 11:18:29 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Checks whether a `winget` package with the specified id is installed.
|
|
|
|
|
|
|
|
.PARAMETER ID
|
|
|
|
The id of the package to check.
|
|
|
|
#>
|
|
|
|
function Test-WingetPackage {
|
|
|
|
[OutputType([bool])]
|
|
|
|
param(
|
2024-09-02 23:16:42 +00:00
|
|
|
[string] $Name,
|
|
|
|
[string[]] $ArgumentList
|
2024-08-07 11:18:29 +00:00
|
|
|
)
|
|
|
|
|
2024-09-02 23:16:42 +00:00
|
|
|
& { $null = winget list --accept-source-agreements -e --id $Name @ArgumentList; $?; };
|
2024-08-07 11:18:29 +00:00
|
|
|
}
|
|
|
|
|
2024-08-01 16:35:45 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Checks whether a command with the specified name exists.
|
|
|
|
|
|
|
|
.PARAMETER Name
|
|
|
|
The name of the command to check.
|
|
|
|
#>
|
|
|
|
function Test-Command {
|
|
|
|
param (
|
|
|
|
[string] $Name
|
|
|
|
)
|
|
|
|
|
|
|
|
[bool] (Get-Command $Name -ErrorAction SilentlyContinue);
|
|
|
|
}
|
2024-08-07 01:23:59 +00:00
|
|
|
|
2024-08-07 01:34:12 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Checks whether `winget` is working properly.
|
|
|
|
#>
|
|
|
|
function Test-Winget {
|
2024-08-16 13:04:37 +00:00
|
|
|
(Test-Command winget) -and (
|
|
|
|
& {
|
|
|
|
$output = winget source update winget;
|
|
|
|
|
|
|
|
$? -and -not ([System.Linq.Enumerable]::Any(
|
|
|
|
[string[]]($output),
|
|
|
|
[System.Func[string,bool]]{ param($line) $line -eq "Cancelled"; }));
|
|
|
|
});
|
2024-08-07 01:34:12 +00:00
|
|
|
}
|
|
|
|
|
2024-08-07 01:23:59 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Checks whether a package with the specified name is installed.
|
|
|
|
|
|
|
|
.PARAMETER Name
|
|
|
|
The name of the package to check.
|
|
|
|
#>
|
|
|
|
function Test-PSPackage {
|
|
|
|
param(
|
|
|
|
[string] $Name
|
|
|
|
)
|
|
|
|
|
|
|
|
[bool] (Get-Package $Name -ErrorAction SilentlyContinue);
|
|
|
|
}
|
2024-08-26 23:25:32 +00:00
|
|
|
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Checks whether a module with the specified name is installed.
|
|
|
|
|
|
|
|
.PARAMETER Name
|
|
|
|
The name of the module to check.
|
|
|
|
#>
|
|
|
|
function Test-PSModule {
|
|
|
|
param(
|
|
|
|
[string] $Name
|
|
|
|
)
|
|
|
|
|
|
|
|
[bool](Get-Module -ListAvailable $Name -ErrorAction SilentlyContinue);
|
|
|
|
}
|