github.com/ezbercih/terraform@v0.1.1-0.20140729011846-3c33865e0839/website/helpers/download_helpers.rb (about)

     1  require "net/http"
     2  
     3  $terraform_files = {}
     4  $terraform_os = []
     5  
     6  if ENV["TERRAFORM_VERSION"]
     7    raise "BINTRAY_API_KEY must be set." if !ENV["BINTRAY_API_KEY"]
     8    http = Net::HTTP.new("dl.bintray.com", 80)
     9    req = Net::HTTP::Get.new("/mitchellh/terraform/")
    10    req.basic_auth "mitchellh", ENV["BINTRAY_API_KEY"]
    11    response = http.request(req)
    12  
    13    response.body.split("\n").each do |line|
    14      next if line !~ /\/mitchellh\/terraform\/(#{Regexp.quote(ENV["TERRAFORM_VERSION"])}.+?)'/
    15      filename = $1.to_s
    16      os = filename.split("_")[1]
    17      next if os == "SHA256SUMS"
    18      next if os == "web"
    19  
    20      $terraform_files[os] ||= []
    21      $terraform_files[os] << filename
    22    end
    23  
    24    $terraform_os = ["darwin", "linux", "windows"] & $terraform_files.keys
    25    $terraform_os += $terraform_files.keys
    26    $terraform_os.uniq!
    27  
    28    $terraform_files.each do |key, value|
    29      value.sort!
    30    end
    31  end
    32  
    33  module DownloadHelpers
    34    def download_arch(file)
    35      parts = file.split("_")
    36      return "" if parts.length != 3
    37      parts[2].split(".")[0]
    38    end
    39  
    40    def download_os_human(os)
    41      if os == "darwin"
    42        return "Mac OS X"
    43      elsif os == "freebsd"
    44        return "FreeBSD"
    45      elsif os == "openbsd"
    46        return "OpenBSD"
    47      elsif os == "Linux"
    48        return "Linux"
    49      elsif os == "windows"
    50        return "Windows"
    51      else
    52        return os
    53      end
    54    end
    55  
    56    def download_url(file)
    57      "https://dl.bintray.com/mitchellh/terraform/#{file}"
    58    end
    59  
    60    def latest_version
    61      ENV["TERRAFORM_VERSION"]
    62    end
    63  end