Class: Chef::Provider::Package::Freebsd
Constant Summary
Mixin::ShellOut::DEPRECATED_OPTIONS
Instance Attribute Summary
#candidate_version
#action, #current_resource, #new_resource, #run_context
Instance Method Summary
collapse
#run_command_compatible_options, #shell_out, #shell_out!
#action_install, #action_purge, #action_reconfig, #action_remove, #action_upgrade, #define_resource_requirements, #expand_options, #get_preseed_file, #preseed_package, #preseed_resource, #purge_package, #reconfig_package, #removing_package?, #target_version_already_installed?, #upgrade_package, #whyrun_supported?
#chdir_or_tmpdir, #handle_command_failures, #output_of_command, #run_command, #run_command_with_systems_locale
#popen4
#popen4
#action_nothing, #cleanup_after_converge, #cookbook_name, #define_resource_requirements, #events, #node, #process_resource_requirements, #requirements, #resource_collection, #run_action, #set_updated_status, #whyrun_mode?, #whyrun_supported?
#method_missing
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Constructor Details
#initialize(*args) ⇒ Freebsd
33
34
35
36
|
# File 'lib/chef/provider/package/freebsd.rb', line 33
def initialize(*args)
super
@current_resource = Chef::Resource::Package.new(@new_resource.name)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Chef::DSL::Recipe
Instance Method Details
#current_installed_version ⇒ Object
38
39
40
41
|
# File 'lib/chef/provider/package/freebsd.rb', line 38
def current_installed_version
pkg_info = shell_out!("pkg_info -E \"#{package_name}*\"", :env => nil, :returns => [0,1])
pkg_info.stdout[/^#{package_name}-(.+)/, 1]
end
|
#file_candidate_version ⇒ Object
75
76
77
|
# File 'lib/chef/provider/package/freebsd.rb', line 75
def file_candidate_version
file_candidate_version_path.split(/-/).last.split(/.tbz/).first
end
|
#file_candidate_version_path ⇒ Object
71
72
73
|
# File 'lib/chef/provider/package/freebsd.rb', line 71
def file_candidate_version_path
Dir["#{@new_resource.source}/#{@current_resource.package_name}*"][-1].to_s
end
|
#install_package(name, version) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/chef/provider/package/freebsd.rb', line 116
def install_package(name, version)
unless @current_resource.version
case @new_resource.source
when /^ports$/
shell_out!("make -DBATCH install", :timeout => 1200, :env => nil, :cwd => port_path).status
when /^http/, /^ftp/
if @new_resource.source =~ /\/$/
shell_out!("pkg_add -r #{package_name}", :env => { "PACKAGESITE" => @new_resource.source, 'LC_ALL' => nil }).status
else
shell_out!("pkg_add -r #{package_name}", :env => { "PACKAGEROOT" => @new_resource.source, 'LC_ALL' => nil }).status
end
Chef::Log.debug("#{@new_resource} installed from: #{@new_resource.source}")
when /^\//
shell_out!("pkg_add #{file_candidate_version_path}", :env => { "PKG_PATH" => @new_resource.source , 'LC_ALL'=>nil}).status
Chef::Log.debug("#{@new_resource} installed from: #{@new_resource.source}")
else
shell_out!("pkg_add -r #{latest_link_name}", :env => nil).status
end
end
end
|
#latest_link_name ⇒ Object
99
100
101
|
# File 'lib/chef/provider/package/freebsd.rb', line 99
def latest_link_name
ports_makefile_variable_value("LATEST_LINK")
end
|
#load_current_resource ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/chef/provider/package/freebsd.rb', line 79
def load_current_resource
@current_resource.package_name(@new_resource.package_name)
@current_resource.version(current_installed_version)
Chef::Log.debug("#{@new_resource} current version is #{@current_resource.version}") if @current_resource.version
case @new_resource.source
when /^http/, /^ftp/
@candidate_version = "0.0.0"
when /^\//
@candidate_version = file_candidate_version
else
@candidate_version = ports_candidate_version
end
Chef::Log.debug("#{@new_resource} 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
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/chef/provider/package/freebsd.rb', line 104
def package_name
if ::File.exist?("/usr/ports/Makefile")
if ports_makefile_variable_value("PKGNAME") =~ /^(.+)-[^-]+$/
$1
else
raise Chef::Exceptions::Package, "Unexpected form for PKGNAME variable in #{port_path}/Makefile"
end
else
@new_resource.package_name
end
end
|
#port_path ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/chef/provider/package/freebsd.rb', line 43
def port_path
case @new_resource.package_name
when /^\//
@new_resource.package_name
when /\//
"/usr/ports/#{@new_resource.package_name}"
else
whereis = shell_out!("whereis -s #{@new_resource.package_name}", :env => nil)
unless path = whereis.stdout[/^#{@new_resource.package_name}:\s+(.+)$/, 1]
raise Chef::Exceptions::Package, "Could not find port with the name #{@new_resource.package_name}"
end
path
end
end
|
#ports_candidate_version ⇒ Object
67
68
69
|
# File 'lib/chef/provider/package/freebsd.rb', line 67
def ports_candidate_version
ports_makefile_variable_value("PORTVERSION")
end
|
#ports_makefile_variable_value(variable) ⇒ Object
62
63
64
65
|
# File 'lib/chef/provider/package/freebsd.rb', line 62
def ports_makefile_variable_value(variable)
make_v = shell_out!("make -V #{variable}", :cwd => port_path, :env => nil, :returns => [0,1])
make_v.stdout.strip.split($\).first
end
|
#remove_package(name, version) ⇒ Object
137
138
139
140
141
142
143
144
|
# File 'lib/chef/provider/package/freebsd.rb', line 137
def remove_package(name, version)
if version
shell_out!("pkg_delete #{package_name}-#{version}", :env => nil).status
else
shell_out!("pkg_delete #{package_name}-#{@current_resource.version}", :env => nil).status
end
end
|