Skip to content

Instantly share code, notes, and snippets.

@n0ts
Created February 10, 2014 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n0ts/8915146 to your computer and use it in GitHub Desktop.
Save n0ts/8915146 to your computer and use it in GitHub Desktop.
Get Chef Packages
#
# get_packages.rb <el5|el6|deb>
#
require 'net/http'
require 'rexml/document'
case ARGV[0]
when 'el5', 'el6', 'deb'
package = ARGV[0]
else
p 'Usage: get_packages.rb <el5|el6|deb>'
exit 1
end
baseurl = 'opscode-omnibus-packages.s3.amazonaws.com'
# get the XML data as a string
xml_data = Net::HTTP.get_response(URI.parse('http://' + baseurl)).body
doc = REXML::Document.new(xml_data)
Net::HTTP.start(baseurl) do |http|
doc.elements.each('ListBucketResult/Contents/Key') do |v|
# x86_64 packages only, exclude rc git packages
next if v.text =~ /^.*(git|rc|alpha|beta).*$/
case package
when 'el5'
next if v.text !~ /^.*.el5.x86_64.rpm$/
when 'el6'
next if v.text !~ /^.*.el6.x86_64.rpm$/
when 'deb'
next if v.text !~ /^.*amd64.deb$/
end
package_name = File.basename(v.text)
next if File.exist?(package_name)
puts 'Downloading ' + v.text
resp = http.get('/' + v.text)
open(package_name, 'wb') { |file|
file.write(resp.body)
}
end
end
puts "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment