Class: LinuxAdmin::Rpm
- Inherits:
-
Package
- Object
- LinuxAdmin
- Package
- LinuxAdmin::Rpm
- Defined in:
- lib/linux_admin/rpm.rb
Constant Summary
Constants inherited from LinuxAdmin
Class Method Summary collapse
-
.import_key(file) ⇒ Object
Import a GPG file for use with RPM.
- .info(pkg) ⇒ Object
- .list_installed ⇒ Object
- .rpm_cmd ⇒ Object
- .upgrade(pkg) ⇒ Object
Methods included from Common
Class Method Details
.import_key(file) ⇒ Object
Import a GPG file for use with RPM
Rpm.import_key("/etc/pki/my-gpg-key")
18 19 20 21 |
# File 'lib/linux_admin/rpm.rb', line 18 def self.import_key(file) params = {"--import" => file} run!("rpm", :params => params) end |
.info(pkg) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/linux_admin/rpm.rb', line 23 def self.info(pkg) params = { "-qi" => pkg} in_description = false out = run!(rpm_cmd, :params => params).output # older versions of rpm may have multiple fields per line, # split up lines with multiple tags/values: out.gsub!(/(^.*:.*)\s\s+(.*:.*)$/, "\\1\n\\2") out.split("\n").each.with_object({}) do |line, rpm| next if !line || line.empty? 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_installed ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/linux_admin/rpm.rb', line 7 def self.list_installed out = run!("#{rpm_cmd} -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 |
.rpm_cmd ⇒ Object
3 4 5 |
# File 'lib/linux_admin/rpm.rb', line 3 def self.rpm_cmd Distros.local.command(:rpm) end |
.upgrade(pkg) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/linux_admin/rpm.rb', line 46 def self.upgrade(pkg) cmd = "rpm -U" params = { nil => pkg } run(cmd, :params => params).exit_status == 0 end |