@@ -38,29 +38,37 @@ def initialize
3838
3939 def updates
4040 return [ ] if @update_mgmt . nil?
41+
4142 u = @update_mgmt . updates
4243 return [ ] if u . nil? || u . empty?
44+
4345 u [ 'available' ]
4446 end
4547
4648 def uptodate?
4749 return nil if @update_mgmt . nil?
50+
4851 u = @update_mgmt . updates
4952 return false if u . nil? || !u [ 'available' ] . empty?
53+
5054 l = @update_mgmt . patches
5155 return false if l . nil? || !l . empty?
56+
5257 true
5358 end
5459
5560 def packages
5661 return [ ] if @update_mgmt . nil?
62+
5763 p = @update_mgmt . packages
5864 return [ ] if p . nil? || p . empty?
65+
5966 p [ 'installed' ]
6067 end
6168
6269 def patches
6370 return [ ] if @update_mgmt . nil?
71+
6472 @update_mgmt . patches || [ ]
6573 end
6674
@@ -156,7 +164,7 @@ def packages
156164 grep '^install ok installed\\ s' |\\
157165 awk '{ printf "{\\ "name\\ ":\\ ""$4"\\ ",\\ "version\\ ":\\ ""$5"\\ ",\\ "arch\\ ":\\ ""$6"\\ "}," }' | rev | cut -c 2- | rev | tr -d '\\ n'
158166echo -n ']}'
159- PRINT_JSON
167+ PRINT_JSON
160168 parse_json ( ubuntu_packages )
161169 end
162170
@@ -166,7 +174,7 @@ def updates
166174DEBIAN_FRONTEND=noninteractive apt-get upgrade --dry-run | grep Inst | tr -d '[]()' |\\
167175 awk '{ printf "{\\ "name\\ ":\\ ""$2"\\ ",\\ "version\\ ":\\ ""$4"\\ ",\\ "repo\\ ":\\ ""$5"\\ ",\\ "arch\\ ":\\ ""$6"\\ "}," }' | rev | cut -c 2- | rev | tr -d '\\ n'
168176echo -n ']}'
169- PRINT_JSON
177+ PRINT_JSON
170178 parse_json ( ubuntu_updates )
171179 end
172180
@@ -179,7 +187,7 @@ def ubuntu_base
179187readlock() { cat /proc/locks | awk '{print $5}' | grep -v ^0 | xargs -I {1} find /proc/{1}/fd -maxdepth 1 -exec readlink {} \\ ; | grep '^/var/lib/dpkg/lock$'; }
180188while test -n "$(readlock)"; do sleep 1; done
181189echo " "
182- PRINT_JSON
190+ PRINT_JSON
183191 base
184192 end
185193end
@@ -192,15 +200,15 @@ def packages
192200rpm -qa --queryformat '"name":"%{NAME}","version":"%{VERSION}-%{RELEASE}","arch":"%{ARCH}"\\ n' |\\
193201 awk '{ printf "{"$1"}," }' | rev | cut -c 2- | rev | tr -d '\\ n'
194202echo -n ']}'
195- PRINT_JSON
203+ PRINT_JSON
196204 parse_json ( rhel_packages )
197205 end
198206
199207 def updates
200208 rhel_updates = <<-PRINT_JSON
201209#!/bin/sh
202210python -c 'import sys; sys.path.insert(0, "/usr/share/yum-cli"); import cli; ybc = cli.YumBaseCli(); ybc.setCacheDir("/tmp"); list = ybc.returnPkgLists(["updates"]);res = ["{\\ "name\\ ":\\ ""+x.name+"\\ ", \\ "version\\ ":\\ ""+x.version+"-"+x.release+"\\ ",\\ "arch\\ ":\\ ""+x.arch+"\\ ",\\ "repository\\ ":\\ ""+x.repo.id+"\\ "}" for x in list.updates]; print "{\\ "available\\ ":["+",".join(res)+"]}"'
203- PRINT_JSON
211+ PRINT_JSON
204212 cmd = @inspec . bash ( rhel_updates )
205213 unless cmd . exit_status == 0
206214 # essentially we want https://github.com/chef/inspec/issues/1205
0 commit comments