consul/website/helpers/download_helpers.rb

68 lines
1.5 KiB
Ruby
Raw Normal View History

2014-02-08 00:41:03 +00:00
require "net/http"
2014-04-14 22:19:30 +00:00
$consul_files = {}
$consul_os = []
2014-02-08 00:41:03 +00:00
2014-04-14 22:19:30 +00:00
if ENV["CONSUL_VERSION"]
2014-02-08 00:41:03 +00:00
raise "BINTRAY_API_KEY must be set." if !ENV["BINTRAY_API_KEY"]
http = Net::HTTP.new("dl.bintray.com", 80)
2014-04-17 16:42:10 +00:00
req = Net::HTTP::Get.new("/mitchellh/consul/")
2014-02-08 00:41:03 +00:00
req.basic_auth "mitchellh", ENV["BINTRAY_API_KEY"]
response = http.request(req)
response.body.split("\n").each do |line|
2014-04-14 22:19:30 +00:00
next if line !~ /\/mitchellh\/consul\/(#{Regexp.quote(ENV["CONSUL_VERSION"])}.+?)'/
2014-02-08 00:41:03 +00:00
filename = $1.to_s
os = filename.split("_")[1]
next if os == "SHA256SUMS"
2014-05-01 18:35:25 +00:00
next if os == "web"
2014-02-08 00:41:03 +00:00
2014-04-14 22:19:30 +00:00
$consul_files[os] ||= []
$consul_files[os] << filename
2014-02-08 00:41:03 +00:00
end
2014-04-14 22:19:30 +00:00
$consul_os = ["darwin", "linux", "windows"] & $consul_files.keys
$consul_os += $consul_files.keys
$consul_os.uniq!
2014-02-08 00:41:03 +00:00
2014-04-14 22:19:30 +00:00
$consul_files.each do |key, value|
2014-02-08 00:41:03 +00:00
value.sort!
end
end
module DownloadHelpers
def download_arch(file)
parts = file.split("_")
return "" if parts.length != 3
parts[2].split(".")[0]
end
def download_os_human(os)
if os == "darwin"
return "Mac OS X"
elsif os == "freebsd"
return "FreeBSD"
elsif os == "openbsd"
return "OpenBSD"
elsif os == "Linux"
return "Linux"
elsif os == "windows"
return "Windows"
else
return os
end
end
def download_url(file)
2014-04-14 22:19:30 +00:00
"https://dl.bintray.com/mitchellh/consul/#{file}"
2014-02-08 00:41:03 +00:00
end
2014-05-01 17:49:30 +00:00
def ui_download_url
download_url("#{latest_version}_web_ui.zip")
end
2014-02-08 00:41:03 +00:00
def latest_version
2014-04-14 22:19:30 +00:00
ENV["CONSUL_VERSION"]
2014-02-08 00:41:03 +00:00
end
end