@@ -18,7 +18,7 @@ class LinuxUpdateManager < Inspec.resource(1)
1818 # if inspec.os.redhat?
1919 # @update_mgmt = RHELUpdateFetcher.new(inspec)
2020 # elsif inspec.os.debian?
21- # @update_mgmt = UbuntuUpdateFetcher .new(inspec)
21+ # @update_mgmt = DebianUpdateFetcher .new(inspec)
2222 # end
2323 # return skip_resource 'The `linux_update` resource is not supported on your OS.' if @update_mgmt.nil?
2424 # end
@@ -29,7 +29,7 @@ def initialize
2929 when 'redhat' , 'amazon'
3030 @update_mgmt = RHELUpdateFetcher . new ( inspec )
3131 when 'debian'
32- @update_mgmt = UbuntuUpdateFetcher . new ( inspec )
32+ @update_mgmt = DebianUpdateFetcher . new ( inspec )
3333 when 'suse'
3434 @update_mgmt = SuseUpdateFetcher . new ( inspec )
3535 end
@@ -156,36 +156,40 @@ def extract_xml_updates(updates_el)
156156 end
157157end
158158
159- class UbuntuUpdateFetcher < UpdateFetcher
159+ class DebianUpdateFetcher < UpdateFetcher
160160 def packages
161- ubuntu_packages = ubuntu_base + <<-PRINT_JSON
161+ debian_packages = debian_base + <<-PRINT_JSON
162162echo -n '{"installed":['
163163dpkg-query -W -f='${Status}\\ t${Package}\\ t${Version}\\ t${Architecture}\\ n' |\\
164164 grep '^install ok installed\\ s' |\\
165165 awk '{ printf "{\\ "name\\ ":\\ ""$4"\\ ",\\ "version\\ ":\\ ""$5"\\ ",\\ "arch\\ ":\\ ""$6"\\ "}," }' | rev | cut -c 2- | rev | tr -d '\\ n'
166166echo -n ']}'
167167 PRINT_JSON
168- parse_json ( ubuntu_packages )
168+ parse_json ( debian_packages )
169169 end
170170
171171 def updates
172- ubuntu_updates = ubuntu_base + <<-PRINT_JSON
172+ debian_updates = debian_base + <<-PRINT_JSON
173173echo -n '{"available":['
174- DEBIAN_FRONTEND=noninteractive apt-get upgrade --dry-run | grep Inst | tr -d '[]()' |\\
174+ DEBIAN_FRONTEND=noninteractive apt upgrade --dry-run | grep Inst | tr -d '[]()' |\\
175175 awk '{ printf "{\\ "name\\ ":\\ ""$2"\\ ",\\ "version\\ ":\\ ""$4"\\ ",\\ "repo\\ ":\\ ""$5"\\ ",\\ "arch\\ ":\\ ""$6"\\ "}," }' | rev | cut -c 2- | rev | tr -d '\\ n'
176176echo -n ']}'
177177 PRINT_JSON
178- parse_json ( ubuntu_updates )
178+ parse_json ( debian_updates )
179179 end
180180
181181 private
182182
183- def ubuntu_base
183+ def debian_base
184184 base = <<-PRINT_JSON
185185#!/bin/sh
186- DEBIAN_FRONTEND=noninteractive apt-get update >/dev/null 2>&1
187- 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$'; }
188- while test -n "$(readlock)"; do sleep 1; done
186+ COMMAND="DEBIAN_FRONTEND=noninteractive apt update >>/dev/null 2>&1"
187+ eval $COMMAND
188+ while [ $? -ne 0 ]
189+ do
190+ sleep 30s
191+ eval $COMMAND
192+ done
189193echo " "
190194 PRINT_JSON
191195 base
0 commit comments