icinga2/tools/win32/download-openssl.ps1

77 lines
2.3 KiB
PowerShell
Raw Normal View History

2018-08-02 14:42:14 +02:00
$ErrorActionPreference = "Stop"
2018-02-02 17:22:15 +01:00
$OpenSSL_version = '1.1.0g-1'
2018-08-02 14:42:14 +02:00
if (Test-Path env:VSCMD_ARG_TGT_ARCH) {
$OpenSSL_arch = $env:VSCMD_ARG_TGT_ARCH
} else {
throw "Missing env variable VSCMD_ARG_TGT_ARCH"
}
if (Test-Path env:VSCMD_VER) {
$VSmajor = $env:VSCMD_VER -replace "\..*$", ""
$OpenSSL_vcbuild = "vc${VSmajor}0"
} else {
throw "Missing env variable VSCMD_VER"
}
2018-02-02 17:22:15 +01:00
$OpenSSL_fileversion = $OpenSSL_version.Replace('.', '_').Split('-')[0]
2018-02-02 17:19:14 +01:00
$OpenSSL_file = [string]::Format(
'openssl-{0}-binary-icinga-{1}-{2}.zip',
$OpenSSL_fileversion,
$OpenSSL_arch,
$OpenSSL_vcbuild
)
2018-02-02 17:22:15 +01:00
$OpenSSL_url = [string]::Format(
'https://github.com/Icinga/openssl-windows/releases/download/v{0}/{1}',
$OpenSSL_version,
$OpenSSL_file
)
2018-02-02 17:19:14 +01:00
2018-08-02 14:42:14 +02:00
if (-not (Test-Path env:ICINGA2_BUILDPATH)) {
$env:ICINGA2_BUILDPATH = '.\build'
}
$vendor_path = $env:ICINGA2_BUILDPATH + '\vendor'
$OpenSSL_zip_location = $env:ICINGA2_BUILDPATH + '\vendor\' + $OpenSSL_file
$OpenSSL_vendor_path = "$vendor_path\OpenSSL-$OpenSSL_arch-$OpenSSL_vcbuild"
2018-02-02 17:19:14 +01:00
2018-08-02 14:42:14 +02:00
# Tune Powershell TLS protocols
$AllProtocols = [System.Net.SecurityProtocolType]'Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
if (-not (Test-Path $env:ICINGA2_BUILDPATH)) {
mkdir $env:ICINGA2_BUILDPATH | out-null
}
2018-02-02 17:19:14 +01:00
if (-not (Test-Path $vendor_path)) {
2018-08-02 14:42:14 +02:00
mkdir $vendor_path | out-null
2018-02-02 17:19:14 +01:00
}
if (Test-Path $OpenSSL_zip_location) {
2018-02-02 17:22:15 +01:00
Write-Output "OpenSSL archive available at $OpenSSL_zip_location"
2018-02-02 17:19:14 +01:00
} else {
2018-02-02 17:22:15 +01:00
Write-Output "Downloading OpenSSL binary dist from $OpenSSL_url"
2018-02-02 17:19:14 +01:00
$progressPreference = 'silentlyContinue'
2018-02-02 17:22:15 +01:00
Invoke-WebRequest -Uri $OpenSSL_url -OutFile $OpenSSL_zip_location
2018-02-02 17:19:14 +01:00
$progressPreference = 'Continue'
2018-08-02 14:42:14 +02:00
2018-02-02 17:19:14 +01:00
if (Test-Path $OpenSSL_vendor_path) {
Remove-Item -Recurse $OpenSSL_vendor_path
}
}
if (-not (Test-Path $OpenSSL_vendor_path)) {
2018-08-02 14:42:14 +02:00
mkdir $OpenSSL_vendor_path | out-null
2018-02-02 17:19:14 +01:00
2018-02-02 17:22:15 +01:00
Write-Output "Extracting ZIP to $OpenSSL_vendor_path"
Add-Type -AssemblyName System.IO.Compression.FileSystem
2018-08-02 14:42:14 +02:00
$pwd = Get-Location
[System.IO.Compression.ZipFile]::ExtractToDirectory(
(Join-Path -path $pwd -childpath $OpenSSL_zip_location),
(Join-Path -path $pwd -childpath $OpenSSL_vendor_path)
)
if ($lastexitcode -ne 0){ exit $lastexitcode }
2018-02-02 17:22:15 +01:00
} else {
Write-Output "OpenSSL is already available at $OpenSSL_vendor_path"
}