Skip to content

Commit

Permalink
(RE-6470) enable config file special case
Browse files Browse the repository at this point in the history
This commit adds the functionality to specical
case configuration files (specifically puppet.conf)
so that we can pull in configuration and preserve
these files if they were edited by the user
  • Loading branch information
Sean P. McDonald committed Mar 22, 2016
1 parent a1ab832 commit 0495e5d
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 30 deletions.
108 changes: 105 additions & 3 deletions resources/windows/wix/customactions.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,54 @@
<Fragment>
<ComponentGroup Id="FragmentCustomActions" />

<!-- Properties for existing Ini Values - expanding the remembered properties pattern just a bit
-->

<CustomAction
Id="SetIniPropertyValues"
Script="vbscript"
Execute="firstSequence"
Return="ignore">
<![CDATA[
On Error Resume Next
Function SetPropertyFromIni (keyName, propertyName, textToSearch)
Set iniValueRegex = New RegExp
iniValueRegex.IgnoreCase = true
iniValueRegex.Multiline = true
iniValueRegex.Global = false
iniValueRegex.Pattern = "^" & keyName & "=(.*[^\s\r\n]*)$"
Set matches = iniValueRegex.Execute(textToSearch)
dim iniValue
iniValue = ""
If (matches.Count <> 0) Then
If (matches.Item(0).SubMatches.Count <> 0) Then
iniValue = matches.Item(0).SubMatches(0)
iniValue = Replace(Replace(Replace(iniValue, Chr(13), ""), vbNewLine, ""), vbLf, "")
End If
End If
If (iniValue <> "") Then
Session.Property(propertyName) = iniValue
End If
End Function
Dim fso, wshShell, iniPath
Set wshShell = CreateObject("WScript.Shell")
iniPath = wshShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%\PuppetLabs\puppet\etc\puppet.conf")
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(iniPath)) Then
Set iniFile = fso.OpenTextFile(iniPath, 1, false)
iniFileText = iniFile.ReadAll()
iniFile.Close
Set iniFile = Nothing
SetPropertyFromIni "server", "INI_PUPPET_MASTER_SERVER", iniFileText
SetPropertyFromIni "environment", "INI_PUPPET_AGENT_ENVIRONMENT", iniFileText
SetPropertyFromIni "certname", "INI_PUPPET_AGENT_CERTNAME", iniFileText
SetPropertyFromIni "ca_server", "INI_PUPPET_CA_SERVER", iniFileText
End If
]]>
</CustomAction>

<!-- Custom Actions to handle command line property values that override
remembered property values -->
<!-- INSTALLDIR -->
<CustomAction
Id="SaveCmdLineInstallDir"
Expand All @@ -17,6 +65,11 @@
Execute="firstSequence" />

<!-- PUPPET_MASTER_SERVER -->
<CustomAction
Id="SetFromIniPuppetMasterServer"
Property="PUPPET_MASTER_SERVER"
Value="[INI_PUPPET_MASTER_SERVER]"
Execute="firstSequence" />
<CustomAction
Id="SaveCmdLinePuppetMasterServer"
Property="CMDLINE_PUPPET_MASTER_SERVER"
Expand All @@ -34,6 +87,11 @@
Execute="firstSequence" />

<!-- PUPPET_AGENT_ENVIRONMENT -->
<CustomAction
Id="SetFromIniPuppetAgentEnvironment"
Property="PUPPET_AGENT_ENVIRONMENT"
Value="[INI_PUPPET_AGENT_ENVIRONMENT]"
Execute="firstSequence" />
<CustomAction
Id="SaveCmdLinePuppetAgentEnvironment"
Property="CMDLINE_PUPPET_AGENT_ENVIRONMENT"
Expand All @@ -51,6 +109,11 @@
Execute="firstSequence" />

