class RepoMgr::Backend::Rpm
rpm backend handler
Public Class Methods
new(config)
click to toggle source
# File lib/repo_mgr/backends/rpm.rb, line 11 def initialize(config) @config = config end
Public Instance Methods
add_pkg(repo, pkg)
click to toggle source
# 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)
click to toggle source
this is managed from RepoMgr::Config
# File lib/repo_mgr/backends/rpm.rb, line 16 def add_repo(_name); end
check_sig(pkg)
click to toggle source
# 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
export(repo)
click to toggle source
# File lib/repo_mgr/backends/rpm.rb, line 78 def export(repo) sync_repo repo end
rebuild_pkg_list(repo)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
build_repo(arch)
click to toggle source
# File lib/repo_mgr/backends/rpm.rb, line 109 def build_repo(arch) cmd = 'createrepo --zck --verbose --update .' out, status = Open3.capture2e cmd return if status.exitstatus.zero? Tools.error "unable to create repo for #{arch} - createrepo "\ "returned:\n#{out}" end
extract_arch(pkg)
click to toggle source
# File lib/repo_mgr/backends/rpm.rb, line 84 def extract_arch(pkg) pkg.split('.')[-2] end
sign_repo(repo)
click to toggle source
# File lib/repo_mgr/backends/rpm.rb, line 120 def sign_repo(repo) keyid = @config.cfg[:repos][repo][:keyid] data = GPGME::Data.new File.read('repomd.xml') opt = { armor: true, signer: keyid, mode: GPGME::SIG_MODE_DETACH } signature = GPGME::Crypto.sign data, opt File.write 'repomd.xml.asc', signature end
sync_repo(repo)
click to toggle source
# File lib/repo_mgr/backends/rpm.rb, line 88 def sync_repo(repo) repo_dir = @config.cfg[:repos][repo][:path] Dir["#{@config.cfg_dir}/rpms/#{repo}/*"].each do |arch_dir| arch = File.basename arch_dir arch_dest = "#{repo_dir}/#{arch}" FileUtils.rm_rf arch_dest FileUtils.mkdir_p arch_dest Dir["#{@config.cfg_dir}/rpms/#{repo}/#{arch}/*.rpm"].each do |rpm| FileUtils.cp rpm, arch_dest end Dir.chdir arch_dest do build_repo arch Dir.chdir('repodata') { sign_repo repo } end end end