class RightPublish::YumRepo

Constants

ARCHITECTURES
BIN_ALL_ARCH
DEFAULT_DESCRIPTION
DEFAULT_EPEL_LAYOUT
DEFAULT_YUM_DIR
DEFAULT_YUM_EPEL
PKG_TYPES
REPO_KEY
REPO_OPTIONS
SRC_ALL_ARCH
SRC_ALL_PATH
YUM_EXT

Public Instance Methods

add(file_or_dir, target) click to toggle source
# File lib/right_publish/repos/yum.rb, line 27
def add(file_or_dir, target)
  repo_updates = {}

  get_pkg_list(file_or_dir, YUM_EXT) do |path|
    # Determine package architectures, and sort
    appropriate_repos(path, target) do |repo_path|
      repo_path = File.join(repo_config[:subdir], repo_path)
      repo_updates[repo_path] ||= []
      repo_updates[repo_path].push(path)
    end
  end
  return if repo_updates.size == 0

  full_pkg_paths = []
  repo_updates.each_pair do |repo_path, pkgs|
    pkgs.each do |pkg|
      import_pkg( pkg, repo_path )
      full_pkg_paths << File.join(repo_path, File.basename(pkg))
    end
  end
  sign_files full_pkg_paths

  # Rebuild the yum index'
  repo_updates.each_key do |repo_path|
    regen_metadata( repo_path )
    sign_metadata( repo_path )
  end
end
annotate(options={}) click to toggle source
Calls superclass method RightPublish::Repo#annotate
# File lib/right_publish/repos/yum.rb, line 56
def annotate(options={})
  options[:subdir] ||= File.join(repo_config[:subdir], '1')
  options[:filter] = ['*.rpm']
  super(options)
end
import_pkg( pkg, repo_path ) click to toggle source
# File lib/right_publish/repos/yum.rb, line 62
def import_pkg( pkg, repo_path )
  # Remove any instances of this package at a different versionh
  yum_prune( pkg, repo_path )
  install_file( pkg, repo_path )
end
pkg_parts(path) click to toggle source
# File lib/right_publish/repos/yum.rb, line 80
def pkg_parts(path)
  @infocache ||= {}
  return @infocache[path] if @infocache.has_key?(path)

  result = {:name=>nil, :version=>nil, :arch=>nil, :release=>nil}

  query = IO.popen("rpm --queryformat '%{NAME} %{VERSION} %{RELEASE} %{ARCH}' -qp #{path}")
  result[:name], result[:version], result[:release], result[:arch] = query.readline.split(' ')

  # RPM query doesn't identify package as a source package, we just
  # have to test the filename.
  result[:arch] = SRC_ALL_ARCH if path.end_with?('src.rpm')

  @infocache[path] = result
  result
end
sign_files( pkgs ) click to toggle source
# File lib/right_publish/repos/yum.rb, line 68
def sign_files( pkgs )
  if repo_config[:gpg_key_id]
    do_in_subdir('') do

      cmd = "rpm --define '%_gpg_name #{repo_config[:gpg_key_id]}' --addsign #{pkgs.join(' ')}"
      exited = shellout_with_password(cmd)

      raise Exception, "rpm signing failed; cannot continue publishing" unless exited
    end
  end
end

Private Instance Methods

appropriate_repos(path, target) { |''| ... } click to toggle source
# File lib/right_publish/repos/yum.rb, line 107
def appropriate_repos(path, target)
  unless repo_config[:epel]
    # This is a flat repo
    yield ''
    return
  end

  pkg_arch = pkg_parts(path)[:arch] || fail("could not determine architecture for package: #{path}")

  if target
    #TODO Check that the specified dist is configured in the profile (sanity)
    dists = [target]
  else
    unless [BIN_ALL_ARCH,SRC_ALL_ARCH].include? pkg_arch
      fail("need to specify a distribution with binary packages!")
    end
    dists = repo_config[:dists]
  end

  dists.each do |dist|
    dist_name, dist_ver = dist.split("/")
    fail("dist #{dist} format needs to be in form 'dist/dist_version'!") unless dist_name && dist_ver =~ /^\d+$/
    # Source RPMS stored in SRPMS architecture, noarchs go to all architectures
    case pkg_arch
    when SRC_ALL_ARCH
      [SRC_ALL_PATH]
    when BIN_ALL_ARCH
      ARCHITECTURES
    else
      [pkg_arch]
    end.each { |arch| yield repo_dir(repo_config[:epel].to_s, dist_name.to_s, dist_ver.to_s, arch) }
  end
end
regen_metadata(repo_path) click to toggle source
# File lib/right_publish/repos/yum.rb, line 141
def regen_metadata(repo_path)
  # Rebuild the yum index
  Profile.log("Rebuilding Yum Repo [#{repo_path}]...")
  do_in_subdir(repo_path) do
    exit_val = system('createrepo --update -o $(pwd) $(pwd) 2>&1 >/dev/null')
    raise Exception, "yum regen_metadata failed; cannot continue publishing" unless exit_val
  end
end
repo_dir(epel_ver, dist, dist_ver, arch) click to toggle source
# File lib/right_publish/repos/yum.rb, line 99
def repo_dir(epel_ver, dist, dist_ver, arch)
  if repo_config[:epel_layout] == "rightscale-software"
    File.join(dist_ver, arch)
  else
    File.join(epel_ver.to_s, dist, dist_ver, arch)
  end
end
sign_metadata(repo_path) click to toggle source
# File lib/right_publish/repos/yum.rb, line 150
def sign_metadata(repo_path)
  do_in_subdir(repo_path) do
    if repo_config[:gpg_key_id]
      File.unlink("repodata/repomd.xml.asc") if File.exists?("repodata/repomd.xml.asc")
      exit_val = system("gpg -a --batch --passphrase '#{repo_config[:gpg_password]}' --detach-sign repodata/repomd.xml")
      raise Exception, "signing of repodata.xml failed; cannot continue publishing" unless exit_val
      exit_val = system("gpg -a --export '#{repo_config[:gpg_key_id]}' > repodata/repomd.xml.key")
      raise Exception, "exporting gpg public key failed; cannot continue publishing" unless exit_val
    end
  end
end
yum_prune(pkg, repo_path) click to toggle source
# File lib/right_publish/repos/yum.rb, line 162
def yum_prune(pkg, repo_path)
  our_name = pkg_parts(pkg)[:name]
  our_arch = pkg_parts(pkg)[:arch]

  do_in_subdir(repo_path) do
    Dir.glob("*.#{YUM_EXT}") do |rpm|
      File.unlink(rpm) if pkg_parts(rpm)[:name] == our_name && pkg_parts(rpm)[:arch] == our_arch
    end
  end
end