<!-- PUPPET_AGENT_CERTNAME -->
<CustomAction
Id="SetFromIniPuppetAgentCertname"
Property="PUPPET_AGENT_CERTNAME"
Value="[INI_PUPPET_AGENT_CERTNAME]"
Execute="firstSequence" />
<CustomAction
Id="SaveCmdLinePuppetAgentCertname"
Property="CMDLINE_PUPPET_AGENT_CERTNAME"
Expand All @@ -63,6 +126,11 @@
Execute="firstSequence" />

<!-- PUPPET_CA_SERVER -->
<CustomAction
Id="SetFromIniPuppetCaServer"
Property="PUPPET_CA_SERVER"
Value="[INI_PUPPET_CA_SERVER]"
Execute="firstSequence" />
<CustomAction
Id="SaveCmdLinePuppetCaServer"
Property="CMDLINE_PUPPET_CA_SERVER"
Expand All @@ -86,7 +154,7 @@
Value="[CMDLINE_PUPPET_AGENT_STARTUP_MODE]"
Execute="firstSequence" />

<!-- PUPPET_AGENT_ACCOUNT_DOMAIN -->
<!-- PUPPET_AGENT_ACCOUNT_DOMAIN -->
<CustomAction
Id="SetDomainToLocalComputer"
Property="PUPPET_AGENT_ACCOUNT_DOMAIN"
Expand All @@ -98,17 +166,51 @@
Value="NT AUTHORITY"
Execute="firstSequence"/>

<!--<Property Id="WixQuietExecCmdLine" Value="&quot;[INSTALLDIR]service\nssm.exe&quot; stop pxp-agent"/> -->
<!--<Property Id="WixQuietExecCmdLine" Value="&quot;[INSTALLDIR]service\nssm.exe&quot; stop pxp-agent"/> -->
<CustomAction
Id="ShutdownPxpAgentService_SetProp"
Property="QtExecCmdLine"
Value="&quot;[INSTALLDIR]service\nssm.exe&quot; stop pxp-agent"
Execute="immediate" />
<CustomAction
<CustomAction
Id="ShutdownPxpAgentService"
BinaryKey="WixCA"
DllEntry="CAQuietExec"
Execute="immediate"
Return="ignore" />

