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.



11
12
13
# File 'lib/repo_mgr/backends/rpm.rb', line 11

def initialize(config)
  @config = config
end

Instance Method Details

#add_pkg(repo, pkg) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/repo_mgr/backends/rpm.rb', line 18

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



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

def add_repo(_name); end

#check_sig(pkg) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/repo_mgr/backends/rpm.rb', line 40

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

#rebuild_pkg_list(repo) ⇒ Object



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

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



30
31
32
33
34
35
36
37
38
# File 'lib/repo_mgr/backends/rpm.rb', line 30

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/repo_mgr/backends/rpm.rb', line 49

def sign_pkg(repo, pkg)
  keyid = @config.cfg[:repos][repo][:keyid]
  gpg_name = GPGME::Key.find(keyid).first.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