vagrant/website/www/helpers/download_helpers.rb

83 lines
1.9 KiB
Ruby
Raw Normal View History

2013-12-09 08:17:20 +00:00
require "net/http"
$vagrant_files = {}
$vagrant_os = []
$vagrant_os_mappings = {
".deb" => "debian",
".dmg" => "darwin",
".msi" => "windows",
".rpm" => "rpm",
}
$vagrant_os_order = ["darwin", "windows", "debian", "rpm"]
$vagrant_downloads = {}
$vagrant_versions = []
2013-12-09 08:17:20 +00:00
if ENV["VAGRANT_VERSION"]
puts "Finding downloads for Vagrant"
2013-12-09 08:17:20 +00:00
raise "BINTRAY_API_KEY must be set." if !ENV["BINTRAY_API_KEY"]
http = Net::HTTP.new("dl.bintray.com", 80)
2014-02-12 19:52:02 +00:00
req = Net::HTTP::Get.new("/mitchellh/vagrant/")
2013-12-09 08:17:20 +00:00
req.basic_auth "mitchellh", ENV["BINTRAY_API_KEY"]
response = http.request(req)
response.body.split("\n").each do |line|
next if line !~ /\/mitchellh\/vagrant\/(.+?)'/
filename = $1.to_s
# Ignore any files that don't appear to have a version in it
next if filename !~ /[-_]?(\d+\.\d+\.\d+[^-_.]*)/
version = Gem::Version.new($1.to_s)
$vagrant_downloads[version] ||= {}
$vagrant_os_mappings.each do |suffix, os|
2013-12-09 08:17:20 +00:00
if filename.end_with?(suffix)
$vagrant_downloads[version][os] ||= []
$vagrant_downloads[version][os] << filename
2013-12-09 08:17:20 +00:00
end
end
end
$vagrant_versions = $vagrant_downloads.keys.sort.reverse
$vagrant_versions.each do |v|
puts "- Version #{v} found"
2013-12-09 08:17:20 +00:00
end
2013-12-09 19:00:43 +00:00
else
puts "Not generating downloads."
2013-12-09 08:17:20 +00:00
end
module DownloadHelpers
def download_arch(file)
if file.include?("i686")
return "32-bit"
elsif file.include?("x86_64")
return "64-bit"
else
return "Universal (32 and 64-bit)"
end
end
def download_os_human(os)
if os == "darwin"
return "Mac OS X"
elsif os == "debian"
return "Debian / Ubuntu"
elsif os == "rpm"
return "CentOS / RedHat / Fedora"
elsif os == "windows"
return "Windows"
else
return os
end
end
def download_url(file)
"https://dl.bintray.com/mitchellh/vagrant/#{file}"
end
def latest_version
$vagrant_versions.first
2013-12-09 08:17:20 +00:00
end
end