Sha256: 1a2dde5bcb33bc9dbceca2a64ae77e15f24c6166651d833b5b51418df504f8f1

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

module LinuxAdmin
  class Rpm < Package
    extend Logging

    def self.rpm_cmd
      Distros.local.command(: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)
      logger.info("#{self.class.name}##{__method__} Importing RPM-GPG-KEY: #{file}")
      run!("rpm", :params => {"--import" => file})
    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

3 entries across 3 versions & 1 rubygems

Version Path
linux_admin-0.11.1 lib/linux_admin/rpm.rb
linux_admin-0.11.0 lib/linux_admin/rpm.rb
linux_admin-0.10.1 lib/linux_admin/rpm.rb