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
Instance Attribute Summary
Attributes inherited from Chef::Provider
#action, #current_resource, #logger, #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.
- #version_equals?(current_version, new_version) ⇒ Boolean
Methods included from Mixin::Checksum
Methods included from Mixin::Uris
Methods inherited from Chef::Provider::Package
#action_lock, #action_unlock, #as_array, #check_resource_semantics!, #expand_options, #get_preseed_file, #initialize, #lock_package, #multipackage_api_adapter, #options, #package_locked, #preseed_package, #preseed_resource, #purge_package, #reconfig_package, #removing_package?, #unlock_package, #upgrade_package, #version_requirement_satisfied?
Methods included from Mixin::SubclassDirective
Methods included from Mixin::ShellOut
#a_to_s, apply_default_env, maybe_add_timeout, #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
Methods inherited from Chef::Provider
action, #action_nothing, #check_resource_semantics!, #cleanup_after_converge, #compile_and_converge_action, #converge_by, #converge_if_changed, #cookbook_name, #description, #events, include_resource_dsl?, include_resource_dsl_module, #initialize, #introduced, #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 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!, #resources, #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 Mixin::PowershellExec
Methods included from DSL::PlatformIntrospection
#docker?, #older_than_win_2012_or_8?, #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
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/chef/provider/package/windows.rb', line 131 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.
159 160 161 |
# File 'lib/chef/provider/package/windows.rb', line 159 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
167 168 169 |
# File 'lib/chef/provider/package/windows.rb', line 167 def current_version_array [ current_resource.version ] end |
#define_resource_requirements ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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.package_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 unless uri_scheme?(new_resource.source) requirements.assert(:install) do |a| a.assertion { ::File.exist?(new_resource.source) } a. Chef::Exceptions::Package, "Source for package #{new_resource.package_name} does not exist" a.whyrun "Assuming source file #{new_resource.source} would have been created." end end end |
#have_any_matching_version? ⇒ Boolean
188 189 190 |
# File 'lib/chef/provider/package/windows.rb', line 188 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
144 145 146 |
# File 'lib/chef/provider/package/windows.rb', line 144 def install_package(name, version) package_provider.install_package end |
#installer_type ⇒ Object
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 122 123 124 125 126 127 128 129 |
# File 'lib/chef/provider/package/windows.rb', line 81 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.package_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?
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/chef/provider/package/windows.rb', line 53 def load_current_resource @current_resource = Chef::Resource::WindowsPackage.new(new_resource.name) if downloadable_file_missing? logger.trace("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.
153 154 155 156 |
# File 'lib/chef/provider/package/windows.rb', line 153 def new_version_array # Because the one in the parent caches things [new_resource.version] end |
#package_provider ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/chef/provider/package/windows.rb', line 66 def package_provider @package_provider ||= begin case installer_type when :msi logger.trace("#{new_resource} is MSI") require "chef/provider/package/windows/msi" Chef::Provider::Package::Windows::MSI.new(resource_for_provider, uninstall_registry_entries) else logger.trace("#{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
148 149 150 |
# File 'lib/chef/provider/package/windows.rb', line 148 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.
175 176 177 |
# File 'lib/chef/provider/package/windows.rb', line 175 def target_version_already_installed?(current_version, new_version) version_equals?(current_version, new_version) end |
#version_equals?(current_version, new_version) ⇒ Boolean
179 180 181 182 183 184 185 186 |
# File 'lib/chef/provider/package/windows.rb', line 179 def version_equals?(current_version, new_version) logger.trace("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 |