Class: Puppet::Provider::Package::Windows::ExePackage

Inherits:
Package show all
Defined in:
lib/puppet/provider/package/windows/exe_package.rb

Constant Summary collapse

REG_VALUE_NAMES =

registry values to load under each product entry in HKLMSOFTWAREMicrosoftWindowsCurrentVersionUninstall for this provider

[ 'DisplayVersion', 'UninstallString', 'ParentKeyName', 'Security Update', 'Update Rollup', 'Hotfix', 'WindowsInstaller' ]

Constants inherited from Package

Package::REG_DISPLAY_VALUE_NAMES

Constants included from Util::Windows::Registry

Util::Windows::Registry::ERROR_NO_MORE_ITEMS, Util::Windows::Registry::KEY32, Util::Windows::Registry::KEY64, Util::Windows::Registry::KEY_ALL_ACCESS, Util::Windows::Registry::KEY_READ, Util::Windows::Registry::KEY_WRITE, Util::Windows::Registry::WCHAR_SIZE

Instance Attribute Summary collapse

Attributes inherited from Package

#name, #version

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Package

each, get_display_name, installer_class, munge, quote, reg_value_names_to_load, replace_forward_slashes, with_key

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, error_location, error_location_with_space, error_location_with_unknowns, #exceptwrap, #fail

Methods included from Util::Windows::Registry

#delete_key, #delete_value, #each_key, #each_value, #keys, #open, #root, #values, #values_by_name

Constructor Details

#initialize(name, version, uninstall_string) ⇒ ExePackage

Returns a new instance of ExePackage.

 53 54 55 56 57
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 53 def initialize(name, version, uninstall_string) super(name, version) @uninstall_string = uninstall_string end

Instance Attribute Details

#uninstall_stringObject (readonly)

 7 8 9
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 7 def uninstall_string @uninstall_string end

Class Method Details

.from_registry(name, values) ⇒ Object

Return an instance of the package from the registry, or nil

 28 29 30 31 32 33 34 35 36
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 28 def self.from_registry(name, values) if valid?(name, values) ExePackage.new( get_display_name(values), values['DisplayVersion'], values['UninstallString'] ) end end

.install_command(resource) ⇒ Object

 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 64 def self.install_command(resource) file_location = resource[:source] if file_location.start_with?('http://', 'https://') tempfile = Tempfile.new(['', '.exe']) begin uri = URI(Puppet::Util.uri_encode(file_location)) client = Puppet.runtime[:http] client.get(uri, options: { include_system_store: true }) do |response| raise Puppet::HTTP::ResponseError, response unless response.success? File.open(tempfile.path, 'wb') do |file| response.read_body do |data| file.write(data) end end end rescue => detail raise Puppet::Error.new(_("Error when installing %{package}: %{detail}") % { package: resource[:name], detail: detail.message }, detail) ensure register(tempfile.path) tempfile.close() file_location = tempfile.path end end munge(file_location) end

.register(path) ⇒ Object

 22 23 24 25
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 22 def self.register(path) Puppet::Type::Package::ProviderWindows.paths ||= [] Puppet::Type::Package::ProviderWindows.paths << path end

.valid?(name, values) ⇒ Boolean

Is this a valid executable package we should manage?

Returns:

  • (Boolean)
 39 40 41 42 43 44 45 46 47 48 49 50 51
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 39 def self.valid?(name, values) # See http://community.spiceworks.com/how_to/show/2238  displayName = get_display_name(values) !!(displayName && displayName.length > 0 && values['UninstallString'] && values['UninstallString'].length > 0 && values['WindowsInstaller'] != 1 && # DWORD  name !~ /^KB[0-9]{6}/ && values['ParentKeyName'].nil? && values['Security Update'].nil? && values['Update Rollup'].nil? && values['Hotfix'].nil?) end

Instance Method Details

#match?(resource) ⇒ Boolean

Does this package match the resource?

Returns:

  • (Boolean)
 60 61 62
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 60 def match?(resource) resource[:name] == name end

#uninstall_commandObject

 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 92 def uninstall_command # Only quote bare uninstall strings, e.g.  # C:\Program Files (x86)\Notepad++\uninstall.exe  # Don't quote uninstall strings that are already quoted, e.g.  # "c:\ruby187\unins000.exe"  # Don't quote uninstall strings that contain arguments:  # "C:\Program Files (x86)\Git\unins000.exe" /SILENT  if uninstall_string =~ /\A[^"]*.exe\Z/i command = "\"#{uninstall_string}\"" else command = uninstall_string end command end