Module: Yum::CentOS

Defined in:
lib/repo_conf_generators/yum_conf_generators.rb

Defined Under Namespace

Classes: AddOns, Base, CentOSPlus, Extras, Updates

Constant Summary collapse

RPM_GPG_KEY_CentOS =
"file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-"

Class Method Summary collapse

Class Method Details

.abstract_generate(params) ⇒ Object

INTERNAL FUNCTIONS #######################################################



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/repo_conf_generators/yum_conf_generators.rb', line 112

def self.abstract_generate(params)
return unless Yum::CentOS::is_this_centos?

ver = Yum::execute("lsb_release  -rs").strip
arch = Yum::execute("uname -i").strip

major_ver = ver.strip.split(".").first

opts = { :enabled => true, :gpgkey_file => RPM_GPG_KEY_CentOS + major_ver, :frozen_date => "latest"}
opts.merge!(params)
repo_path = "#{major_ver}/#{opts[:repo_subpath]}/#{arch}"

raise "missing parameters to generate file!" unless opts[:repo_filename] && opts[:repo_name] && opts[:repo_subpath] &&
                                                    opts[:base_urls] && opts[:frozen_date] && opts[:enabled] && opts[:gpgkey_file]
# Old CentOS versions 5.0 and 5.1 were not versioned...so we just point to the base of the repo instead.
if !(ver =~ /5\.[01]/)
  repo_path = repo_path + "/archive/" + opts[:frozen_date]
end

mirror_list =  opts[:base_urls].map do |bu|
    bu +='/' unless bu[-1..-1] == '/' # ensure the base url is terminated with a '/'
    bu+repo_path
  end
config_body = <<END
[#{opts[:repo_name]}]
name = #{opts[:description]}
baseurl = #{mirror_list.join("\n ")}
failovermethod=priority
gpgcheck=1
enabled=#{(opts[:enabled] ? 1:0)}
gpgkey=#{opts[:gpgkey_file]}
END

target_filename = "#{Yum::BaseRepositoryDir}/#{opts[:repo_filename]}.repo"
File.rename(target_filename,"#{Yum::BaseRepositoryDir}/.#{opts[:repo_filename]}.repo.#{`date +%Y%m%d%M%S`.strip}") if File.exists?("#{Yum::BaseRepositoryDir}/#{opts[:repo_filename]}.repo")
File.open(target_filename,'w') { |f| f.write(config_body) }
puts "Yum config file for CentOS successfully generated in #{target_filename}"
mirror_list
end

.is_this_centos?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/repo_conf_generators/yum_conf_generators.rb', line 152

def self.is_this_centos?
  return ::RightScale::Platform.linux? && ::RightScale::Platform.centos?
end