PortValhalla/scripts/Windows/Scripts/SoftwarePackage.ps1

29 lines
1 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();
$tempFile = Join-Path $tempDir "download.tmp";
Write-Information "Downloading setup file from $location";
$response = Invoke-WebRequest $location -OutFile $tempFile;
$fileName = [System.IO.Path]::GetFileName($response.Headers["Location"]);
Write-Information "Renaming setup file to $fileName";
$filePath = Join-Path $tempDir $fileName;
Move-Item $tempFile $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;
}
}