PortValhalla/scripts/Windows/Scripts/SoftwarePackage.ps1

27 lines
802 B
PowerShell

#!/bin/bash
. "$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";
$response = Invoke-WebRequest $location -OutFile $tempFile;
$fileName = [System.IO.Path]::GetFileName($response.Headers["Location"]);
$filePath = Join-Path $tempDir $fileName;
Move-Item $tempFile $filePath;
} else {
$filePath = $location;
}
Start-Process -Wait -FilePath $filePath -ArgumentList $argumentList;
if ($tempDir) {
Remove-Item -Recurse $tempDir;
}
}