@@ -33,7 +33,7 @@ def initialize
3333 when 'suse'
3434 @update_mgmt = SuseUpdateFetcher . new ( inspec )
3535 end
36- return skip_resource 'The `linux_update` resource is not supported on your OS.' if @update_mgmt . nil?
36+ skip_resource 'The `linux_update` resource is not supported on your OS.' if @update_mgmt . nil?
3737 end
3838
3939 def updates
@@ -150,57 +150,57 @@ def extract_xml_updates(updates_el)
150150
151151class UbuntuUpdateFetcher < UpdateFetcher
152152 def packages
153- ubuntu_packages = ubuntu_base + <<-EOH
153+ ubuntu_packages = ubuntu_base + <<-PRINT_JSON
154154echo -n '{"installed":['
155155dpkg-query -W -f='${Status}\\ t${Package}\\ t${Version}\\ t${Architecture}\\ n' |\\
156156 grep '^install ok installed\\ s' |\\
157157 awk '{ printf "{\\ "name\\ ":\\ ""$4"\\ ",\\ "version\\ ":\\ ""$5"\\ ",\\ "arch\\ ":\\ ""$6"\\ "}," }' | rev | cut -c 2- | rev | tr -d '\\ n'
158158echo -n ']}'
159- EOH
159+ PRINT_JSON
160160 parse_json ( ubuntu_packages )
161161 end
162162
163163 def updates
164- ubuntu_updates = ubuntu_base + <<-EOH
164+ ubuntu_updates = ubuntu_base + <<-PRINT_JSON
165165echo -n '{"available":['
166166DEBIAN_FRONTEND=noninteractive apt-get upgrade --dry-run | grep Inst | tr -d '[]()' |\\
167167 awk '{ printf "{\\ "name\\ ":\\ ""$2"\\ ",\\ "version\\ ":\\ ""$4"\\ ",\\ "repo\\ ":\\ ""$5"\\ ",\\ "arch\\ ":\\ ""$6"\\ "}," }' | rev | cut -c 2- | rev | tr -d '\\ n'
168168echo -n ']}'
169- EOH
169+ PRINT_JSON
170170 parse_json ( ubuntu_updates )
171171 end
172172
173173 private
174174
175175 def ubuntu_base
176- base = <<-EOH
177- #!/bin/sh
178- DEBIAN_FRONTEND=noninteractive apt-get update >/dev/null 2>&1
179- readlock() { 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$'; }
180- while test -n "$(readlock)"; do sleep 1; done
181- echo " "
182- EOH
176+ base = <<-PRINT_JSON
177+ #!/bin/sh
178+ DEBIAN_FRONTEND=noninteractive apt-get update >/dev/null 2>&1
179+ readlock() { 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$'; }
180+ while test -n "$(readlock)"; do sleep 1; done
181+ echo " "
182+ PRINT_JSON
183183 base
184184 end
185185end
186186
187187class RHELUpdateFetcher < UpdateFetcher
188188 def packages
189- rhel_packages = <<-EOH
189+ rhel_packages = <<-PRINT_JSON
190190sleep 2 && echo " "
191191echo -n '{"installed":['
192192rpm -qa --queryformat '"name":"%{NAME}","version":"%{VERSION}-%{RELEASE}","arch":"%{ARCH}"\\ n' |\\
193193 awk '{ printf "{"$1"}," }' | rev | cut -c 2- | rev | tr -d '\\ n'
194194echo -n ']}'
195- EOH
195+ PRINT_JSON
196196 parse_json ( rhel_packages )
197197 end
198198
199199 def updates
200- rhel_updates = <<-EOH
200+ rhel_updates = <<-PRINT_JSON
201201#!/bin/sh
202202python -c 'import sys; sys.path.insert(0, "/usr/share/yum-cli"); import cli; list = cli.YumBaseCli().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- EOH
203+ PRINT_JSON
204204 cmd = @inspec . bash ( rhel_updates )
205205 unless cmd . exit_status == 0
206206 # essentially we want https://github.com/chef/inspec/issues/1205
0 commit comments