2014-10-15 15:44:50 +02:00
|
|
|
apt_package_updates = nil
|
|
|
|
Facter.add("apt_has_updates") do
|
2014-06-26 15:50:11 +02:00
|
|
|
confine :osfamily => 'Debian'
|
2016-02-12 23:21:28 +01:00
|
|
|
if File.executable?("/usr/bin/apt-get")
|
|
|
|
apt_get_result = Facter::Util::Resolution.exec('/usr/bin/apt-get -s upgrade 2>&1')
|
|
|
|
if not apt_get_result.nil?
|
|
|
|
apt_package_updates = [[], []]
|
|
|
|
apt_get_result.each_line do |line|
|
|
|
|
if line =~ /^Inst\s/
|
|
|
|
package = line.gsub(/^Inst\s([^\s]+)\s.*/, '\1').strip
|
|
|
|
apt_package_updates[0].push(package)
|
|
|
|
security_matches = [
|
|
|
|
/ Debian[^\s]+-updates /,
|
|
|
|
/ Debian-Security:/,
|
|
|
|
/ Ubuntu[^\s]+-security /,
|
|
|
|
/ gNewSense[^\s]+-security /
|
|
|
|
]
|
|
|
|
re = Regexp.union(security_matches)
|
|
|
|
if line.match(re)
|
|
|
|
apt_package_updates[1].push(package)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-01-08 06:45:43 +01:00
|
|
|
end
|
2014-10-15 15:44:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
setcode do
|
2015-01-08 06:45:43 +01:00
|
|
|
if not apt_package_updates.nil? and apt_package_updates.length == 2
|
2016-02-12 23:21:28 +01:00
|
|
|
apt_package_updates != [[], []]
|
2015-01-08 06:45:43 +01:00
|
|
|
end
|
2014-10-15 15:44:50 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Facter.add("apt_package_updates") do
|
|
|
|
confine :apt_has_updates => true
|
2014-06-26 15:50:11 +02:00
|
|
|
setcode do
|
2014-10-15 15:44:50 +02:00
|
|
|
if Facter.version < '2.0.0'
|
2016-02-12 23:21:28 +01:00
|
|
|
apt_package_updates[0].join(',')
|
2014-10-15 15:44:50 +02:00
|
|
|
else
|
2016-02-12 23:21:28 +01:00
|
|
|
apt_package_updates[0]
|
2014-06-26 15:50:11 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-10-15 15:44:50 +02:00
|
|
|
|
|
|
|
Facter.add("apt_updates") do
|
|
|
|
confine :apt_has_updates => true
|
|
|
|
setcode do
|
2016-02-12 23:21:28 +01:00
|
|
|
Integer(apt_package_updates[0].length)
|
2014-10-15 15:44:50 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Facter.add("apt_security_updates") do
|
|
|
|
confine :apt_has_updates => true
|
|
|
|
setcode do
|
2016-02-12 23:21:28 +01:00
|
|
|
Integer(apt_package_updates[1].length)
|
2014-10-15 15:44:50 +02:00
|
|
|
end
|
|
|
|
end
|