class Inspec::Resources::Deb

Debian / Ubuntu

def info(package_name)

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',
  }
end