Class: Chef::Provider::Package::Windows::Exe

Inherits:
Object
  • Object
show all
Includes:
Mixin::ShellOut
Defined in:
lib/chef/provider/package/windows/exe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, installer_type, uninstall_entries) ⇒ Exe

Returns a new instance of Exe.


29
30
31
32
33
34
# File 'lib/chef/provider/package/windows/exe.rb', line 29

def initialize(resource, installer_type, uninstall_entries)
  @new_resource = resource
  @logger = new_resource.logger
  @installer_type = installer_type
  @uninstall_entries = uninstall_entries
end

Instance Attribute Details

#installer_typeObject (readonly)

Returns the value of attribute installer_type


38
39
40
# File 'lib/chef/provider/package/windows/exe.rb', line 38

def installer_type
  @installer_type
end

#loggerObject (readonly)

Returns the value of attribute logger


37
38
39
# File 'lib/chef/provider/package/windows/exe.rb', line 37

def logger
  @logger
end

#new_resourceObject (readonly)

Returns the value of attribute new_resource


36
37
38
# File 'lib/chef/provider/package/windows/exe.rb', line 36

def new_resource
  @new_resource
end

#uninstall_entriesObject (readonly)

Returns the value of attribute uninstall_entries


39
40
41
# File 'lib/chef/provider/package/windows/exe.rb', line 39

def uninstall_entries
  @uninstall_entries
end

Instance Method Details

#expand_options(options) ⇒ Object

From Chef::Provider::Package


42
43
44
# File 'lib/chef/provider/package/windows/exe.rb', line 42

def expand_options(options)
  options ? " #{options}" : ""
end

#install_packageObject


56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/chef/provider/package/windows/exe.rb', line 56

def install_package
  logger.trace("#{new_resource} installing #{new_resource.installer_type} package '#{new_resource.source}'")
  shell_out!(
    [
      "start",
      "\"\"",
      "/wait",
      "\"#{new_resource.source}\"",
      unattended_flags,
      expand_options(new_resource.options),
      "& exit %%%%ERRORLEVEL%%%%",
    ].join(" "), default_env: false, timeout: new_resource.timeout, returns: new_resource.returns, sensitive: new_resource.sensitive
  )
end

#installed_versionObject

Returns a version if the package is installed or nil if it is not.


47
48
49
50
# File 'lib/chef/provider/package/windows/exe.rb', line 47

def installed_version
  logger.trace("#{new_resource} checking package version")
  current_installed_version
end

#package_versionObject


52
53
54
# File 'lib/chef/provider/package/windows/exe.rb', line 52

def package_version
  new_resource.version
end

#remove_packageObject


71
72
73
74
75
76
77
78
# File 'lib/chef/provider/package/windows/exe.rb', line 71

def remove_package
  uninstall_version = new_resource.version || current_installed_version
  uninstall_entries.select { |entry| [uninstall_version].flatten.include?(entry.display_version) }
    .map(&:uninstall_string).uniq.each do |uninstall_string|
      logger.trace("Registry provided uninstall string for #{new_resource} is '#{uninstall_string}'")
      shell_out!(uninstall_command(uninstall_string), default_env: false, timeout: new_resource.timeout, returns: new_resource.returns)
    end
end