forked from evolvingweb/puppet-apt
-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #581 from robinelfrink/master
Make apt_updates facts use /usr/bin/apt-get.
- Loading branch information
Showing
5 changed files
with
55 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,57 @@ | ||
apt_package_updates = nil | ||
Facter.add("apt_has_updates") do | ||
confine :osfamily => 'Debian' | ||
if File.executable?("/usr/lib/update-notifier/apt-check") | ||
apt_check_result = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check 2>&1') | ||
if not apt_check_result.nil? and apt_check_result =~ /^\d+;\d+$/ | ||
apt_package_updates = apt_check_result.split(';') | ||
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 | ||
end | ||
end | ||
|
||
setcode do | ||
if not apt_package_updates.nil? and apt_package_updates.length == 2 | ||
apt_package_updates != ['0', '0'] | ||
apt_package_updates != [[], []] | ||
end | ||
end | ||
end | ||
|
||
Facter.add("apt_package_updates") do | ||
confine :apt_has_updates => true | ||
setcode do | ||
packages = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check -p 2>&1').split("\n") | ||
if Facter.version < '2.0.0' | ||
packages.join(',') | ||
apt_package_updates[0].join(',') | ||
else | ||
packages | ||
apt_package_updates[0] | ||
end | ||
end | ||
end | ||
|
||
Facter.add("apt_updates") do | ||
confine :apt_has_updates => true | ||
setcode do | ||
Integer(apt_package_updates[0]) | ||
Integer(apt_package_updates[0].length) | ||
end | ||
end | ||
|
||
Facter.add("apt_security_updates") do | ||
confine :apt_has_updates => true | ||
setcode do | ||
Integer(apt_package_updates[1]) | ||
Integer(apt_package_updates[1].length) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters