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

Methods included from Mixin::ShellOut

#a_to_s, #clean_array, #shell_out, #shell_out!, #shell_out_compact, #shell_out_compact!, #shell_out_compact_timeout, #shell_out_compact_timeout!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!

Methods included from Mixin::PathSanity

#enforce_path_sanity, #sanitized_path

Constructor Details

#initialize(resource, installer_type, uninstall_entries) ⇒ Exe

Returns a new instance of Exe


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

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

Instance Attribute Details

#installer_typeObject (readonly)

Returns the value of attribute installer_type


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

def installer_type
  @installer_type
end

#new_resourceObject (readonly)

Returns the value of attribute new_resource


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

def new_resource
  @new_resource
end

#uninstall_entriesObject (readonly)

Returns the value of attribute uninstall_entries


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

def uninstall_entries
  @uninstall_entries
end

Instance Method Details

#expand_options(options) ⇒ Object

From Chef::Provider::Package


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

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

#install_packageObject


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

def install_package
  Chef::Log.debug("#{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(" "), timeout: new_resource.timeout, returns: new_resource.returns
  )
end

#installed_versionObject

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


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

def installed_version
  Chef::Log.debug("#{new_resource} checking package version")
  current_installed_version
end

#package_versionObject


50
51
52
# File 'lib/chef/provider/package/windows/exe.rb', line 50

def package_version
  new_resource.version
end

#remove_packageObject


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

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|
    Chef::Log.debug("Registry provided uninstall string for #{new_resource} is '#{uninstall_string}'")
    shell_out!(uninstall_command(uninstall_string), timeout: new_resource.timeout, returns: new_resource.returns)
  end
end