github.com/observiq/bindplane-agent@v1.51.0/windows/templates/product.wxs (about)

     1  <?xml version="1.0"?>
     2  
     3  <?if $(sys.BUILDARCH)="x86"?>
     4      <?define Program_Files="ProgramFilesFolder"?>
     5  <?elseif $(sys.BUILDARCH)="x64"?>
     6      <?define Program_Files="ProgramFiles64Folder"?>
     7  <?else?>
     8      <?error Unsupported value of sys.BUILDARCH=$(sys.BUILDARCH)?>
     9  <?endif?>
    10  
    11  <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
    12       xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
    13  
    14     <Product Id="*" UpgradeCode="{{.UpgradeCode}}"
    15              Name="{{.Product}}"
    16              Version="{{.Version.MSI}}"
    17              Manufacturer="{{.Company}}"
    18              Language="1033">
    19  
    20        <Package InstallerVersion="200" Compressed="yes" Description="{{.Product}} {{.Version.Display}}"
    21                 Comments="This installs {{.Product}} {{.Version.Display}}" InstallScope="perMachine"/>
    22  
    23        <MediaTemplate EmbedCab="yes" {{if gt (.Compression | len) 0}}CompressionLevel="{{.Compression}}"{{end}}/>
    24  
    25        <MajorUpgrade
    26          Schedule="afterInstallExecute"
    27          DowngradeErrorMessage="A newer version of this software is already installed."/>
    28  
    29        {{if gt (.Banner | len) 0 }} <WixVariable Id="WixUIBannerBmp" Value="{{.Banner}}"/> {{end}}
    30        {{if gt (.Dialog | len) 0 }} <WixVariable Id="WixUIDialogBmp" Value="{{.Dialog}}"/> {{end}}
    31  
    32        {{if gt (.Icon | len) 0 }}
    33        <Icon Id="Installer.Ico" SourceFile="{{.Icon}}"/>
    34        <Property Id="ARPPRODUCTICON" Value="Installer.Ico"/>
    35        {{end}}
    36        <!-- Need to customize the Add/remove program list entry, set the automatically created one to SystemComponent to hide it then create another one. -->
    37        <Property Id="ARPSYSTEMCOMPONENT" Value="1"/>
    38  
    39        {{range $i, $p := .Properties}}
    40        <Property Id="{{$p.ID}}" {{if $p.Value}}Value="{{$p.Value}}"{{end}} {{if not $p.Registry}}Secure="yes"{{end}}>
    41           {{if $p.Registry}}
    42           <RegistrySearch Id="{{$p.ID}}Search" Root="{{$p.Registry.Root}}" Key="{{$p.Registry.Key}}"
    43              {{if gt ($p.Registry.Name | len) 0}} Name="{{$p.Registry.Name}}" {{end}} Type="raw"/>
    44           {{end}}
    45        </Property>
    46        {{end}}
    47        {{range $i, $c := .Conditions}}
    48        <Condition Message="{{$c.Message}}"><![CDATA[{{$c.Condition}}]]></Condition>
    49        {{end}}
    50        
    51        <!-- Load previous install directory (if it exists); This will populate the install dir with the current install dir
    52             for upgrades. -->
    53        <Property Id="INSTALLDIR">
    54            <RegistrySearch Id='LOADINSTALLDIR' Type='raw'
    55              Root='HKLM' Key='Software\Microsoft\Windows\CurrentVersion\Uninstall\[ProductName]' Name='InstallLocation' />
    56            <!-- Load up the install dir form the previous ProductName if it exists there, instead.-->
    57            <RegistrySearch Id='LOADINSTALLDIROLD' Type='raw'
    58              Root='HKLM' Key='Software\Microsoft\Windows\CurrentVersion\Uninstall\observIQ OpenTelemetry Collector' Name='InstallLocation' />
    59        </Property>
    60        
    61        <!-- Set default install dir to be "C:\Program Files\observIQ OpenTelemetry Collector" instead of "C:\Program Files\[ProductName]"-->
    62        <SetProperty Id="INSTALLDIR" Value="[$(var.Program_Files)]\observIQ OpenTelemetry Collector" Before="CostInitialize">
    63          <![CDATA[NOT INSTALLDIR]]>
    64        </SetProperty>
    65  
    66        <!-- Set command prompt -->
    67        <SetProperty Id="CMDEXE" Value="[%SystemRoot]\system32\cmd.exe" Before="CostInitialize">
    68          <![CDATA[NOT CMDEXE]]>
    69        </SetProperty>
    70  
    71        <Directory Id="TARGETDIR" Name="SourceDir">
    72  
    73          <Directory Id="$(var.Program_Files)">
    74              <Directory Id="INSTALLDIR" Name="observIQ OpenTelemetry Collector">
    75                  {{define "FILES"}}
    76                  {{range $f := .}}
    77                  <Component 
    78                      Id="ApplicationFiles{{$f.ID}}" 
    79                      Guid="*"
    80                      Permanent="{{if $f.Permanent}}yes{{else}}no{{end}}"
    81                      NeverOverwrite="{{if $f.NeverOverwrite}}yes{{else}}no{{end}}">
    82                      
    83                      <File Id="ApplicationFile{{$f.ID}}" Source="{{$f.Path}}"/>
    84                      {{if $f.Service}}
    85                      <ServiceInstall Id="ServiceInstall{{$f.ID}}" Type="ownProcess" Name="{{$f.Service.Name}}" Start="{{$f.Service.Start}}" Account="LocalSystem" ErrorControl="normal"
    86                      {{if gt ($f.Service.DisplayName | len) 0}} DisplayName="{{$f.Service.DisplayName}}" {{end}}
    87                      {{if gt ($f.Service.Description | len) 0}} Description="{{$f.Service.Description}}" {{end}}
    88                      {{if gt ($f.Service.Arguments | len) 0}} Arguments="{{$f.Service.Arguments}}" {{end}}>
    89                          {{range $d := $f.Service.Dependencies}}
    90                          <ServiceDependency Id="{{$d}}"/>
    91                          {{end}}
    92                          {{if $f.Service.Delayed}}
    93                          <ServiceConfig DelayedAutoStart="yes" OnInstall="yes" OnReinstall ="yes" FailureActionsWhen="failedToStopOrReturnedError"/>
    94                          {{end}}
    95                          <util:ServiceConfig FirstFailureActionType="restart"
    96                                              SecondFailureActionType="restart"
    97                                              ThirdFailureActionType="restart"
    98                                              ResetPeriodInDays="30"
    99                                              RestartServiceDelayInSeconds="5"/>
   100                      </ServiceInstall>
   101                      <ServiceControl Id="ServiceControl{{$f.ID}}" Name="{{$f.Service.Name}}" Start="install" Stop="both" Remove="uninstall"/>
   102                      {{end}}
   103                   </Component>
   104                  {{end}}
   105                  {{end}}
   106                  {{template "FILES" .Directory.Files}}
   107                  {{define "DIRECTORIES"}}
   108                  {{range $d := .}}
   109                  <Directory Id="ApplicationDirectory{{$d.ID}}" Name="{{$d.Name}}">
   110                  {{template "FILES" $d.Files}}
   111                  {{template "DIRECTORIES" $d.Directories}}
   112                  </Directory>
   113                  {{end}}
   114                  {{end}}
   115                  {{template "DIRECTORIES" .Directory.Directories}}
   116              </Directory>
   117          </Directory>
   118  
   119          {{range $i, $e := .Environments}}
   120          <Component Id="Environments{{$i}}" Guid="*">
   121              <Environment Id="Environment{{$i}}" Name="{{$e.Name}}" Value="{{$e.Value}}" Permanent="{{$e.Permanent}}" Part="{{$e.Part}}" Action="{{$e.Action}}" System="{{$e.System}}"/>
   122              <RegistryValue Root="HKLM" Key="Software\[Manufacturer]\[ProductName]" Name="envvar{{$i}}" Type="integer" Value="1" KeyPath="yes"/>
   123              {{if gt ($e.Condition | len) 0}}<Condition><![CDATA[{{$e.Condition}}]]></Condition>{{end}}
   124          </Component>
   125          {{end}}
   126  
   127          {{range $i, $r := .Registries}}
   128          <Component Id="RegistryEntries{{$i}}" Guid="*">
   129              <RegistryKey Root="{{$r.Root}}" Key="{{$r.Key}}">
   130                  {{range $j, $v := $r.Values}}
   131                  <RegistryValue Type="{{$v.Type}}" {{if gt ($v.Name | len) 0}} Name="{{$v.Name}}" {{end}} Value="{{$v.Value}}" {{if eq $i 0}}{{if eq $j 0}} KeyPath="yes" {{end}}{{end}}/>
   132                  {{end}}
   133              </RegistryKey>
   134              {{if gt ($r.Condition | len) 0}}<Condition><![CDATA[{{$r.Condition}}]]></Condition>{{end}}
   135          </Component>
   136          {{end}}
   137          <Component Id="RegistryEntriesARP" Guid="*">
   138              <!-- 
   139                  Remove old registry key; This one sticks around for some reason after upgrading to the new product name, which is a problem,
   140                  since this registry key is the one that makes it show up in the "Uninstall a program" dialog.
   141              -->
   142              <RemoveRegistryKey Action="removeOnInstall" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\observIQ OpenTelemetry Collector"/>
   143              <RegistryKey Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\[ProductName]">
   144                  <RegistryValue Type="string" Name="AuthorizedCDFPrefix" Value=""/>
   145                  <RegistryValue Type="string" Name="Comments" Value="{{.Info.Comments}}"/>
   146                  <RegistryValue Type="string" Name="Contact" Value="{{.Info.Contact}}"/>
   147                  {{if gt (.Icon | len) 0 }}
   148                  <RegistryValue Type="string" Name="DisplayIcon" Value="%SystemRoot%\Installer\[ProductCode]\Installer.Ico"/>
   149                  {{end}}
   150                  <RegistryValue Type="string" Name="DisplayName" Value="[ProductName]" KeyPath="yes"/>
   151                  <RegistryValue Type="string" Name="DisplayVersion" Value="{{.Version.Display}}"/>
   152                  <RegistryValue Type="integer" Name="EstimatedSize" Value="{{.Info.Size}}"/>
   153                  <RegistryValue Type="string" Name="HelpLink" Value="{{.Info.HelpLink}}"/>
   154                  <RegistryValue Type="string" Name="HelpTelephone" Value="{{.Info.SupportTelephone}}"/>
   155                  <RegistryValue Type="string" Name="InstallDate" Value="[Date]"/>
   156                  <RegistryValue Type="string" Name="InstallLocation" Value="[INSTALLDIR]"/>
   157                  <RegistryValue Type="string" Name="InstallSource" Value="[SourceDir]"/>
   158                  <RegistryValue Type="integer" Name="Language" Value="[ProductLanguage]"/>
   159                  <RegistryValue Type="expandable" Name="ModifyPath" Value="MsiExec.exe /I[ProductCode]"/>
   160                  <RegistryValue Type="string" Name="Publisher" Value="{{.Company}}"/>
   161                  <RegistryValue Type="string" Name="Readme" Value="{{.Info.Readme}}"/>
   162                  <RegistryValue Type="expandable" Name="UninstallString" Value="MsiExec.exe /I[ProductCode]"/>
   163                  <RegistryValue Type="string" Name="URLInfoAbout" Value="{{.Info.SupportLink}}"/>
   164                  <RegistryValue Type="string" Name="URLUpdateInfo" Value="{{.Info.UpdateInfoLink}}"/>
   165                  <RegistryValue Type="integer" Name="Version" Value="{{.Version.Hex}}"/>
   166                  <RegistryValue Type="integer" Name="NoModify" Value="1"/>
   167              </RegistryKey>
   168          </Component>
   169  
   170          <Directory Id="ProgramMenuFolder"/>
   171          <Directory Id="DesktopFolder"/>
   172  
   173          {{range $i, $s := .Shortcuts}}
   174          <Component Id="ApplicationShortcuts{{$i}}" Guid="*">
   175              <Shortcut Id="ApplicationShortcut{{$i}}" Name="{{$s.Name}}" Description="{{$s.Description}}" Target="{{$s.Target}}" WorkingDirectory="{{$s.WDir}}"
   176                  Directory={{if eq $s.Location "program"}}"ProgramMenuFolder"{{else}}"DesktopFolder"{{end}}
   177                  {{if gt ($s.Arguments | len) 0}}Arguments="{{$s.Arguments}}"{{end}}>
   178                  {{if gt ($s.Icon | len) 0}}<Icon Id="Icon{{$i}}" SourceFile="{{$s.Icon}}"/>{{end}}
   179                  {{range $j, $p := $s.Properties}}<ShortcutProperty Key="{{$p.Key}}" Value="{{$p.Value}}"/>{{end}}
   180              </Shortcut>
   181              {{if gt ($s.Condition | len) 0}}<Condition><![CDATA[{{$s.Condition}}]]></Condition>{{end}}
   182              <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Name="shortcut{{$i}}" Type="integer" Value="1" KeyPath="yes"/>
   183          </Component>
   184          {{end}}
   185  
   186        </Directory>
   187           
   188        {{range $i, $h := .Hooks}}
   189        <SetProperty Action="SetCustomExec{{$i}}" {{if eq $h.Execute "immediate"}} Id="WixQuietExecCmdLine" {{else}} Id="CustomExec{{$i}}" {{end}} Value="{{$h.CookedCommand}}" Before="CustomExec{{$i}}" Sequence="execute"/>
   190        <CustomAction Id="CustomExec{{$i}}" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="{{$h.Execute}}" Impersonate="{{$h.Impersonate}}" {{if gt ($h.Return | len) 0}} Return="{{$h.Return}}" {{end}}/>
   191        {{end}}
   192  
   193        <!-- 
   194          This command needs CALL in it, otherwise the quoted values aren't treated correctly.
   195          https://stackoverflow.com/questions/17674255/why-does-windows-start-command-not-work-with-spaces-in-arguments-and-path
   196        -->
   197  
   198        <CustomAction Id="CustomExecCreateManagerYaml_set"
   199                Property="CustomExecCreateManagerYaml"
   200                Value="&quot;[CMDEXE]&quot; /C CALL &quot;[INSTALLDIR]install\generate-manager-yaml.bat&quot; &quot;[INSTALLDIR]&quot; &quot;[OPAMPENDPOINT]&quot; &quot;[OPAMPSECRETKEY]&quot; &quot;[OPAMPLABELS]&quot;"
   201                Execute="immediate"/>
   202  
   203        <CustomAction Id="CustomExecCreateManagerYaml" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Impersonate="no" Return="check" />
   204  
   205        <CustomAction Id="CustomExecRemoveManagerYaml_set"
   206                Property="CustomExecRemoveManagerYaml"
   207                Value="&quot;[CMDEXE]&quot; /C del &quot;[INSTALLDIR]manager.yaml&quot;"
   208                Execute="immediate"/>
   209  
   210        <CustomAction Id="CustomExecRemoveManagerYaml" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Impersonate="no" Return="ignore" />
   211  
   212        <InstallExecuteSequence>
   213           {{range $i, $h := .Hooks}}
   214           <Custom Action="CustomExec{{$i}}" {{if eq $h.When "install"}} After="InstallFiles" {{else if eq $h.Execute "immediate"}} Before="InstallValidate" {{else}} After="InstallInitialize" {{end}}>
   215              {{if eq $h.When "install"}}
   216              <![CDATA[NOT Installed AND NOT REMOVE{{if gt ($h.Condition | len) 0}} AND ({{$h.Condition}}){{end}}]]>
   217              {{else if eq $h.When "uninstall"}}
   218              <![CDATA[REMOVE{{if gt ($h.Condition | len) 0}} AND ({{$h.Condition}}){{end}}]]>
   219              {{else if gt ($h.Condition | len) 0 }}
   220              <![CDATA[{{$h.Condition}}]]>
   221              {{end}}
   222           </Custom>
   223           {{end}}
   224  
   225          <!-- The below custom actions should be skipped if VersionNT (32 bit systems) or VersionNT64 (64 bit systems) is >= 603.
   226              This should filter out older versions of Windows where some custom actions get stuck. 
   227              Link to windows versions for reference https://learn.microsoft.com/en-us/windows/win32/msi/operating-system-property-values-->
   228  
   229          <!-- Schedule the action that creates the manager.yaml file on initial install -->
   230          <Custom Action="CustomExecCreateManagerYaml_set" After="InstallInitialize" >
   231              <![CDATA[(VersionNT >= 603 OR VersionNT64 >= 603) AND NOT Installed AND NOT REMOVE AND ENABLEMANAGEMENT AND NOT WIX_UPGRADE_DETECTED]]>
   232          </Custom>
   233          <Custom Action="CustomExecCreateManagerYaml" After="InstallFiles" >
   234              <![CDATA[(VersionNT >= 603 OR VersionNT64 >= 603) AND NOT Installed AND NOT REMOVE AND ENABLEMANAGEMENT AND NOT WIX_UPGRADE_DETECTED]]>
   235          </Custom>
   236          
   237          <!-- Schedule the action that removes the manager.yaml file on final uninstall -->
   238          <Custom Action="CustomExecRemoveManagerYaml_set" After="InstallInitialize" >
   239              <![CDATA[(VersionNT >= 603 OR VersionNT64 >= 603) and REMOVE="ALL" and not UPGRADINGPRODUCTCODE]]>
   240          </Custom>
   241          <Custom Action="CustomExecRemoveManagerYaml" Before="RemoveFiles" >
   242              <![CDATA[(VersionNT >= 603 OR VersionNT64 >= 603) and REMOVE="ALL" and not UPGRADINGPRODUCTCODE]]>
   243          </Custom>
   244        </InstallExecuteSequence>
   245  
   246        <Feature Id="DefaultFeature" Level="1">
   247           {{range $i, $e := .Environments}}
   248           <ComponentRef Id="Environments{{$i}}"/>
   249           {{end}}
   250           {{$id := 0}}
   251           {{define "FILESREF"}}
   252           {{range $f := .}}
   253           <ComponentRef Id="ApplicationFiles{{$f.ID}}"/>
   254           {{end}}
   255           {{end}}
   256           {{template "FILESREF" .Directory.Files}}
   257           {{define "DIRECTORIESREF"}}
   258           {{range $d := .}}
   259           {{template "FILESREF" $d.Files}}
   260           {{template "DIRECTORIESREF" $d.Directories}}
   261           {{end}}
   262           {{end}}
   263           {{template "DIRECTORIESREF" .Directory.Directories}}
   264           {{range $i, $r := .Registries}}
   265           <ComponentRef Id="RegistryEntries{{$i}}"/>
   266           {{end}}
   267           <ComponentRef Id="RegistryEntriesARP"/>
   268           {{range $i, $e := .Shortcuts}}
   269           <ComponentRef Id="ApplicationShortcuts{{$i}}"/>
   270           {{end}}
   271        </Feature>
   272  
   273        <UI>
   274           <UIRef Id="WixUI_ErrorProgressText"/>
   275           <!-- Define the installer UI -->
   276           <UIRef Id="WixUI_HK"/>
   277        </UI>
   278  
   279        <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
   280  
   281        <!-- disable "change" button when uninstalling the collector-->
   282        <Property Id="ARPNOMODIFY" Value="yes" Secure="yes" />
   283  
   284        <!-- this should help to propagate env var changes -->
   285        <CustomActionRef Id="WixBroadcastEnvironmentChange" />
   286     </Product>
   287  
   288  </Wix>