Module: Yum::Epel

Defined in:
lib/repo_conf_generators/yum_conf_generators.rb

Overview

Module CentOS

Constant Summary collapse

RPM_GPG_KEY_EPEL =
"file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-"

Class Method Summary collapse

Class Method Details

.abstract_generate(params) ⇒ Object

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



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/repo_conf_generators/yum_conf_generators.rb', line 171

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

epel_version = get_enterprise_linux_version
puts "found EPEL version: #{epel_version}"
opts = { :enabled => true, :gpgkey_file => RPM_GPG_KEY_EPEL + epel_version.to_s, :frozen_date => "latest"}
opts.merge!(params)
raise "missing parameters to generate file!" unless opts[:repo_filename] && opts[:repo_name] &&
                                                    opts[:base_urls] && opts[:frozen_date] && opts[:enabled] && opts[:gpgkey_file]

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

  repo_path = "#{epel_version}/#{arch}/archive/"+opts[:frozen_date]
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 = "[\#{opts[:repo_name]}]\nname = \#{opts[:description]}\nbaseurl = \#{mirror_list.join(\"\\n \")}\nfailovermethod=priority\ngpgcheck=1\nenabled=\#{(opts[:enabled] ? 1:0)}\ngpgkey=\#{opts[:gpgkey_file]}\n"

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 Epel successfully generated in #{target_filename}"
mirror_list
end

.generate(description, base_urls, frozen_date = "latest") ⇒ Object



160
161
162
163
164
165
166
167
168
169
# File 'lib/repo_conf_generators/yum_conf_generators.rb', line 160

def self.generate(description, base_urls, frozen_date = "latest")
  opts = {:repo_filename => "Epel",
    :repo_name => "epel",
    :description => description,
    :base_urls => base_urls,
    :frozen_date => frozen_date,
    :enabled => true }
  opts[:frozen_date] = frozen_date || "latest" # Optional frozen date
  Yum::Epel::abstract_generate(opts)
end

.get_enterprise_linux_versionObject

Return the enterprise linux version of the running machine…or an exception if it’s a non-enterprise version of linux. At this point we will only test for CentOS … but in the future we can test RHEL, and any other compatible ones Note the version is a single (major) number.



208
209
210
211
212
213
214
215
216
# File 'lib/repo_conf_generators/yum_conf_generators.rb', line 208

def self.get_enterprise_linux_version
  version=nil
  if Yum::CentOS::is_this_centos?
    version = Yum::execute("lsb_release  -rs").strip.split(".").first
  else
    raise "This doesn't appear to be an Enterprise Linux edition"
  end
  version
end