Class: Chef::Provider::Package::Windows
- Inherits:
-
Chef::Provider::Package
- Object
- Chef::Provider
- Chef::Provider::Package
- Chef::Provider::Package::Windows
- Includes:
- Mixin::Checksum, Mixin::Uris
- Defined in:
- lib/chef/provider/package/windows.rb,
lib/chef/provider/package/windows/exe.rb,
lib/chef/provider/package/windows/msi.rb,
lib/chef/provider/package/windows/registry_uninstall_entry.rb
Defined Under Namespace
Classes: Exe, MSI, RegistryUninstallEntry
Constant Summary
Constants included from Mixin::ShellOut
Mixin::ShellOut::DEPRECATED_OPTIONS
Instance Attribute Summary
Attributes inherited from Chef::Provider
#action, #cookbook_name, #current_resource, #new_resource, #recipe_name, #run_context
Instance Method Summary collapse
- #action_install ⇒ Object
-
#candidate_version ⇒ String
Candidate_version.
-
#current_version_array ⇒ Array
this package provider does not support package arrays However, There may be multiple versions for a single package so the first element may be a nested array.
- #define_resource_requirements ⇒ Object
- #have_any_matching_version? ⇒ Boolean
-
#install_package(name, version) ⇒ Object
Chef::Provider::Package action_install + action_remove call install_package + remove_package Pass those calls to the correct sub-provider.
- #installer_type ⇒ Object
-
#load_current_resource ⇒ Object
load_current_resource is run in Chef::Provider#run_action when not in whyrun_mode?.
-
#new_version_array ⇒ Array
New_version(s) as an array.
- #package_provider ⇒ Object
- #remove_package(name, version) ⇒ Object
-
#target_version_already_installed?(current_version, new_version) ⇒ Boolean
True if new_version is equal to or included in current_version.
Methods included from Mixin::Checksum
Methods included from Mixin::Uris
Methods inherited from Chef::Provider::Package
#action_purge, #action_reconfig, #action_remove, #action_upgrade, #as_array, #check_resource_semantics!, #expand_options, #get_preseed_file, #initialize, #multipackage_api_adapter, #preseed_package, #preseed_resource, #purge_package, #reconfig_package, #removing_package?, #upgrade_package, #version_requirement_satisfied?, #whyrun_supported?
Methods included from Mixin::SubclassDirective
Methods included from Mixin::ShellOut
#run_command_compatible_options, #shell_out, #shell_out!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!
Methods included from Mixin::Command
#chdir_or_tmpdir, #handle_command_failures, #output_of_command, #run_command, #run_command_and_return_stdout_stderr, #run_command_with_systems_locale
Methods included from Mixin::Command::Windows
Methods included from Mixin::Command::Unix
Methods inherited from Chef::Provider
#action_nothing, #check_resource_semantics!, #cleanup_after_converge, #converge_by, #converge_if_changed, #events, include_resource_dsl, include_resource_dsl_module, #initialize, #node, #process_resource_requirements, provides, provides?, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, supports?, use_inline_resources, #whyrun_mode?, #whyrun_supported?
Methods included from Mixin::Provides
#provided_as, #provides, #provides?
Methods included from Mixin::DescendantsTracker
#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited
Methods included from DeprecatedLWRPClass
#const_missing, #deprecated_constants, #register_deprecated_lwrp_class
Methods included from Mixin::LazyModuleInclude
#descendants, #include, #included
Methods included from Mixin::NotifyingBlock
#notifying_block, #subcontext_block
Methods included from DSL::DeclareResource
#build_resource, #declare_resource, #delete_resource, #delete_resource!, #edit_resource, #edit_resource!, #find_resource, #find_resource!, #with_run_context
Methods included from Mixin::PowershellOut
#powershell_out, #powershell_out!
Methods included from Mixin::WindowsArchitectureHelper
#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory
Methods included from DSL::PlatformIntrospection
#docker?, #platform?, #platform_family?, #value_for_platform, #value_for_platform_family
Constructor Details
This class inherits a constructor from Chef::Provider::Package
Instance Method Details
#action_install ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/chef/provider/package/windows.rb', line 123 def action_install if uri_scheme?(new_resource.source) download_source_file load_current_resource else validate_content! end super end |
#candidate_version ⇒ String
Returns candidate_version.
151 152 153 |
# File 'lib/chef/provider/package/windows.rb', line 151 def candidate_version @candidate_version ||= (new_resource.version || "latest") end |
#current_version_array ⇒ Array
this package provider does not support package arrays However, There may be multiple versions for a single package so the first element may be a nested array
159 160 161 |
# File 'lib/chef/provider/package/windows.rb', line 159 def current_version_array [ current_resource.version ] end |
#define_resource_requirements ⇒ Object
37 38 39 40 41 42 |
# File 'lib/chef/provider/package/windows.rb', line 37 def define_resource_requirements requirements.assert(:install) do |a| a.assertion { new_resource.source || msi? } a. Chef::Exceptions::NoWindowsPackageSource, "Source for package #{new_resource.name} must be specified in the resource's source property for package to be installed because the package_name property is used to test for the package installation state for this package type." end end |
#have_any_matching_version? ⇒ Boolean
176 177 178 |
# File 'lib/chef/provider/package/windows.rb', line 176 def have_any_matching_version? target_version_already_installed?(current_resource.version, new_resource.version) end |
#install_package(name, version) ⇒ Object
Chef::Provider::Package action_install + action_remove call install_package + remove_package Pass those calls to the correct sub-provider
136 137 138 |
# File 'lib/chef/provider/package/windows.rb', line 136 def install_package(name, version) package_provider.install_package end |
#installer_type ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/chef/provider/package/windows.rb', line 73 def installer_type # Depending on the installer, we may need to examine installer_type or # source attributes, or search for text strings in the installer file # binary to determine the installer type for the user. Since the file # must be on disk to do so, we have to make this choice in the provider. @installer_type ||= begin return :msi if msi? if new_resource.installer_type new_resource.installer_type elsif source_location.nil? inferred_registry_type else basename = ::File.basename(source_location) file_extension = basename.split(".").last.downcase # search the binary file for installer type ::Kernel.open(::File.(source_location), "rb") do |io| filesize = io.size bufsize = 4096 # read 4K buffers overlap = 16 # bytes to overlap between buffer reads until io.eof contents = io.read(bufsize) case contents when /inno/i # Inno Setup return :inno when /wise/i # Wise InstallMaster return :wise when /nullsoft/i # Nullsoft Scriptable Install System return :nsis end if io.tell() < filesize io.seek(io.tell() - overlap) end end # if file is named 'setup.exe' assume installshield if basename == "setup.exe" :installshield else raise Chef::Exceptions::CannotDetermineWindowsInstallerType, "Installer type for Windows Package '#{new_resource.name}' not specified and cannot be determined from file extension '#{file_extension}'" end end end end end |
#load_current_resource ⇒ Object
load_current_resource is run in Chef::Provider#run_action when not in whyrun_mode?
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/chef/provider/package/windows.rb', line 45 def load_current_resource @current_resource = Chef::Resource::WindowsPackage.new(new_resource.name) if downloadable_file_missing? Chef::Log.debug("We do not know the version of #{new_resource.source} because the file is not downloaded") current_resource.version(:unknown.to_s) else current_resource.version(package_provider.installed_version) new_resource.version(package_provider.package_version) if package_provider.package_version end current_resource end |
#new_version_array ⇒ Array
Returns new_version(s) as an array.
145 146 147 148 |
# File 'lib/chef/provider/package/windows.rb', line 145 def new_version_array # Because the one in the parent caches things [new_resource.version] end |
#package_provider ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/chef/provider/package/windows.rb', line 58 def package_provider @package_provider ||= begin case installer_type when :msi Chef::Log.debug("#{new_resource} is MSI") require "chef/provider/package/windows/msi" Chef::Provider::Package::Windows::MSI.new(resource_for_provider, uninstall_registry_entries) else Chef::Log.debug("#{new_resource} is EXE with type '#{installer_type}'") require "chef/provider/package/windows/exe" Chef::Provider::Package::Windows::Exe.new(resource_for_provider, installer_type, uninstall_registry_entries) end end end |
#remove_package(name, version) ⇒ Object
140 141 142 |
# File 'lib/chef/provider/package/windows.rb', line 140 def remove_package(name, version) package_provider.remove_package end |
#target_version_already_installed?(current_version, new_version) ⇒ Boolean
Returns true if new_version is equal to or included in current_version.
167 168 169 170 171 172 173 174 |
# File 'lib/chef/provider/package/windows.rb', line 167 def target_version_already_installed?(current_version, new_version) Chef::Log.debug("Checking if #{new_resource} version '#{new_version}' is already installed. #{current_version} is currently installed") if current_version.is_a?(Array) current_version.include?(new_version) else new_version == current_version end end |