class Sprinkle::Installers::Source

Source Package Installer

The source package installer installs software from source. It handles downloading, extracting, configuring, building, and installing software.

Configuration Options

The source installer has many configuration options:

Pre/Post Hooks

The source installer defines a myriad of new stages which can be hooked into:

Example Usage

First, a simple package, no configuration:

package :magic_beans do
  source 'http://magicbeansland.com/latest-1.1.1.tar.gz'
end

Second, specifying exactly where I want my files:

package :magic_beans do
  source 'http://magicbeansland.com/latest-1.1.1.tar.gz' do
    prefix    '/usr/local'
    archives  '/tmp'
    builds    '/tmp/builds'
  end
end

Third, specifying some hooks:

package :magic_beans do
  source 'http://magicbeansland.com/latest-1.1.1.tar.gz' do
    prefix    '/usr/local'

    pre :prepare { 'echo "Here we go folks."' }
    post :extract { 'echo "I believe..."' }
    pre :build { 'echo "Cross your fingers!"' }
  end
end

Fourth, specifying a custom archive name because the downloaded file name differs from the source URL:

package :gitosis do
  source 'http://github.com/crafterm/sprinkle/tarball/master' do
    custom_archive 'crafterm-sprinkle-518e33c835986c03ec7ae8ea88c657443b006f28.tar.gz'
  end
end

Fifth, specifying a custom directory where the archive actually is extracted to:

package :ruby_build do
  source 'https://github.com/sstephenson/ruby-build/archive/v20130227.tar.gz' do
    custom_dir 'ruby-build-20130227'
    custom_install './install.sh'
  end
end

Sixth, specifying custom configure, build, and install commands:

package :mysql_build do
  source 'http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.25a.tar.gz/from/http://cdn.mysql.com/' do
    custom_archive 'mysql-5.5.25a.tar.gz'
    configure_command 'cmake .'
    build_command 'make'             # This is actually the default command but could be set to something else here.
    install_command 'make install'   # This is actually the default command but could be set to something else here.
  end
end

As you can see, setting options is as simple as creating a block and calling the option as a method with the value as its parameter.

Public Instance Methods

source(source, options = {}, &block) click to toggle source
# File lib/sprinkle/installers/source.rb, line 93
def source(source, options = {}, &block)
  recommends :build_essential # Ubuntu/Debian
  install Source.new(self, source, options, &block)
end

Protected Instance Methods

dress(commands, pre_or_post, stage) click to toggle source

dress is overriden from the base Sprinkle::Installers::Installer class so that the command changes directory to the build directory first. Also, the result of the command is logged.

# File lib/sprinkle/installers/source.rb, line 194
def dress(commands, pre_or_post, stage)
  chdir = "cd #{build_dir} && "
  chdir = "" if [:prepare, :download].include?(stage)
  chdir = "" if stage == :extract and pre_or_post == :pre
  flatten(commands).collect { |command| "bash -c '#{chdir}#{command} >> #{@package.name}-#{stage}.log 2>&1'" }
end
in_build_dir(cmd) click to toggle source
# File lib/sprinkle/installers/source.rb, line 179
def in_build_dir(cmd)
  "bash -c 'cd #{build_dir} && #{cmd}'"
end
with_log(cmd, stage) click to toggle source
# File lib/sprinkle/installers/source.rb, line 175
def with_log(cmd, stage)
  "#{cmd} > #{@package.name}-#{stage}.log 2>&1"
end