|
| 1 | +# Copyright 2020, Google Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +<# |
| 16 | +.SYNOPSIS |
| 17 | + Makefile like build commands for the Operations Collector on Windows. |
| 18 | + |
| 19 | + Usage: .\make.ps1 <Command> [-<Param> <Value> ...] |
| 20 | + Example: .\make.ps1 New-MSI -Config "./config.yaml" |
| 21 | +.PARAMETER Target |
| 22 | + Build target to run (Install-Tools, New-MSI, Confirm-MSI) |
| 23 | +#> |
| 24 | +Param( |
| 25 | + [Parameter(Mandatory=$true, ValueFromRemainingArguments=$true)][string]$Target |
| 26 | +) |
| 27 | + |
| 28 | +$ErrorActionPreference = "Stop" |
| 29 | + |
| 30 | +function Install-Tools { |
| 31 | + choco install wixtoolset -y |
| 32 | + setx /m PATH "%PATH%;C:\Program Files (x86)\WiX Toolset v3.11\bin" |
| 33 | + refreshenv |
| 34 | +} |
| 35 | + |
| 36 | +function New-MSI( |
| 37 | + [string]$Version="0.0.0", |
| 38 | + [string]$Config="./config.yml" |
| 39 | +) { |
| 40 | + candle -arch x64 -dVersion="$Version" -dConfig="$Config" packaging/msi/google-cloudops-opentelemetry-collector.wxs |
| 41 | + light google-cloudops-opentelemetry-collector.wixobj |
| 42 | + Move-Item -Force google-cloudops-opentelemetry-collector.msi bin/google-cloudops-opentelemetry-collector.msi |
| 43 | +} |
| 44 | + |
| 45 | +function Confirm-MSI { |
| 46 | + # ensure system32 is in Path so we can use executables like msiexec & sc |
| 47 | + $env:Path += ";C:\Windows\System32" |
| 48 | + |
| 49 | + # install msi, validate service is installed & running |
| 50 | + Start-Process -Wait msiexec "/i `"$pwd\bin\google-cloudops-opentelemetry-collector.msi`" /qn" |
| 51 | + sc.exe query state=all | findstr "google-cloudops-opentelemetry-collector" | Out-Null |
| 52 | + if ($LASTEXITCODE -ne 0) { Throw "google-cloudops-opentelemetry-collector service failed to install" } |
| 53 | + |
| 54 | + # stop service |
| 55 | + Stop-Service google-cloudops-opentelemetry-collector |
| 56 | + |
| 57 | + # start service |
| 58 | + Start-Service google-cloudops-opentelemetry-collector |
| 59 | + |
| 60 | + # uninstall msi, validate service is uninstalled |
| 61 | + Start-Process -Wait msiexec "/x `"$pwd\bin\opentelemetry-contrib-collector.msi`" /qn" |
| 62 | + sc.exe query state=all | findstr "google-cloudops-opentelemetry-collector" | Out-Null |
| 63 | + if ($LASTEXITCODE -ne 1) { Throw "google-cloudops-opentelemetry-collector service failed to uninstall" } |
| 64 | +} |
| 65 | + |
| 66 | +$sb = [scriptblock]::create("$Target") |
| 67 | +Invoke-Command -ScriptBlock $sb |
0 commit comments