Class: Inspec::Resources::Deb

Inherits:
PkgManagement show all
Defined in:
lib/inspec/resources/package.rb

Overview

Debian / Ubuntu

Instance Attribute Summary

Attributes inherited from PkgManagement

#inspec

Instance Method Summary collapse

Methods inherited from PkgManagement

#initialize, #missing_requirements

Constructor Details

This class inherits a constructor from Inspec::Resources::PkgManagement

Instance Method Details

#info(package_name) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/inspec/resources/package.rb', line 147

def info(package_name)
  cmd = inspec.command("dpkg -s #{package_name}")
  return {} if cmd.exit_status.to_i != 0

  params = SimpleConfig.new(
    cmd.stdout.chomp,
    assignment_regex: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
    multiple_values: false
  ).params
  # If the package is installed, Status is "install ok installed"
  # If the package is installed and marked hold, Status is "hold ok installed"
  # If the package is removed and not purged, Status is "deinstall ok config-files" with exit_status 0
  # If the package is purged cmd fails with non-zero exit status

  {
    name: params["Package"],
    installed: params["Status"].split(" ")[2] == "installed",
    held: params["Status"].split(" ")[0] == "hold",
    version: params["Version"],
    type: "deb",
    only_version_no: fetch_version_no(params["Version"]),
  }
end

#latest_version(package_name) ⇒ Object



171
172
173
174
# File 'lib/inspec/resources/package.rb', line 171

def latest_version(package_name)
  cmd_string = "apt list #{package_name} -a"
  fetch_latest_version(cmd_string)
end