Class: LinuxAdmin::Yum

Inherits:
Object
  • Object
show all
Defined in:
lib/linux_admin/yum.rb,
lib/linux_admin/yum/repo_file.rb

Defined Under Namespace

Classes: RepoFile

Class Method Summary collapse

Class Method Details

.create_repo(path, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/linux_admin/yum.rb', line 6

def self.create_repo(path, options = {})
  raise ArgumentError, "path is required" unless path
  options = {:database => true, :unique_file_names => true}.merge(options)

  FileUtils.mkdir_p(path)

  cmd    = "createrepo"
  params = {nil => path}
  params["--database"]            = nil  if options[:database]
  params["--unique-md-filenames"] = nil  if options[:unique_file_names]

  Common.run!(cmd, :params => params)
end

.download_packages(path, packages, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/linux_admin/yum.rb', line 20

def self.download_packages(path, packages, options = {})
  raise ArgumentError, "path is required"       unless path
  raise ArgumentError, "packages are required"  unless packages
  options = {:mirror_type => :package}.merge(options)

  FileUtils.mkdir_p(path)

  cmd = case options[:mirror_type]
        when :package;  "repotrack"
        else;           raise ArgumentError, "mirror_type unsupported"
        end
  params = {"-p" => path}
  params["-a"]  = options[:arch] if options[:arch]
  params[nil]   = packages

  Common.run!(cmd, :params => params)
end

.repo_list(scope = "enabled") ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/linux_admin/yum.rb', line 80

def self.repo_list(scope = "enabled")
  # Scopes could be "enabled", "all"

  cmd     = "yum repolist"
  params  = {nil => scope}
  output  = Common.run!(cmd, :params => params).output

  parse_repo_list_output(output)
end

.repo_settingsObject



38
39
40
# File 'lib/linux_admin/yum.rb', line 38

def self.repo_settings
  self.parse_repo_dir("/etc/yum.repos.d")
end

.update(*packages) ⇒ Object

Raises:

  • (AwesomeSpawn::CommandResultError)


54
55
56
57
58
59
60
61
62
63
64
# File 'lib/linux_admin/yum.rb', line 54

def self.update(*packages)
  cmd    = "yum -y update"
  params = {nil => packages} unless packages.blank?

  out = Common.run!(cmd, :params => params)

  # Handle errors that exit 0  https://bugzilla.redhat.com/show_bug.cgi?id=1141318
  raise AwesomeSpawn::CommandResultError.new(out.error, out) if out.error.include?("No Match for argument")

  out
end

.updates_available?(*packages) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/linux_admin/yum.rb', line 42

def self.updates_available?(*packages)
  cmd    = "yum check-update"
  params = {nil => packages} unless packages.blank?

  spawn = Common.run(cmd, :params => params)
  case spawn.exit_status
  when 0;   false
  when 100; true
  else raise "Error: #{cmd} returns '#{spawn.exit_status}', '#{spawn.error}'"
  end
end

.version_available(*packages) ⇒ Object

Raises:

  • (ArgumentError)


66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/linux_admin/yum.rb', line 66

def self.version_available(*packages)
  raise ArgumentError, "packages requires at least one package name" if packages.blank?

  cmd    = "repoquery --qf=\"%{name} %{version}\""
  params = {nil => packages}

  out = Common.run!(cmd, :params => params).output

  out.split("\n").each_with_object({}) do |i, versions|
    name, version         = i.split(" ", 2)
    versions[name.strip]  = version.strip
  end
end