Public/Utils.ps1

<#
.SYNOPSIS
Attempts to clear the /tmp directory when run from Linux
#>

function Clear-Tmp() {
    if ($IsLinux)
    {
        try
        {
            Remove-Item -Recurse -Path "/tmp/*"
        }
        catch
        {
            # Ignore
        }
    }
}

function New-TemporaryDirectory {
    if ($IsLinux) { return "/tmp/$([guid]::NewGuid().ToString())" }
    $dir = New-TemporaryFile
    rm $dir | Out-Null
    mkdir $dir | Out-Null
    return $dir
}

function Expand-Archive
{
    param (
        [string]$zipfile,
        [string]$outpath
    )

    [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}

function Expand-RemoteArchive {
    param (
        [string]$tempDir,
        [string]$url,
        [string]$executableName = $null
    )

    $ProgressPreference = 'SilentlyContinue'

    $tmpFile = "$tempDir/$([guid]::NewGuid().ToString())"
    Invoke-WebRequest -Uri $url -OutFile $tmpFile
    Expand-Archive $tmpFile $tmpDir

    if ($executableName -ne $null) {
        if ($IsLinux)
        {
            chmod 500 "$tmpDir/$executableName"
        }
    }
}

function Enable-TLS12 {
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
}