class Chef::Provider::Package::Windows::Exe

Attributes

installer_type[R]
logger[R]
new_resource[R]
uninstall_entries[R]

Public Class Methods

new(resource, installer_type, uninstall_entries) click to toggle source
# 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

Public Instance Methods

expand_options(options) click to toggle source

From Chef::Provider::Package

# File lib/chef/provider/package/windows/exe.rb, line 42
def expand_options(options)
  options ? " #{options}" : ""
end
install_package() click to toggle source
# 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(" "), timeout: new_resource.timeout, returns: new_resource.returns, sensitive: new_resource.sensitive
  )
end
installed_version() click to toggle source

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

# 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_version() click to toggle source
# File lib/chef/provider/package/windows/exe.rb, line 52
def package_version
  new_resource.version
end
remove_package() click to toggle source
# 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), timeout: new_resource.timeout, returns: new_resource.returns)
  end
end

Private Instance Methods

current_installed_version() click to toggle source
# File lib/chef/provider/package/windows/exe.rb, line 93
def current_installed_version
  @current_installed_version ||=
    if uninstall_entries.count != 0
      uninstall_entries.map(&:display_version).uniq
    end
end
unattended_flags() click to toggle source

unattended.sourceforge.net/installers.php

# File lib/chef/provider/package/windows/exe.rb, line 101
def unattended_flags
  case installer_type
  when :installshield
    "/s /sms"
  when :nsis
    "/S /NCRC"
  when :inno
    "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART"
  when :wise
    "/s"
  end
end
uninstall_command(uninstall_string) click to toggle source
# File lib/chef/provider/package/windows/exe.rb, line 82
def uninstall_command(uninstall_string)
  uninstall_string = "\"#{uninstall_string}\"" if ::File.exist?(uninstall_string)
  uninstall_string = [
    uninstall_string,
    expand_options(new_resource.options),
    " ",
    unattended_flags,
  ].join
  %{start "" /wait #{uninstall_string} & exit %%%%ERRORLEVEL%%%%}
end