Class: Knife::Pkg::AptPackageController
Constant Summary
PackageController::ONE_DAY_IN_SECS
Instance Attribute Summary
#node, #options, #session, #ui
Instance Method Summary
collapse
available_updates, #exec, init_controller, list_available_updates, #max_pkg_cache_age, platform_family_by_local_ohai, #sudo, #try_update_pkg_cache, ui, update!, #update_dialog, #update_info, #update_package_verbose!
Constructor Details
Returns a new instance of AptPackageController.
23
24
25
26
|
# File 'lib/knife-pkg/controllers/apt.rb', line 23
def initialize(node, session, opts = {})
super(node, session, opts)
@installed_packages = Array.new
end
|
Instance Method Details
#available_updates ⇒ Object
63
64
65
|
# File 'lib/knife-pkg/controllers/apt.rb', line 63
def available_updates
parse_upgrade(exec("#{sudo} apt-get dist-upgrade -V -s | egrep -v \"^(Conf|Inst)\"").stdout)
end
|
#dry_run_supported? ⇒ Boolean
28
29
30
|
# File 'lib/knife-pkg/controllers/apt.rb', line 28
def dry_run_supported?
true
end
|
#installed_version(package) ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/knife-pkg/controllers/apt.rb', line 48
def installed_version(package)
package = @installed_packages.select { |p| p.name == package.name }.first || Package.new("")
if !package.name.empty?
version = package.version
else
version = exec("dpkg -p #{package.name} | grep -i Version: | awk '{print $2}' | head -1").stdout.chomp
end
version
end
|
#last_pkg_cache_update ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/knife-pkg/controllers/apt.rb', line 36
def last_pkg_cache_update
result = nil
begin
result = exec("#{sudo} stat -c %y /var/lib/apt/lists")
Time.parse(result.stdout.chomp)
rescue RuntimeError => e
e.backtrace.each { |l| Chef::Log.debug(l) }
Chef::Log.warn(e.message)
Time.now - (max_pkg_cache_age + 100)
end
end
|
#parse_upgrade(upgrade_line) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/knife-pkg/controllers/apt.rb', line 67
def parse_upgrade(upgrade_line)
result = Array.new
rx = Regexp.new(/\s+(?<name>\S+)\s\((?<installed>.+)\s=>\s(?<new>.+)\)/)
found = false
upgrade_line.split("\n").each do |line|
unless found
found = true if line.match(/will be upgraded/)
next
end
match = rx.match(line)
unless match.nil?
result << Package.new(match[:name], match[:new])
@installed_packages << Package.new(match[:name], match[:installed])
end
end
result
end
|
#update_package!(package) ⇒ Object
85
86
87
88
89
|
# File 'lib/knife-pkg/controllers/apt.rb', line 85
def update_package!(package)
cmd_string = "#{sudo} DEBIAN_FRONTEND=noninteractive apt-get install #{package.name} -y -o Dpkg::Options::='--force-confold'"
cmd_string += " -s" if @options[:dry_run]
exec(cmd_string)
end
|
#update_pkg_cache ⇒ Object
32
33
34
|
# File 'lib/knife-pkg/controllers/apt.rb', line 32
def update_pkg_cache
exec("#{sudo}apt-get update")
end
|
#update_version(package) ⇒ Object
59
60
61
|
# File 'lib/knife-pkg/controllers/apt.rb', line 59
def update_version(package)
exec("#{sudo} apt-cache policy #{package.name} | grep Candidate | awk '{print $2}'").stdout.chomp
end
|