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, installer_class, munge, quote, replace_forward_slashes, with_key

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.



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

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(
      values['DisplayName'],
      values['DisplayVersion'],
      values['UninstallString']
    )
  end
end

.install_command(resource) ⇒ Object



42
43
44
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 42

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
# 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
  !!(values['DisplayName'] and values['DisplayName'].length > 0 and
     values['UninstallString'] and values['UninstallString'].length > 0 and
     values['WindowsInstaller'] != 1 and # DWORD
     name !~ /^KB[0-9]{6}/ and
     values['ParentKeyName'] == nil and
     values['Security Update'] == nil and
     values['Update Rollup'] == nil and
     values['Hotfix'] == nil)
end

Instance Method Details

#match?(resource) ⇒ Boolean

Does this package match the resource?

Returns:

  • (Boolean)


38
39
40
# File 'lib/puppet/provider/package/windows/exe_package.rb', line 38

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

#uninstall_commandObject



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

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