public
Rubygem
Description: Sprinkle is a software provisioning tool you can use to build remote servers with. eg. to install a Rails or Merb stack on a brand new slice directly after its been created
Homepage: http://sprinkle.rubyforge.org/
Clone URL: git://github.com/crafterm/sprinkle.git
sprinkle / lib / sprinkle / installers / apt.rb
100644 53 lines (45 sloc) 1.647 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module Sprinkle
  module Installers
    # = Apt Package Installer
    #
    # The Apt package installer uses the +apt-get+ command to install
    # packages. The apt installer has only one option which can be
    # modified which is the +dependencies_only+ option. When this is
    # set to true, the installer uses +build-dep+ instead of +install+
    # to only build the dependencies.
    #
    # == Example Usage
    #
    # First, a simple installation of the magic_beans package:
    #
    # package :magic_beans do
    # description "Beans beans they're good for your heart..."
    # apt 'magic_beans_package'
    # end
    #
    # Second, only build the magic_beans dependencies:
    #
    # package :magic_beans_depends do
    # apt 'magic_beans_package' { dependencies_only true }
    # 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.
    class Apt < Installer
      attr_accessor :packages #:nodoc:
 
      def initialize(parent, *packages, &block) #:nodoc:
        packages.flatten!
        
        options = { :dependencies_only => false }
        options.update(packages.pop) if packages.last.is_a?(Hash)
        
        super parent, options, &block
        
        @packages = packages
      end
 
      protected
 
        def install_commands #:nodoc:
          command = @options[:dependencies_only] ? 'build-dep' : 'install'
          "DEBCONF_TERSE='yes' DEBIAN_PRIORITY='critical' DEBIAN_FRONTEND=noninteractive apt-get -qyu #{command} #{@packages.join(' ')}"
        end
 
    end
  end
end