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

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

Constant Summary

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

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, replace_forward_slashes, with_key

Methods included from Enumerable

#uniq

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail

Methods included from Util::Windows::Registry

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

Methods included from FFI::Library

#attach_function_private

Constructor Details

#initialize(name, version, uninstall_string) ⇒ ExePackage

Returns a new instance of ExePackage.



33
34
35
36
37
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 33

def initialize(name, version, uninstall_string)
  super(name, version)

  @uninstall_string = uninstall_string
end

Instance Attribute Details

#uninstall_stringObject (readonly)



5
6
7
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 5

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



8
9
10
11
12
13
14
15
16
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 8

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



44
45
46
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 44

def self.install_command(resource)
  ['cmd.exe', '/c', 'start', '"puppet-install"', '/w', munge(resource[:source])]
end

.valid?(name, values) ⇒ Boolean

Is this a valid executable package we should manage?

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 19

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)


40
41
42
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 40

def match?(resource)
  resource[:name] == name
end

#uninstall_commandObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 48

def uninstall_command
  # 1. Launch using cmd /c start because if the executable is a console
  #    application Windows will automatically display its console window
  # 2. Specify a quoted title, otherwise if uninstall_string is quoted,
  #    start will interpret that to be the title, and get confused
  # 3. Specify /w (wait) to wait for uninstall to finish
  command = ['cmd.exe', '/c', 'start', '"puppet-uninstall"', '/w']

  # 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