Logeto.psm1
. "Global.ps1" <# Return Json file from the URL for set product and scope. If version parameter is set it returns Json file only if higher version was found, otherwise returns null. #> function Get-LogetoUpdateInfo { Param( [parameter(Mandatory=$true)] [String] $Product, [parameter(Mandatory=$false)] [String] $Scope, [parameter(Mandatory=$false)] [String] $Version ) Write-LogetoProgress "Searching for new version." "Get-LogetoUpdateInfo" $fileName = $Product if (![String]::IsNullOrEmpty($Scope)) { $fileName += "-" $fileName += $Scope } $fileName += ".json" $file = [System.IO.Path]::GetTempFileName(); try { try { Write-LogetoDebug "URL of the UpdateInfo file is $UpdateInfoURL$fileName" (New-Object System.Net.WebClient).DownloadFile($UpdateInfoURL + $fileName, $file) $json = (Get-Content -Raw -Path $file) | ConvertFrom-Json $downloadedVersion = $json | Select -ExpandProperty Version if (![String]::IsNullOrEmpty($Version)) { if ([System.Version]$downloadedVersion -gt [System.Version]$Version) { Write-LogetoDebug "UpdateInfo has been found!" return $json } else { Write-LogetoDebug "No newer UpdateInfo has been found!" return $null } } if (!$json) { Write-LogetoDebug "Last UpdateInfo has been found!" return $json } } finally { if (Test-Path $file) { Remove-Item $file -Force } } } catch [Exception] { Write-Error $_.Exception.Message return $null; } Write-LogetoDebug "No UpdateInfo has been found!" return $null; } <# Install any Logeto product #> function Get-LogetoProduct { Param( [parameter(Mandatory=$true)] $UpdateInfo, [parameter(Mandatory=$true)] [ValidateSet('logeto-terminal', 'logeto-terminal-service')] $ProductName ) $folder = $LogetoFolder + $DownloadFolderPath + $ProductName try { [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} $packageUrl = $UpdateInfo | Select -ExpandProperty PackageUrl $zipFile = [System.IO.Path]::GetTempFileName(); try { (New-Object System.Net.WebClient).DownloadFile($packageUrl, $zipFile) Invoke-LogetoExtract $zipFile $folder } finally { if (Test-Path $zipFile) { Remove-Item $zipFile -Force } } Write-LogetoDebug "Downloading finished." } catch { throw CreateCustomException "Downloading the newest version failed with reason: $_.Exception.Message" "ScriptSystemartInstallerDownloadFailed" $resultExceptionThrown 1 } } <# Install any Logeto product #> function Install-LogetoProduct { Param( [parameter(Mandatory=$true)] [ValidateSet('logeto-terminal', 'logeto-terminal-service')] $ProductName ) if ($ProductName -eq 'logeto-terminal') { Install-LogetoTerminal (Get-LogetoTerminalUpdateInfo) $ProductName } elseif ($ProductName -eq 'logeto-terminal-service') { Install-LogetoTerminalService (Get-LogetoTerminalServiceUpdateInfo) $ProductName } } <# Uninstall any Logeto product #> function Uninstall-LogetoProduct { Param( [parameter(Mandatory=$true)] [ValidateSet('logeto-terminal', 'logeto-terminal-service')] $ProductName ) if ($ProductName -eq 'logeto-terminal') { } elseif ($ProductName -eq 'logeto-terminal-service') { } } <# Install any Logeto product #> function Set-LogetoProductEnvironment { Param( [parameter(Mandatory=$true)] [ValidateSet('logeto-terminal', 'logeto-terminal-service')] $ProductName ) if ($ProductName -eq 'logeto-terminal') { Set-TerminalPrepareEnvironment $ProductName } elseif ($ProductName -eq 'logeto-terminal-service') { Set-TerminalServicePrepareEnvironment } } <# Extract zip file to dstination directory #> Function Invoke-LogetoExtract($sourceFile, $destionationDir) { if (Test-Path $destionationDir) { Remove-Item $destionationDir -Recurse -Force } if (!(Test-Path $destionationDir)) { New-Item -ItemType Directory -Force -Path $destionationDir | Out-Null } Add-Type -Assembly System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::ExtractToDirectory($sourceFile, $destionationDir) } |