2016-09-16 06:36:58 +00:00
|
|
|
[CmdletBinding()]
|
|
|
|
Param (
|
2018-03-14 10:12:02 +00:00
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
[String] $PathToExecutable,
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
[String] $Version,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
|
|
[ValidateSet("amd64", "386")]
|
|
|
|
[String] $Arch = "amd64"
|
2016-09-16 06:36:58 +00:00
|
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
|
|
# Get absolute path to executable before switching directories
|
|
|
|
$PathToExecutable = Resolve-Path $PathToExecutable
|
|
|
|
# Set working dir to this directory, reset previous on exit
|
|
|
|
Push-Location $PSScriptRoot
|
|
|
|
Trap {
|
2018-03-14 10:12:02 +00:00
|
|
|
# Reset working dir on error
|
|
|
|
Pop-Location
|
2016-09-16 06:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($PSVersionTable.PSVersion.Major -lt 5) {
|
2018-03-14 10:12:02 +00:00
|
|
|
Write-Error "Powershell version 5 required"
|
|
|
|
exit 1
|
2016-09-16 06:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$wc = New-Object System.Net.WebClient
|
|
|
|
function Get-FileIfNotExists {
|
2018-03-14 10:12:02 +00:00
|
|
|
Param (
|
|
|
|
$Url,
|
|
|
|
$Destination
|
|
|
|
)
|
|
|
|
if (-not (Test-Path $Destination)) {
|
|
|
|
Write-Verbose "Downloading $Url"
|
|
|
|
$wc.DownloadFile($Url, $Destination)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Write-Verbose "${Destination} already exists. Skipping."
|
|
|
|
}
|
2016-09-16 06:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$sourceDir = mkdir -Force Source
|
2018-03-14 10:12:02 +00:00
|
|
|
mkdir -Force Work, Output | Out-Null
|
2016-09-16 06:36:58 +00:00
|
|
|
|
|
|
|
Write-Verbose "Downloading WiX..."
|
2018-03-14 10:11:36 +00:00
|
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
2017-06-27 12:10:38 +00:00
|
|
|
Get-FileIfNotExists "https://github.com/wixtoolset/wix3/releases/download/wix311rtm/wix311-binaries.zip" "$sourceDir\wix-binaries.zip"
|
2016-09-16 06:36:58 +00:00
|
|
|
mkdir -Force WiX | Out-Null
|
|
|
|
Expand-Archive -Path "${sourceDir}\wix-binaries.zip" -DestinationPath WiX -Force
|
|
|
|
|
2020-05-24 18:42:23 +00:00
|
|
|
Copy-Item -Force $PathToExecutable Work/windows_exporter.exe
|
2016-09-16 06:36:58 +00:00
|
|
|
|
2020-05-24 18:42:23 +00:00
|
|
|
Write-Verbose "Creating windows_exporter-${Version}-${Arch}.msi"
|
2018-03-14 10:12:02 +00:00
|
|
|
$wixArch = @{"amd64" = "x64"; "386" = "x86"}[$Arch]
|
2018-04-05 06:37:23 +00:00
|
|
|
$wixOpts = "-ext WixFirewallExtension -ext WixUtilExtension"
|
2020-05-24 18:42:23 +00:00
|
|
|
Invoke-Expression "WiX\candle.exe -nologo -arch $wixArch $wixOpts -out Work\windows_exporter.wixobj -dVersion=`"$Version`" windows_exporter.wxs"
|
|
|
|
Invoke-Expression "WiX\light.exe -nologo -spdb $wixOpts -out `"Output\windows_exporter-${Version}-${Arch}.msi`" Work\windows_exporter.wixobj"
|
2016-09-16 06:36:58 +00:00
|
|
|
|
|
|
|
Write-Verbose "Done!"
|
2017-03-17 18:23:03 +00:00
|
|
|
Pop-Location
|