PortValhalla/scripts/Windows/Scripts/SoftwareManagement.ps1

59 lines
1.5 KiB
PowerShell

. "$PSScriptRoot/Context.ps1";
function Install-SoftwarePackage([Context] $context, [string] $location, [string[]] $argumentList = @("/S"), [switch]$local) {
[string]$filePath = "";
[string]$tempDir = $null;
if (-not ($local.IsPresent)) {
$tempDir = $context.GetTempDirectory();
Write-Information "Determining the file name of $location";
$fileName = ([uri]$location).Segments[-1];
Write-Information "$fileName";
$filePath = Join-Path $tempDir $fileName;
Write-Information "Downloading setup file from $location";
Invoke-WebRequest $location -OutFile $filePath;
} else {
$filePath = $location;
}
$fileName = [System.IO.Path]::GetFileName($filePath);
Write-Information "Starting installation of $fileName";
Start-Process -Wait -FilePath $filePath -ArgumentList $argumentList;
if ($tempDir) {
Remove-Item -Recurse $tempDir;
}
}
<#
.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));
}
<#
.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);
}