class Packer::Binary::Executable
This class handles downloading, extracting, and saving the associated binary file
Constants
- PACKER_DOWNLOAD_URI
The download URI for the binary package
Public Class Methods
new()
click to toggle source
Loads global config values and creates the download directory if the current platform is supported
# File lib/packer/binary/executable.rb, line 16 def initialize @packer_version = Packer::Binary.config.version @download_path = "#{Packer::Binary.config.download_path.chomp('/')}/packer-binary/#{@packer_version}/bin" @download_filename = "#{@packer_version}-packer.zip" FileUtils.mkdir_p @download_path raise PlatformUnsupported unless supported? end
Public Instance Methods
binary()
click to toggle source
Returns the path to the binary if it exists @return [String] absolute path of the binary
# File lib/packer/binary/executable.rb, line 28 def binary Dir["#{@download_path}/packer*"][0] end
download()
click to toggle source
Downloads the zipfile from the origin
# File lib/packer/binary/executable.rb, line 33 def download return if binary_exist? msg("Downloading https://#{download_domain}/#{download_uri}") require 'open-uri' File.open("#{@download_path}/#{@download_filename}", 'wb') do |saved_file| # the following "open" is provided by open-uri open("https://#{download_domain}/#{download_uri}", 'rb') do |read_file| saved_file.write(read_file.read) end end end
extract()
click to toggle source
Extracts the binary from the zipfile and makes it executable
# File lib/packer/binary/executable.rb, line 49 def extract return if binary_exist? Compressor.extract("#{@download_path}/#{@download_filename}", @download_path) make_exe end
Private Instance Methods
binary_exist?()
click to toggle source
# File lib/packer/binary/executable.rb, line 58 def binary_exist? !binary.nil? end
download_domain()
click to toggle source
# File lib/packer/binary/executable.rb, line 77 def download_domain PACKER_DOWNLOAD_URI end
download_uri()
click to toggle source
# File lib/packer/binary/executable.rb, line 70 def download_uri "packer/#{@packer_version}/packer_#{@packer_version}_freebsd_amd64.zip" if OS.freebsd? "packer/#{@packer_version}/packer_#{@packer_version}_darwin_amd64.zip" if OS.mac? "packer/#{@packer_version}/packer_#{@packer_version}_windows_amd64.zip" if OS.windows? "packer/#{@packer_version}/packer_#{@packer_version}_linux_amd64.zip" if OS.linux? end
make_exe()
click to toggle source
# File lib/packer/binary/executable.rb, line 66 def make_exe FileUtils.chmod('a+x', binary) if binary_exist? end
supported?()
click to toggle source
# File lib/packer/binary/executable.rb, line 62 def supported? OS.freebsd? || OS.mac? || OS.windows? || OS.linux? end