@@ -18,7 +18,7 @@ class LinuxUpdateManager < Inspec.resource(1)
18
18
# if inspec.os.redhat?
19
19
# @update_mgmt = RHELUpdateFetcher.new(inspec)
20
20
# elsif inspec.os.debian?
21
- # @update_mgmt = UbuntuUpdateFetcher .new(inspec)
21
+ # @update_mgmt = DebianUpdateFetcher .new(inspec)
22
22
# end
23
23
# return skip_resource 'The `linux_update` resource is not supported on your OS.' if @update_mgmt.nil?
24
24
# end
@@ -29,7 +29,7 @@ def initialize
29
29
when 'redhat' , 'amazon'
30
30
@update_mgmt = RHELUpdateFetcher . new ( inspec )
31
31
when 'debian'
32
- @update_mgmt = UbuntuUpdateFetcher . new ( inspec )
32
+ @update_mgmt = DebianUpdateFetcher . new ( inspec )
33
33
when 'suse'
34
34
@update_mgmt = SuseUpdateFetcher . new ( inspec )
35
35
end
@@ -156,36 +156,40 @@ def extract_xml_updates(updates_el)
156
156
end
157
157
end
158
158
159
- class UbuntuUpdateFetcher < UpdateFetcher
159
+ class DebianUpdateFetcher < UpdateFetcher
160
160
def packages
161
- ubuntu_packages = ubuntu_base + <<-PRINT_JSON
161
+ debian_packages = debian_base + <<-PRINT_JSON
162
162
echo -n '{"installed":['
163
163
dpkg-query -W -f='${Status}\\ t${Package}\\ t${Version}\\ t${Architecture}\\ n' |\\
164
164
grep '^install ok installed\\ s' |\\
165
165
awk '{ printf "{\\ "name\\ ":\\ ""$4"\\ ",\\ "version\\ ":\\ ""$5"\\ ",\\ "arch\\ ":\\ ""$6"\\ "}," }' | rev | cut -c 2- | rev | tr -d '\\ n'
166
166
echo -n ']}'
167
167
PRINT_JSON
168
- parse_json ( ubuntu_packages )
168
+ parse_json ( debian_packages )
169
169
end
170
170
171
171
def updates
172
- ubuntu_updates = ubuntu_base + <<-PRINT_JSON
172
+ debian_updates = debian_base + <<-PRINT_JSON
173
173
echo -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 '[]()' |\\
175
175
awk '{ printf "{\\ "name\\ ":\\ ""$2"\\ ",\\ "version\\ ":\\ ""$4"\\ ",\\ "repo\\ ":\\ ""$5"\\ ",\\ "arch\\ ":\\ ""$6"\\ "}," }' | rev | cut -c 2- | rev | tr -d '\\ n'
176
176
echo -n ']}'
177
177
PRINT_JSON
178
- parse_json ( ubuntu_updates )
178
+ parse_json ( debian_updates )
179
179
end
180
180
181
181
private
182
182
183
- def ubuntu_base
183
+ def debian_base
184
184
base = <<-PRINT_JSON
185
185
#!/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
189
193
echo " "
190
194
PRINT_JSON
191
195
base
0 commit comments