Class: LinuxAdmin::Rpm

Inherits:
Package show all
Defined in:
lib/linux_admin/rpm.rb

Constant Summary collapse

RPM_CMD =
'/usr/bin/rpm'

Constants inherited from LinuxAdmin

VERSION

Class Method Summary collapse

Methods included from Common

#cmd, #run, #run!

Class Method Details

.info(pkg) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/linux_admin/rpm.rb', line 13

def self.info(pkg)
  params = { "-qi" => pkg}
  in_description = false
  out = run!(RPM_CMD, :params => params).output
  out.split("\n").each.with_object({}) do |line, rpm|
    tag,value = line.split(':')
    tag = tag.strip
    if tag == 'Description'
      in_description = true
    elsif in_description
      rpm['description'] ||= ""
      rpm['description'] << line + " "
    else
      tag = tag.downcase.gsub(/\s/, '_')
      rpm[tag] = value.strip
    end
  end
end

.list_installedObject



5
6
7
8
9
10
11
# File 'lib/linux_admin/rpm.rb', line 5

def self.list_installed
  out = run!("rpm -qa --qf \"%{NAME} %{VERSION}-%{RELEASE}\n\"").output
  out.split("\n").each_with_object({}) do |line, pkg_hash|
    name, ver = line.split(" ")
    pkg_hash[name] = ver
  end
end

.upgrade(pkg) ⇒ Object



32
33
34
35
36
37
# File 'lib/linux_admin/rpm.rb', line 32

def self.upgrade(pkg)
  cmd     = "rpm -U"
  params  = { nil => pkg }

  run(cmd, :params => params).exit_status == 0
end