Class: Packer::Binary::Executable

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/packer/binary/executable.rb

Instance Method Summary collapse

Methods included from Helpers

debug, err, msg, stderr, stdout, system_command

Constructor Details

#initializeExecutable

Returns a new instance of Executable.



6
7
8
9
10
11
12
13
# File 'lib/packer/binary/executable.rb', line 6

def initialize
  @packer_version = Packer::Binary.config.version
  @download_path = "#{Packer::Binary.config.download_path}/packer-binary/#{@packer_version}/bin"
  @download_filename = "#{@packer_version}-packer.zip"
  FileUtils.mkdir_p @download_path

  raise 'Your OS is not supported' unless supported?
end

Instance Method Details

#binaryObject



15
16
17
# File 'lib/packer/binary/executable.rb', line 15

def binary
  Dir["#{@download_path}/packer*"][0]
end

#downloadObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/packer/binary/executable.rb', line 19

def download
  return "#{binary} already exists" 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

  extract
  make_exe
end