Class: Sprinkle::Installers::Binary

Inherits:
Installer show all
Defined in:
lib/sprinkle/installers/binary.rb

Overview

The Binary installer will download a binary archive and then extract it in the directory specified by the prefix option.

Example Usage

binary "http://some.url.com/archive.tar.gz" do
  prefix   "/home/user/local"
  archives "/home/user/sources"
end

This example will download archive.tar.gz to /home/user/sources and then extract it into /home/user/local.

Instance Attribute Summary

Attributes inherited from Installer

#delivery, #options, #package, #post, #pre

Instance Method Summary collapse

Methods inherited from Installer

#announce, api, #commands_from_block, #defer, #escape_shell_arg, inherited, #install_sequence, #method_missing, #per_host?, #post_process, #process, subclasses, verify_api

Methods included from Sudo

#sudo?, #sudo_cmd, #sudo_stack

Methods included from Attributes

#defaults, #set_defaults

Constructor Details

#initialize(parent, binary_archive, options = {}, &block) ⇒ Binary

:nodoc:


23
24
25
26
# File 'lib/sprinkle/installers/binary.rb', line 23

def initialize(parent, binary_archive, options = {}, &block) #:nodoc:
  @binary_archive = binary_archive
  super parent, options, &block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Sprinkle::Installers::Installer

Instance Method Details

#archive_nameObject

:nodoc:


41
42
43
# File 'lib/sprinkle/installers/binary.rb', line 41

def archive_name #:nodoc:
  @archive_name ||= @binary_archive.split("/").last.gsub('%20', ' ')
end

#extract_commandObject

:nodoc:


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sprinkle/installers/binary.rb', line 45

def extract_command #:nodoc:
  case archive_name
  when /(tar.gz)|(tgz)$/
    'tar xzf'
  when /(tar.bz2)|(tb2)$/
    'tar xjf'
  when /tar$/
    'tar xf'
  when /zip$/
    'unzip -o'
  else
    raise "Unknown binary archive format: #{archive_name}"
  end
end

#install_commandsObject

:nodoc:


36
37
38
39
# File 'lib/sprinkle/installers/binary.rb', line 36

def install_commands #:nodoc:
  commands = [ "bash -c 'wget -cq --directory-prefix=#{@options[:archives]} #{@binary_archive}'" ]
  commands << "bash -c \"cd #{@options[:prefix]} && #{sudo_cmd} #{extract_command} '#{@options[:archives]}/#{archive_name}'\""
end

#prepare_commandsObject

:nodoc:


28
29
30
31
32
33
34
# File 'lib/sprinkle/installers/binary.rb', line 28

def prepare_commands #:nodoc:
  raise 'No installation area defined' unless @options[:prefix]
  raise 'No archive download area defined' unless @options[:archives]

  [ "mkdir -p #{@options[:prefix]}",
    "mkdir -p #{@options[:archives]}" ]
end