From e29e36acf7d7f3a6199e68c4f1f69dc281fd6ba8 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 8 Aug 2024 04:20:11 +0200 Subject: [PATCH] Add missing function --- scripts/Common/Scripts/Software.ps1 | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/scripts/Common/Scripts/Software.ps1 b/scripts/Common/Scripts/Software.ps1 index 5cbeb41d..1363daee 100644 --- a/scripts/Common/Scripts/Software.ps1 +++ b/scripts/Common/Scripts/Software.ps1 @@ -73,6 +73,50 @@ $null = New-Module { } } + <# + .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; + } + } + <# .SYNOPSIS Installs a package downloaded from ASUS.