Class: Chef::Provider::Package::Freebsd
- Inherits:
-
Chef::Provider::Package
- Object
- Chef::Provider
- Chef::Provider::Package
- Chef::Provider::Package::Freebsd
- Defined in:
- lib/chef/provider/package/freebsd.rb
Instance Attribute Summary
Attributes inherited from Chef::Provider::Package
Attributes inherited from Chef::Provider
#current_resource, #new_resource, #node
Instance Method Summary collapse
- #current_installed_version ⇒ Object
-
#initialize(*args) ⇒ Freebsd
constructor
A new instance of Freebsd.
- #install_package(name, version) ⇒ Object
- #latest_link_name ⇒ Object
- #load_current_resource ⇒ Object
-
#package_name ⇒ Object
The name of the package (without the version number) as understood by pkg_add and pkg_info.
- #port_path ⇒ Object
- #ports_candidate_version ⇒ Object
- #ports_makefile_variable_value(variable) ⇒ Object
- #remove_package(name, version) ⇒ Object
Methods inherited from Chef::Provider::Package
#action_install, #action_purge, #action_remove, #action_upgrade, #expand_options, #get_preseed_file, #preseed_package, #purge_package, #should_remove_package, #upgrade_package
Methods included from Mixin::Command
chdir_or_tmpdir, handle_command_failures, not_if, only_if, output_of_command, popen4, run_command, run_command_with_systems_locale
Methods inherited from Chef::Provider
#action_nothing, build_from_file
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Methods included from Mixin::RecipeDefinitionDSLCore
Methods included from Mixin::Language
#data_bag, #data_bag_item, #platform?, #search, #value_for_platform
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore
Instance Method Details
#current_installed_version ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chef/provider/package/freebsd.rb', line 34 def current_installed_version command = "pkg_info -E \"#{package_name}*\"" status = popen4(command) do |pid, stdin, stdout, stderr| stdout.each do |line| case line when /^#{package_name}-(.+)/ return $1 end end end unless status.exitstatus == 0 || status.exitstatus == 1 raise Chef::Exceptions::Package, "#{command} failed - #{status.inspect}!" end nil end |
#install_package(name, version) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/chef/provider/package/freebsd.rb', line 113 def install_package(name, version) unless @current_resource.version case @new_resource.source when /^ports$/ run_command_with_systems_locale( :command => "make -DBATCH install", :cwd => "#{port_path}" ) when /^http/, /^ftp/ run_command_with_systems_locale( :command => "pkg_add -r #{package_name}", :environment => { "PACKAGESITE" => @new_resource.source } ) Chef::Log.info("Installed package #{package_name} from: #{@new_resource.source}") when /^\// run_command_with_systems_locale( :command => "pkg_add #{@new_resource.name}", :environment => { "PKG_PATH" => @new_resource.source } ) Chef::Log.info("Installed package #{@new_resource.name} from: #{@new_resource.source}") else run_command_with_systems_locale( :command => "pkg_add -r #{latest_link_name}" ) Chef::Log.info("Installed package #{package_name}") end end end |
#latest_link_name ⇒ Object
100 101 102 |
# File 'lib/chef/provider/package/freebsd.rb', line 100 def latest_link_name ports_makefile_variable_value("LATEST_LINK") end |
#load_current_resource ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/chef/provider/package/freebsd.rb', line 88 def load_current_resource @current_resource.package_name(@new_resource.package_name) @current_resource.version(current_installed_version) Chef::Log.debug("Current version is #{@current_resource.version}") if @current_resource.version @candidate_version = ports_candidate_version Chef::Log.debug("Ports candidate version is #{@candidate_version}") if @candidate_version @current_resource end |
#package_name ⇒ Object
The name of the package (without the version number) as understood by pkg_add and pkg_info
105 106 107 108 109 110 111 |
# File 'lib/chef/provider/package/freebsd.rb', line 105 def package_name if ports_makefile_variable_value("PKGNAME") =~ /^(.+)-[^-]+$/ $1 else raise Chef::Exceptions::Package, "Unexpected form for PKGNAME variable in #{port_path}/Makefile" end end |
#port_path ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/chef/provider/package/freebsd.rb', line 50 def port_path case @new_resource.package_name # When the package name starts with a '/' treat it as the full path to the ports directory when /^\// @new_resource.package_name # Otherwise if the package name contains a '/' not at the start (like 'www/wordpress') treat as a relative # path from /usr/ports when /\// "/usr/ports/#{@new_resource.package_name}" # Otherwise look up the path to the ports directory using 'whereis' else popen4("whereis -s #{@new_resource.package_name}") do |pid, stdin, stdout, stderr| stdout.each do |line| case line when /^#{@new_resource.package_name}:\s+(.+)$/ return $1 end end end raise Chef::Exceptions::Package, "Could not find port with the name #{@new_resource.package_name}" end end |
#ports_candidate_version ⇒ Object
84 85 86 |
# File 'lib/chef/provider/package/freebsd.rb', line 84 def ports_candidate_version ports_makefile_variable_value("PORTVERSION") end |
#ports_makefile_variable_value(variable) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/chef/provider/package/freebsd.rb', line 73 def ports_makefile_variable_value(variable) command = "cd #{port_path}; make -V #{variable}" status = popen4(command) do |pid, stdin, stdout, stderr| return stdout.readline.strip end unless status.exitstatus == 0 || status.exitstatus == 1 raise Chef::Exceptions::Package, "#{command} failed - #{status.inspect}!" end nil end |
#remove_package(name, version) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/chef/provider/package/freebsd.rb', line 142 def remove_package(name, version) # a version is mandatory if version run_command_with_systems_locale( :command => "pkg_delete #{package_name}-#{version}" ) else run_command_with_systems_locale( :command => "pkg_delete #{package_name}-#{@current_resource.version}" ) end end |