Class: RepoMgr::Backend::Rpm

Inherits:
Object
  • Object
show all
Defined in:
lib/repo_mgr/backends/rpm.rb

Overview

rpm backend handler

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Rpm

Returns a new instance of Rpm.



16
17
18
# File 'lib/repo_mgr/backends/rpm.rb', line 16

def initialize(config)
  @config = config
end

Instance Method Details

#add_pkg(repo, pkg) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/repo_mgr/backends/rpm.rb', line 23

def add_pkg(repo, pkg)
  sign_pkg repo, pkg

  arch = extract_arch pkg
  dest_dir = "#{@config.cfg_dir}/rpms/#{repo}/#{arch}"

  FileUtils.mkdir_p dest_dir
  FileUtils.cp pkg, dest_dir

  sync_repo repo
end

#add_repo(_name) ⇒ Object

this is managed from RepoMgr::Config



21
# File 'lib/repo_mgr/backends/rpm.rb', line 21

def add_repo(_name); end

#check_sig(pkg) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/repo_mgr/backends/rpm.rb', line 69

def check_sig(pkg)
  out, status = Open3.capture2e "rpm -K #{pkg}"

  return out if status.exitstatus.zero?

  Tools.error "unable to check package signature for #{pkg} - "\
              "rpm -K returned:\n#{out}"
end

#dl_repo(options) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/repo_mgr/backends/rpm.rb', line 35

def dl_repo(options)
  name = options[:repo]
  url = options[:url]
  arch = options[:arch]

  Tools.error 'you must specify an arch name for rpm repo' if arch.nil?

  tmpdir = "/tmp/#{name}/#{arch}"
  dest_dir = "#{@config.cfg_dir}/rpms/#{name}/#{arch}"
  make_dirs tmpdir, dest_dir

  repomd = dl_repomd url, arch, tmpdir
  pkgs = dl_primary url, arch, tmpdir, repomd

  pkgs.each do |hash, file|
    dl_pkg hash, url, arch, file, tmpdir
    copy_pkg "#{tmpdir}/#{file}", dest_dir
  end

  sync_repo name

  pkgs.values
end

#export(repo) ⇒ Object



107
108
109
# File 'lib/repo_mgr/backends/rpm.rb', line 107

def export(repo)
  sync_repo repo
end

#rebuild_pkg_list(repo) ⇒ Object



101
102
103
104
105
# File 'lib/repo_mgr/backends/rpm.rb', line 101

def rebuild_pkg_list(repo)
  Dir["#{@config.cfg_dir}/rpms/#{repo}/**/*.rpm"].map do |e|
    File.basename e
  end
end

#remove_pkg(repo, pkg) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/repo_mgr/backends/rpm.rb', line 59

def remove_pkg(repo, pkg)
  name = File.basename pkg
  arch = extract_arch pkg
  dest_dir = "#{@config.cfg_dir}/rpms/#{repo}/#{arch}"

  FileUtils.rm_f "#{dest_dir}/#{name}"

  sync_repo repo
end

#sign_pkg(repo, pkg) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/repo_mgr/backends/rpm.rb', line 78

def sign_pkg(repo, pkg)
  keyid = @config.cfg[:repos][repo][:keyid]
  gpg_name = GPGME::Key.get(keyid).uids.first.uid

  # need to deal with the %_gpg_name nonsense as adding that via CLI is
  # too bloody much for ARRRRRRRRRR PM - also who in their right mind
  # would target a key by name / email rather than, you know, key ID

  rpm_macros = "#{ENV['HOME']}/.rpmmacros"
  File.write rpm_macros, "%_gpg_name #{gpg_name}"

  # gpg-agent? nah - rpm is special
  cmd = "rpm --addsign #{pkg}"

  out, status = Open3.capture2e cmd

  FileUtils.rm_f rpm_macros

  return if status.exitstatus.zero?

  Tools.error "unable to sign #{pkg} - rpm --addsign returned:\n#{out}"
end