<?if $(var.Platform) = x86 ?>
<!-- If these fail, we don't want to fail the installer -->
<!-- We can't do a registry search for powershell's installed location because it will turn up the WOW64Node version due to not being able to bypass redirection in RegistrySearch
So we will assume the default install location and if it fails, we will ignore the error.
this is the only way to grab path without expanding variables
[Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\\").GetValue("PATH", "", [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames).ToString();
[System.Text.RegularExpressions.Regex]::Replace([Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Control\Session Manager\Environment\").GetValue("PATH", "", [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames).ToString(), "c:\\Program files\\Puppet Labs\\Puppet\\bin(?>;)?", "", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
"c:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NonInteractive -InputFormat None -NoProfile -ExecutionPolicy Bypass -Command "[System.Text.RegularExpressions.Regex]::Replace([Microsoft.Win32.Registry]::LocalMachine.OpenSubKey('SYSTEM\CurrentControlSet\Control\Session Manager\Environment\').GetValue('PATH', '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames).ToString(), [System.Text.RegularExpressions.Regex]::Escape('c:\Program Files\Puppet Labs\Puppet\bin') + '(?>;)?', '', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) | %{[System.Environment]::SetEnvironmentVariable('PATH',$_,'Machine')}"
&quot;[%WINDIR]\System32\WindowsPowerShell\v1.0\powershell.exe&quot; -NoLogo -NonInteractive -InputFormat None -NoProfile -ExecutionPolicy Bypass -Command &quot;[\[]System.Text.RegularExpressions.Regex[\]]::Replace([\[]Microsoft.Win32.Registry[\]]::LocalMachine.OpenSubKey(&apos;SYSTEM\CurrentControlSet\Control\Session Manager\Environment\&apos;).GetValue(&apos;PATH&apos;, &apos;&apos;, [\[]Microsoft.Win32.RegistryValueOptions[\]]::DoNotExpandEnvironmentNames).ToString(), [\[]System.Text.RegularExpressions.Regex[\]]::Escape(&apos;[ProgramFiles64Folder]$(var.OurCompanyName)\Puppet\bin&apos;) + &apos;([\?]&gt;;)[\?]&apos;, &apos;&apos;, [\[]System.Text.RegularExpressions.RegexOptions[\]]::IgnoreCase) | %[\{][\[]System.Environment[\]]::SetEnvironmentVariable(&apos;PATH&apos;,$_, &apos;Machine&apos;)[\}]&quot;
-->
<CustomAction
Id="Remove64BitPath_SetProp"
Property="Remove64BitPath"
Value="&quot;[%WINDIR]\System32\WindowsPowerShell\v1.0\powershell.exe&quot; -NoLogo -NonInteractive -InputFormat None -NoProfile -ExecutionPolicy Bypass -Command &quot;[\[]System.Text.RegularExpressions.Regex[\]]::Replace([\[]Microsoft.Win32.Registry[\]]::LocalMachine.OpenSubKey(&apos;SYSTEM\CurrentControlSet\Control\Session Manager\Environment\&apos;).GetValue(&apos;PATH&apos;, &apos;&apos;, [\[]Microsoft.Win32.RegistryValueOptions[\]]::DoNotExpandEnvironmentNames).ToString(), [\[]System.Text.RegularExpressions.Regex[\]]::Escape(&apos;[ProgramFiles64Folder]$(var.OurCompanyName)\Puppet\bin&apos;) + &apos;([\?]&gt;;)[\?]&apos;, &apos;&apos;, [\[]System.Text.RegularExpressions.RegexOptions[\]]::IgnoreCase) | %[\{][\[]System.Environment[\]]::SetEnvironmentVariable(&apos;PATH&apos;,$_, &apos;Machine&apos;)[\}]&quot;"
Execute="immediate" />
<CustomAction
Id="Remove64BitPath"
BinaryKey="WixCA"
DllEntry="CAQuietExec64"
Execute="deferred"
Return="ignore" />
<CustomAction
Id="Remove64BitProgramFiles_SetProp"
Property="Remove64BitProgramFiles"
Value="&quot;[%WINDIR]\System32\cmd.exe&quot; /c IF EXIST &quot;[ProgramFiles64Folder]$(var.OurCompanyName)\&quot; rmdir /s /q &quot;[ProgramFiles64Folder]$(var.OurCompanyName)&quot;"
Execute="immediate" />
<CustomAction
Id="Remove64BitProgramFiles"
BinaryKey="WixCA"
DllEntry="CAQuietExec64"
Execute="deferred"
Return="ignore" />
<?endif?>
</Fragment>
</Wix>
69 changes: 42 additions & 27 deletions resources/windows/wix/sequences.wxs.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,48 @@
restore the properties set by the command line overriding the recalled
value from the registry -->
<InstallUISequence>
<!-- INSTALLDIR -->
<!-- INSTALLDIR -->
<Custom Action='SaveCmdLineInstallDir' Before='AppSearch' />
<Custom Action='SetFromCmdLineInstallDir' After='AppSearch'>
CMDLINE_INSTALLDIR
</Custom>
<Custom Action='SetIniPropertyValues' After='AppSearch' />
<!-- PUPPET_MASTER_SERVER -->
<Custom Action='SetFromIniPuppetMasterServer' Before='FileCost'>
INI_PUPPET_MASTER_SERVER
</Custom>
<Custom Action='SaveCmdLinePuppetMasterServer' Before='AppSearch' />
<Custom Action='SetFromCmdLinePuppetMasterServer' After='AppSearch'>
<Custom Action='SetFromCmdLinePuppetMasterServer' After='FileCost'>
CMDLINE_PUPPET_MASTER_SERVER
</Custom>
<Custom Action='SetDefaultPuppetMasterServer' After='AppSearch'>
<Custom Action='SetDefaultPuppetMasterServer' Before='CostFinalize'>
PUPPET_MASTER_SERVER=""
</Custom>
<!-- PUPPET_AGENT_ENVIRONMENT -->
<Custom Action='SetFromIniPuppetAgentEnvironment' Before='FileCost'>
INI_PUPPET_AGENT_ENVIRONMENT
</Custom>
<Custom Action='SaveCmdLinePuppetAgentEnvironment' Before='AppSearch' />
<Custom Action='SetFromCmdLinePuppetAgentEnvironment' After='AppSearch'>
<Custom Action='SetFromCmdLinePuppetAgentEnvironment' After='FileCost'>
CMDLINE_PUPPET_AGENT_ENVIRONMENT
</Custom>
<Custom Action='SetDefaultPuppetAgentEnvironment' After='AppSearch'>
<Custom Action='SetDefaultPuppetAgentEnvironment' Before='CostFinalize'>
PUPPET_AGENT_ENVIRONMENT=""
</Custom>
<!-- PUPPET_AGENT_CERTNAME -->
<Custom Action='SetFromIniPuppetAgentCertname' Before='FileCost'>
INI_PUPPET_AGENT_CERTNAME
</Custom>
<Custom Action='SaveCmdLinePuppetAgentCertname' Before='AppSearch' />
<Custom Action='SetFromCmdLinePuppetAgentCertname' After='AppSearch'>
<Custom Action='SetFromCmdLinePuppetAgentCertname' After='FileCost'>
CMDLINE_PUPPET_AGENT_CERTNAME
</Custom>
<!-- PUPPET_CA_SERVER -->
<Custom Action='SetFromIniPuppetCaServer' Before='FileCost'>
INI_PUPPET_CA_SERVER
</Custom>
<Custom Action='SaveCmdLinePuppetCaServer' Before='AppSearch' />
<Custom Action='SetFromCmdLinePuppetCaServer' After='AppSearch'>
<Custom Action='SetFromCmdLinePuppetCaServer' After='FileCost'>
CMDLINE_PUPPET_CA_SERVER
</Custom>
<!-- PUPPET_AGENT_STARTUP_MODE -->
Expand All @@ -54,38 +67,51 @@
</InstallUISequence>

<InstallExecuteSequence>
<Custom Action='SetIniPropertyValues' After='AppSearch' />
<!-- INSTALLDIR -->
<Custom Action='SaveCmdLineInstallDir' Before='AppSearch' />
<Custom Action='SetFromCmdLineInstallDir' After='AppSearch'>
CMDLINE_INSTALLDIR
</Custom>
<!-- PUPPET_MASTER_SERVER -->
<Custom Action='SetFromIniPuppetMasterServer' Before='FileCost'>
INI_PUPPET_MASTER_SERVER
</Custom>
<Custom Action='SaveCmdLinePuppetMasterServer' Before='AppSearch' />
<Custom Action='SetFromCmdLinePuppetMasterServer' After='AppSearch'>
<Custom Action='SetFromCmdLinePuppetMasterServer' After='FileCost'>
CMDLINE_PUPPET_MASTER_SERVER
</Custom>
<Custom Action='SetDefaultPuppetMasterServer' After='AppSearch'>
<Custom Action='SetDefaultPuppetMasterServer' Before='CostFinalize'>
PUPPET_MASTER_SERVER=""
</Custom>
<!-- PUPPET_AGENT_ENVIRONMENT -->
<Custom Action='SetFromIniPuppetAgentEnvironment' Before='FileCost'>
INI_PUPPET_AGENT_ENVIRONMENT
</Custom>
<Custom Action='SaveCmdLinePuppetAgentEnvironment' Before='AppSearch' />
<Custom Action='SetFromCmdLinePuppetAgentEnvironment' After='AppSearch'>
<Custom Action='SetFromCmdLinePuppetAgentEnvironment' After='FileCost'>
CMDLINE_PUPPET_AGENT_ENVIRONMENT
</Custom>
<Custom Action='SetDefaultPuppetAgentEnvironment' After='AppSearch'>
<Custom Action='SetDefaultPuppetAgentEnvironment' Before='CostFinalize'>
PUPPET_AGENT_ENVIRONMENT=""
</Custom>
<!-- PUPPET_AGENT_CERTNAME -->
<Custom Action='SetFromIniPuppetAgentCertname' Before='FileCost'>
INI_PUPPET_AGENT_CERTNAME
</Custom>
<Custom Action='SaveCmdLinePuppetAgentCertname' Before='AppSearch' />
<Custom Action='SetFromCmdLinePuppetAgentCertname' After='AppSearch'>
<Custom Action='SetFromCmdLinePuppetAgentCertname' After='FileCost'>
CMDLINE_PUPPET_AGENT_CERTNAME
</Custom>
<!-- PUPPET_CA_SERVER -->
<Custom Action='SetFromIniPuppetCaServer' Before='FileCost'>
INI_PUPPET_CA_SERVER
</Custom>
<Custom Action='SaveCmdLinePuppetCaServer' Before='AppSearch' />
<Custom Action='SetFromCmdLinePuppetCaServer' After='AppSearch'>
<Custom Action='SetFromCmdLinePuppetCaServer' After='FileCost'>
CMDLINE_PUPPET_CA_SERVER
</Custom>
<!-- PUPPET_AGENT_START_MODE -->
<!-- PUPPET_AGENT_STARTUP_MODE -->
<Custom Action='SaveCmdLinePuppetAgentStartupMode' Before='AppSearch' />
<Custom Action='SetFromCmdLinePuppetAgentStartupMode' After='AppSearch'>
CMDLINE_PUPPET_AGENT_STARTUP_MODE
Expand All @@ -101,23 +127,12 @@
<Custom Action='Remove64BitPath_SetProp' After='CostFinalize' />
<Custom Action='Remove64BitProgramFiles_SetProp' After='CostFinalize' />
<Custom Action='Remove64BitProgramFiles' After='InstallFiles'>
<![CDATA[VersionNT64 >= 100 AND <%= settings[:win64] %> = no AND NOT (&<%= settings[:product_id] %>Runtime = 2)]]>
<![CDATA[VersionNT64 >= 100 AND $(var.Win64) = no AND NOT (&$(var.OurProductNameWord)Runtime = 2)]]>
</Custom>
<Custom Action='Remove64BitPath' After='InstallFiles'>
<![CDATA[VersionNT64 >= 100 AND <%= settings[:win64] %> = no AND NOT (&<%= settings[:product_id] %>Runtime = 2)]]>
<![CDATA[VersionNT64 >= 100 AND $(var.Win64) = no AND NOT (&$(var.OurProductNameWord)Runtime = 2)]]>
</Custom>
<?endif?>
<!-- Make sure pxp-agent service is shutdown before we validate the install -->
<!-- Only executed if pxp-agent is already installed (i.e. an Uninstall or upgrade - check for repair also) -->
<Custom Action='ShutdownPxpAgentService_SetProp' Before='ShutdownPxpAgentService'>
REMOVE="ALL" OR WIX_UPGRADE_DETECTED or REINSTALL
</Custom>
<Custom Action='ShutdownPxpAgentService' Before='InstallValidate'>
REMOVE="ALL" OR WIX_UPGRADE_DETECTED or REINSTALL
</Custom>
<!--
WIX_UPGRADE_DETECTED
-->
</InstallExecuteSequence>

<SetProperty Id="ARPINSTALLLOCATION" Value="[INSTALLDIR]" After="CostFinalize" />
Expand Down

0 comments on commit 0495e5d

Please sign in to comment.