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



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/inspec/resources/package.rb', line 114

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