# # # Copyright (c) 2009-2011 RightScale Inc # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. require 'fileutils' require 'date' module Yum BaseRepositoryDir="/etc/yum.repos.d" unless defined?(BaseRepositoryDir) def self.execute(command) res = `#{command}` raise "Error #{RightScale::SubprocessFormatting.reason($?)} executing: `#{command}`: #{res}" unless $? == 0 res end module RightScale module Epel ##################################################################### def self.generate(description, base_urls, frozen_date = "latest") opts = {:repo_filename => "RightScale-epel", :repo_name => "rightscale-epel", :description => description, :base_urls => base_urls, :frozen_date => frozen_date, :enabled => true } opts[:frozen_date] = frozen_date || "latest" # Optional frozen date Yum::RightScale::Epel::abstract_generate(opts) end module Testing #########################Epel-testing ########################### def self.generate(description, base_urls, frozen_date = "latest") opts = {:repo_filename => "RightScale-epel-testing", :repo_name => "rightscale-epel-testing", :description => description, :base_urls => base_urls, :frozen_date => frozen_date, :enabled => true } opts[:frozen_date] = frozen_date || "latest" # Optional frozen date Yum::RightScale::Epel::abstract_generate(opts) end end ############## INTERNAL FUNCTIONS ####################################################### def self.abstract_generate(params) return unless Yum::RightScale::Epel::yum_installed? epel_version = get_enterprise_linux_version puts "found EPEL version: #{epel_version}" opts = { :enabled => true, :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] 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 gpgcheck = "1" unless Yum::RightScale::Epel::rightscale_gpgkey_imported? gpgfile = "/etc/pki/rpm-gpg/RPM-GPG-KEY-RightScale" if File.exists?(gpgfile) # This file should be installed by the rightimage cookbook # starting with 12H1 (May 2012) gpgkey = "file://#{gpgfile}" gpgcheck = "1" else gpgfile = File.expand_path("../rightscale_key.pub", __FILE__) Yum::execute("rpm --import #{gpgfile}") gpgcheck = "1" gpgkey = "" end end config_body = < "rightscale_extra", :repo_name => "default", :description => description, :codename => '#{c}', :base_urls => base_urls, :frozen_date => frozen_date, :enabled => true } opts[:frozen_date] = frozen_date || "latest" # Optional frozen date Apt::RightScale::abstract_generate(opts) end end EOS end def self.path_to_sources_list "/etc/apt/sources.list.d" end def self.rightscale_gpgkey_imported? begin Apt::execute("apt-key list | grep RightScale") true rescue false end end ############## INTERNAL FUNCTIONS ####################################################### def self.abstract_generate(params) return unless ::RightScale::Platform.linux? && ::RightScale::Platform.ubuntu? opts = { :enabled => true, :frozen_date => "latest"} opts.merge!(params) raise ArgumentError.new("missing parameters to generate file!") unless opts[:repo_filename] && opts[:repo_name] && opts[:base_urls] && opts[:frozen_date] && opts[:enabled] return unless opts[:enabled] target = opts[:codename].downcase codename = ::RightScale::Platform.codename.downcase raise ::RightScale::Exceptions::PlatformError, "Unsupported Ubuntu release #{codename}" unless SUPPORTED_REPOS.include?(codename) raise ::RightScale::Exceptions::PlatformError, "Wrong release; repo is for #{target}, we are #{codename}" unless target == codename FileUtils.mkdir_p(Apt::RightScale::path_to_sources_list) if opts[:frozen_date] != 'latest' x = Date.parse(opts[:frozen_date]).to_s x.gsub!(/-/,"/") opts[:frozen_date] = x end mirror_list = opts[:base_urls].map do |bu| bu +='/' unless bu[-1..-1] == '/' # ensure the base url is terminated with a '/' bu + opts[:frozen_date] end config_body = "" mirror_list.each do |mirror_url| config_body += <