2014-07-16 23:51:48 +02:00
|
|
|
require "net/http"
|
|
|
|
|
|
|
|
$terraform_files = {}
|
|
|
|
$terraform_os = []
|
|
|
|
|
2014-07-28 06:11:40 +02:00
|
|
|
if ENV["TERRAFORM_VERSION"]
|
2014-07-16 23:51:48 +02:00
|
|
|
raise "BINTRAY_API_KEY must be set." if !ENV["BINTRAY_API_KEY"]
|
|
|
|
http = Net::HTTP.new("dl.bintray.com", 80)
|
|
|
|
req = Net::HTTP::Get.new("/mitchellh/terraform/")
|
|
|
|
req.basic_auth "mitchellh", ENV["BINTRAY_API_KEY"]
|
|
|
|
response = http.request(req)
|
|
|
|
|
|
|
|
response.body.split("\n").each do |line|
|
2014-08-05 23:32:27 +02:00
|
|
|
next if line !~ /\/mitchellh\/terraform\/terraform_(#{Regexp.quote(ENV["TERRAFORM_VERSION"])}.+?)'/
|
2014-07-16 23:51:48 +02:00
|
|
|
filename = $1.to_s
|
2014-08-05 23:36:30 +02:00
|
|
|
os = filename.split("_")[1]
|
2014-07-16 23:51:48 +02:00
|
|
|
next if os == "SHA256SUMS"
|
|
|
|
next if os == "web"
|
|
|
|
|
|
|
|
$terraform_files[os] ||= []
|
2014-08-05 23:48:04 +02:00
|
|
|
$terraform_files[os] << filename
|
2014-07-16 23:51:48 +02:00
|
|
|
end
|
|
|
|
|
2014-07-28 06:29:12 +02:00
|
|
|
$terraform_os = ["darwin", "linux", "windows"] & $terraform_files.keys
|
|
|
|
$terraform_os += $terraform_files.keys
|
2014-07-16 23:51:48 +02:00
|
|
|
$terraform_os.uniq!
|
|
|
|
|
|
|
|
$terraform_files.each do |key, value|
|
|
|
|
value.sort!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module DownloadHelpers
|
|
|
|
def download_arch(file)
|
|
|
|
parts = file.split("_")
|
2014-08-11 22:48:05 +02:00
|
|
|
return "" if parts.length != 3
|
|
|
|
parts[2].split(".")[0]
|
2014-07-16 23:51:48 +02:00
|
|
|
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-08-05 23:48:04 +02:00
|
|
|
"https://dl.bintray.com/mitchellh/terraform/terraform_#{file}"
|
2014-07-16 23:51:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def latest_version
|
2014-07-28 06:11:40 +02:00
|
|
|
ENV["TERRAFORM_VERSION"]
|
2014-07-16 23:51:48 +02:00
|
|
|
end
|
|
|
|
end
|