Sha256: c77ffe484f15f8208995998764c2ddf7afc9be06d03432cb6c705d5937f0236f

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

class LinuxAdmin
  class Rpm < Package
    def self.rpm_cmd
      Distros::Distro.local.class::COMMANDS[:rpm]
    end

    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

    # Import a GPG file for use with RPM
    #
    #   Rpm.import_key("/etc/pki/my-gpg-key")
    def self.import_key(file)
      params = {"--import" => file}
      run!("rpm", :params => params)
    end

    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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
linux_admin-0.8.1 lib/linux_admin/rpm.rb