Class: Chef::Provider::Package::Apt
Constant Summary
Mixin::ShellOut::DEPRECATED_OPTIONS
Instance Attribute Summary collapse
#candidate_version
#action, #cookbook_name, #current_resource, #new_resource, #recipe_name, #run_context
Instance Method Summary
collapse
#action_install, #action_purge, #action_reconfig, #action_remove, #action_upgrade, #expand_options, #get_preseed_file, #initialize, #preseed_resource, #removing_package?, #target_version_already_installed?, #whyrun_supported?
#chdir_or_tmpdir, #handle_command_failures, #output_of_command, #run_command, #run_command_and_return_stdout_stderr, #run_command_with_systems_locale
#popen4
#popen4
#action_nothing, #cleanup_after_converge, #converge_by, #events, #initialize, #node, node_map, #process_resource_requirements, provides, provides?, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, supports?, #whyrun_mode?, #whyrun_supported?
#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited
#run_command_compatible_options, #shell_out, #shell_out!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!
Instance Attribute Details
#is_virtual_package ⇒ Object
Returns the value of attribute is_virtual_package.
30
31
32
|
# File 'lib/chef/provider/package/apt.rb', line 30
def is_virtual_package
@is_virtual_package
end
|
Instance Method Details
#check_package_state(package) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
|
# File 'lib/chef/provider/package/apt.rb', line 53
def check_package_state(package)
Chef::Log.debug("#{@new_resource} checking package status for #{package}")
installed = false
shell_out!("apt-cache#{expand_options(default_release_options)} policy #{package}", :timeout => @new_resource.timeout).stdout.each_line do |line|
case line
when /^\s{2}Installed: (.+)$/
installed_version = $1
if installed_version == '(none)'
Chef::Log.debug("#{@new_resource} current version is nil")
@current_resource.version(nil)
else
Chef::Log.debug("#{@new_resource} current version is #{installed_version}")
@current_resource.version(installed_version)
installed = true
end
when /^\s{2}Candidate: (.+)$/
candidate_version = $1
if candidate_version == '(none)'
@is_virtual_package = true
showpkg = shell_out!("apt-cache showpkg #{package}", :timeout => @new_resource.timeout).stdout
providers = Hash.new
showpkg.rpartition(/Reverse Provides:\s*#{$/}/)[2].each_line do |line|
provider, version = line.split
providers[provider] = version
end
num_providers = providers.length
raise Chef::Exceptions::Package, "#{@new_resource.package_name} has no candidate in the apt-cache" if num_providers == 0
raise Chef::Exceptions::Package, "#{@new_resource.package_name} is a virtual package provided by #{num_providers} packages, you must explicitly select one to install" if num_providers > 1
Chef::Log.info("#{@new_resource} is a virtual package, actually acting on package[#{providers.keys.first}]")
installed = check_package_state(providers.keys.first)
else
Chef::Log.debug("#{@new_resource} candidate version is #{$1}")
@candidate_version = $1
end
end
end
return installed
end
|
#default_release_options ⇒ Object
48
49
50
51
|
# File 'lib/chef/provider/package/apt.rb', line 48
def default_release_options
"-o APT::Default-Release=#{@new_resource.default_release}" if @new_resource.provider && @new_resource.default_release
end
|
#define_resource_requirements ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/chef/provider/package/apt.rb', line 39
def define_resource_requirements
super
requirements.assert(:all_actions) do |a|
a.assertion { !@new_resource.source }
a.failure_message(Chef::Exceptions::Package, 'apt package provider cannot handle source attribute. Use dpkg provider instead')
end
end
|
#install_package(name, version) ⇒ Object
99
100
101
102
103
|
# File 'lib/chef/provider/package/apt.rb', line 99
def install_package(name, version)
package_name = "#{name}=#{version}"
package_name = name if @is_virtual_package
run_noninteractive("apt-get -q -y#{expand_options(default_release_options)}#{expand_options(@new_resource.options)} install #{package_name}")
end
|
#load_current_resource ⇒ Object
32
33
34
35
36
37
|
# File 'lib/chef/provider/package/apt.rb', line 32
def load_current_resource
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@current_resource.package_name(@new_resource.package_name)
check_package_state(@new_resource.package_name)
@current_resource
end
|
#preseed_package(preseed_file) ⇒ Object
118
119
120
121
|
# File 'lib/chef/provider/package/apt.rb', line 118
def preseed_package(preseed_file)
Chef::Log.info("#{@new_resource} pre-seeding package installation instructions")
run_noninteractive("debconf-set-selections #{preseed_file}")
end
|
#purge_package(name, version) ⇒ Object
114
115
116
|
# File 'lib/chef/provider/package/apt.rb', line 114
def purge_package(name, version)
run_noninteractive("apt-get -q -y#{expand_options(@new_resource.options)} purge #{@new_resource.package_name}")
end
|
#reconfig_package(name, version) ⇒ Object
123
124
125
126
|
# File 'lib/chef/provider/package/apt.rb', line 123
def reconfig_package(name, version)
Chef::Log.info("#{@new_resource} reconfiguring")
run_noninteractive("dpkg-reconfigure #{name}")
end
|
#remove_package(name, version) ⇒ Object
109
110
111
112
|
# File 'lib/chef/provider/package/apt.rb', line 109
def remove_package(name, version)
package_name = "#{name}"
run_noninteractive("apt-get -q -y#{expand_options(@new_resource.options)} remove #{package_name}")
end
|
#upgrade_package(name, version) ⇒ Object
105
106
107
|
# File 'lib/chef/provider/package/apt.rb', line 105
def upgrade_package(name, version)
install_package(name, version)
end
|