Class: Chef::Provider::Package::Windows::MSI
- Inherits:
-
Object
- Object
- Chef::Provider::Package::Windows::MSI
- Defined in:
- lib/chef/provider/package/windows/msi.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#new_resource ⇒ Object
readonly
Returns the value of attribute new_resource.
-
#uninstall_entries ⇒ Object
readonly
Returns the value of attribute uninstall_entries.
Instance Method Summary collapse
-
#expand_options(options) ⇒ Object
From Chef::Provider::Package.
-
#initialize(resource, uninstall_entries) ⇒ MSI
constructor
A new instance of MSI.
- #install_package ⇒ Object
-
#installed_version ⇒ Object
Returns a version if the package is installed or nil if it is not.
- #package_version ⇒ Object
- #remove_package ⇒ Object
Methods included from ReservedNames::Win32::API::Installer
#get_installed_version, #get_product_property, #open_package
Constructor Details
#initialize(resource, uninstall_entries) ⇒ MSI
Returns a new instance of MSI.
32 33 34 35 36 |
# File 'lib/chef/provider/package/windows/msi.rb', line 32 def initialize(resource, uninstall_entries) @new_resource = resource @logger = new_resource.logger @uninstall_entries = uninstall_entries end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
39 40 41 |
# File 'lib/chef/provider/package/windows/msi.rb', line 39 def logger @logger end |
#new_resource ⇒ Object (readonly)
Returns the value of attribute new_resource.
38 39 40 |
# File 'lib/chef/provider/package/windows/msi.rb', line 38 def new_resource @new_resource end |
#uninstall_entries ⇒ Object (readonly)
Returns the value of attribute uninstall_entries.
40 41 42 |
# File 'lib/chef/provider/package/windows/msi.rb', line 40 def uninstall_entries @uninstall_entries end |
Instance Method Details
#expand_options(options) ⇒ Object
From Chef::Provider::Package
43 44 45 |
# File 'lib/chef/provider/package/windows/msi.rb', line 43 def () ? " #{}" : "" end |
#install_package ⇒ Object
70 71 72 73 74 |
# File 'lib/chef/provider/package/windows/msi.rb', line 70 def install_package # We could use MsiConfigureProduct here, but we'll start off with msiexec logger.trace("#{new_resource} installing MSI package '#{new_resource.source}'") shell_out!("msiexec /qn /i \"#{new_resource.source}\" #{(new_resource.)}", default_env: false, timeout: new_resource.timeout, returns: new_resource.returns) end |
#installed_version ⇒ Object
Returns a version if the package is installed or nil if it is not.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/chef/provider/package/windows/msi.rb', line 48 def installed_version if !new_resource.source.nil? && ::File.exist?(new_resource.source) logger.trace("#{new_resource} getting product code for package at #{new_resource.source}") product_code = get_product_property(new_resource.source, "ProductCode") logger.trace("#{new_resource} checking package status and version for #{product_code}") get_installed_version(product_code) else if uninstall_entries.count != 0 uninstall_entries.map(&:display_version).uniq end end end |
#package_version ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/chef/provider/package/windows/msi.rb', line 61 def package_version return new_resource.version if new_resource.version if !new_resource.source.nil? && ::File.exist?(new_resource.source) logger.trace("#{new_resource} getting product version for package at #{new_resource.source}") get_product_property(new_resource.source, "ProductVersion") end end |
#remove_package ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/chef/provider/package/windows/msi.rb', line 76 def remove_package # We could use MsiConfigureProduct here, but we'll start off with msiexec if !new_resource.source.nil? && ::File.exist?(new_resource.source) logger.trace("#{new_resource} removing MSI package '#{new_resource.source}'") shell_out!("msiexec /qn /x \"#{new_resource.source}\" #{(new_resource.)}", default_env: false, timeout: new_resource.timeout, returns: new_resource.returns) else uninstall_version = new_resource.version || installed_version uninstall_entries.select { |entry| [uninstall_version].flatten.include?(entry.display_version) } .map(&:uninstall_string).uniq.each do |uninstall_string| uninstall_string = "msiexec /x #{uninstall_string.match(/{.*}/)}" uninstall_string += (new_resource.) uninstall_string += " /q" unless %r{ /q}.match?(uninstall_string.downcase) logger.trace("#{new_resource} removing MSI package version using '#{uninstall_string}'") shell_out!(uninstall_string, default_env: false, timeout: new_resource.timeout, returns: new_resource.returns) end end end |