powcloud-sprinkle 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/.gitignore +5 -0
  2. data/CREDITS +33 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.markdown +241 -0
  5. data/Rakefile +50 -0
  6. data/VERSION +1 -0
  7. data/bin/sprinkle +90 -0
  8. data/examples/packages/build_essential.rb +9 -0
  9. data/examples/packages/databases/mysql.rb +13 -0
  10. data/examples/packages/databases/sqlite3.rb +16 -0
  11. data/examples/packages/phusion.rb +55 -0
  12. data/examples/packages/ruby/rails.rb +9 -0
  13. data/examples/packages/ruby/ruby.rb +17 -0
  14. data/examples/packages/ruby/rubygems.rb +17 -0
  15. data/examples/packages/scm/git.rb +11 -0
  16. data/examples/packages/scm/subversion.rb +4 -0
  17. data/examples/packages/servers/apache.rb +15 -0
  18. data/examples/rails/README +15 -0
  19. data/examples/rails/deploy.rb +2 -0
  20. data/examples/rails/packages/database.rb +9 -0
  21. data/examples/rails/packages/essential.rb +9 -0
  22. data/examples/rails/packages/rails.rb +29 -0
  23. data/examples/rails/packages/scm.rb +11 -0
  24. data/examples/rails/packages/search.rb +11 -0
  25. data/examples/rails/packages/server.rb +28 -0
  26. data/examples/rails/rails.rb +73 -0
  27. data/examples/sprinkle/sprinkle.rb +38 -0
  28. data/lib/sprinkle/actors/actors.rb +17 -0
  29. data/lib/sprinkle/actors/capistrano.rb +140 -0
  30. data/lib/sprinkle/actors/local.rb +37 -0
  31. data/lib/sprinkle/actors/ssh.rb +123 -0
  32. data/lib/sprinkle/actors/vlad.rb +78 -0
  33. data/lib/sprinkle/configurable.rb +31 -0
  34. data/lib/sprinkle/deployment.rb +73 -0
  35. data/lib/sprinkle/extensions/arbitrary_options.rb +10 -0
  36. data/lib/sprinkle/extensions/array.rb +5 -0
  37. data/lib/sprinkle/extensions/blank_slate.rb +5 -0
  38. data/lib/sprinkle/extensions/dsl_accessor.rb +15 -0
  39. data/lib/sprinkle/extensions/string.rb +10 -0
  40. data/lib/sprinkle/extensions/symbol.rb +7 -0
  41. data/lib/sprinkle/installers/apt.rb +52 -0
  42. data/lib/sprinkle/installers/binary.rb +46 -0
  43. data/lib/sprinkle/installers/bsd_port.rb +33 -0
  44. data/lib/sprinkle/installers/deb.rb +38 -0
  45. data/lib/sprinkle/installers/freebsd_pkg.rb +37 -0
  46. data/lib/sprinkle/installers/freebsd_portinstall.rb +36 -0
  47. data/lib/sprinkle/installers/gem.rb +64 -0
  48. data/lib/sprinkle/installers/install_package.rb +79 -0
  49. data/lib/sprinkle/installers/installer.rb +120 -0
  50. data/lib/sprinkle/installers/mac_port.rb +38 -0
  51. data/lib/sprinkle/installers/noop.rb +20 -0
  52. data/lib/sprinkle/installers/openbsd_pkg.rb +47 -0
  53. data/lib/sprinkle/installers/opensolaris_pkg.rb +43 -0
  54. data/lib/sprinkle/installers/push_text.rb +45 -0
  55. data/lib/sprinkle/installers/rake.rb +37 -0
  56. data/lib/sprinkle/installers/rpm.rb +37 -0
  57. data/lib/sprinkle/installers/smart.rb +29 -0
  58. data/lib/sprinkle/installers/source.rb +190 -0
  59. data/lib/sprinkle/installers/transfer.rb +164 -0
  60. data/lib/sprinkle/installers/yum.rb +37 -0
  61. data/lib/sprinkle/package.rb +309 -0
  62. data/lib/sprinkle/policy.rb +125 -0
  63. data/lib/sprinkle/script.rb +23 -0
  64. data/lib/sprinkle/verifiers/directory.rb +16 -0
  65. data/lib/sprinkle/verifiers/executable.rb +53 -0
  66. data/lib/sprinkle/verifiers/file.rb +26 -0
  67. data/lib/sprinkle/verifiers/package.rb +26 -0
  68. data/lib/sprinkle/verifiers/process.rb +21 -0
  69. data/lib/sprinkle/verifiers/rpm.rb +21 -0
  70. data/lib/sprinkle/verifiers/ruby.rb +25 -0
  71. data/lib/sprinkle/verifiers/symlink.rb +30 -0
  72. data/lib/sprinkle/verify.rb +114 -0
  73. data/lib/sprinkle.rb +32 -0
  74. data/script/console +8 -0
  75. data/script/destroy +14 -0
  76. data/script/generate +14 -0
  77. data/spec/spec.opts +1 -0
  78. data/spec/spec_helper.rb +17 -0
  79. data/spec/sprinkle/actors/capistrano_spec.rb +265 -0
  80. data/spec/sprinkle/actors/local_spec.rb +29 -0
  81. data/spec/sprinkle/configurable_spec.rb +46 -0
  82. data/spec/sprinkle/deployment_spec.rb +80 -0
  83. data/spec/sprinkle/extensions/array_spec.rb +19 -0
  84. data/spec/sprinkle/extensions/string_spec.rb +21 -0
  85. data/spec/sprinkle/installers/apt_spec.rb +70 -0
  86. data/spec/sprinkle/installers/bsd_port_spec.rb +42 -0
  87. data/spec/sprinkle/installers/freebsd_pkg_spec.rb +49 -0
  88. data/spec/sprinkle/installers/freebsd_portinstall_spec.rb +42 -0
  89. data/spec/sprinkle/installers/gem_spec.rb +107 -0
  90. data/spec/sprinkle/installers/installer_spec.rb +151 -0
  91. data/spec/sprinkle/installers/mac_port_spec.rb +42 -0
  92. data/spec/sprinkle/installers/noop_spec.rb +23 -0
  93. data/spec/sprinkle/installers/openbsd_pkg_spec.rb +49 -0
  94. data/spec/sprinkle/installers/opensolaris_pkg_spec.rb +49 -0
  95. data/spec/sprinkle/installers/push_text_spec.rb +66 -0
  96. data/spec/sprinkle/installers/rake_spec.rb +29 -0
  97. data/spec/sprinkle/installers/rpm_spec.rb +50 -0
  98. data/spec/sprinkle/installers/source_spec.rb +371 -0
  99. data/spec/sprinkle/installers/transfer_spec.rb +98 -0
  100. data/spec/sprinkle/installers/yum_spec.rb +49 -0
  101. data/spec/sprinkle/package_spec.rb +466 -0
  102. data/spec/sprinkle/policy_spec.rb +126 -0
  103. data/spec/sprinkle/script_spec.rb +51 -0
  104. data/spec/sprinkle/sprinkle_spec.rb +25 -0
  105. data/spec/sprinkle/verify_spec.rb +174 -0
  106. metadata +244 -0
@@ -0,0 +1,120 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # The base class which all installers must subclass, this class makes
4
+ # sure all installers share some general features, which are outlined
5
+ # below.
6
+ #
7
+ # = Pre/Post Installation Hooks
8
+ #
9
+ # With all intallation methods you have the ability to specify multiple
10
+ # pre/post installation hooks. This gives you the ability to specify
11
+ # commands to run before and after an installation takes place. All
12
+ # commands by default are sudo'd so there is no need to include "sudo"
13
+ # in the command itself. There are three ways to specify a pre/post hook.
14
+ #
15
+ # First, a single command:
16
+ #
17
+ # pre :install, 'echo "Hello, World!"'
18
+ # post :install, 'rm -rf /'
19
+ #
20
+ # Second, an array of commands:
21
+ #
22
+ # commands = ['echo "First"', 'echo "Then Another"']
23
+ # pre :install, commands
24
+ # post :install, commands
25
+ #
26
+ # Third, a block which returns either a single or multiple commands:
27
+ #
28
+ # pre :install do
29
+ # amount = 7 * 3
30
+ # "echo 'Before we install, lets plant #{amount} magic beans...'"
31
+ # end
32
+ # post :install do
33
+ # ['echo "Now... let's hope they sprout!", 'echo "Indeed they have!"']
34
+ # end
35
+ #
36
+ # = Other Pre/Post Hooks
37
+ #
38
+ # Some installation methods actually grant you more fine grained
39
+ # control of when commands are run rather than a blanket pre :install
40
+ # or post :install. If this is the case, it will be documented on
41
+ # the installation method's corresponding documentation page.
42
+ class Installer
43
+ include Sprinkle::Configurable
44
+ attr_accessor :delivery, :package, :options, :pre, :post #:nodoc:
45
+
46
+ def initialize(package, options = {}, &block) #:nodoc:
47
+ @package = package
48
+ @options = options
49
+ @pre = {}; @post = {}
50
+ self.instance_eval(&block) if block
51
+ end
52
+
53
+ def pre(stage, *commands)
54
+ @pre[stage] ||= []
55
+ @pre[stage] += commands
56
+ @pre[stage] += [yield] if block_given?
57
+ end
58
+
59
+ def post(stage, *commands)
60
+ @post[stage] ||= []
61
+ @post[stage] += commands
62
+ @post[stage] += [yield] if block_given?
63
+ end
64
+
65
+ def process(roles) #:nodoc:
66
+ assert_delivery
67
+
68
+ if logger.debug?
69
+ sequence = install_sequence; sequence = sequence.join('; ') if sequence.is_a? Array
70
+ logger.debug "#{@package.name} install sequence: #{sequence} for roles: #{roles}\n"
71
+ end
72
+
73
+ unless Sprinkle::OPTIONS[:testing]
74
+ logger.info "--> Installing #{package.name} for roles: #{roles}"
75
+ @delivery.process(@package.name, install_sequence, roles)
76
+ end
77
+ end
78
+
79
+ protected
80
+ # More complicated installers that have different stages, and require pre/post commands
81
+ # within stages can override install_sequence and take complete control of the install
82
+ # command sequence construction (eg. source based installer).
83
+ def install_sequence
84
+ commands = pre_commands(:install) + [ install_commands ] + post_commands(:install)
85
+ commands.flatten
86
+ end
87
+
88
+ # A concrete installer (subclass of this virtual class) must override this method
89
+ # and return the commands it needs to run as either a string or an array.
90
+ #
91
+ # <b>Overriding this method is required.</b>
92
+ def install_commands
93
+ raise 'Concrete installers implement this to specify commands to run to install their respective packages'
94
+ end
95
+
96
+ def pre_commands(stage) #:nodoc:
97
+ dress @pre[stage] || [], :pre
98
+ end
99
+
100
+ def post_commands(stage) #:nodoc:
101
+ dress @post[stage] || [], :post
102
+ end
103
+
104
+ # Concrete installers (subclasses of this virtual class) can override this method to
105
+ # specify stage-specific (pre-installation, post-installation, etc.) modifications
106
+ # of commands.
107
+ #
108
+ # An example usage of overriding this would be to prefix all commands for a
109
+ # certain stage to change to a certain directory. An example is given below:
110
+ #
111
+ # def dress(commands, stage)
112
+ # commands.collect { |x| "cd #{magic_beans_path} && #{x}" }
113
+ # end
114
+ #
115
+ # By default, no modifications are made to the commands.
116
+ def dress(commands, stage); commands; end
117
+
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,38 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = Mac OS X Port Installer (macports)
4
+ #
5
+ # The Port installer installs macports ports.
6
+ #
7
+ # == Example Usage
8
+ #
9
+ # Installing the magic_beans port.
10
+ #
11
+ # package :magic_beans do
12
+ # mac_port 'magic/magic_beans'
13
+ # end
14
+ #
15
+ # == Notes
16
+ # Before MacPorts packages can be installed, the PATH
17
+ # environment variable probably has to be changed so
18
+ # capistrano can find the /opt/local/bin/port executable
19
+ #
20
+ # You must set PATH in ~/.ssh/environment on the remote
21
+ # system and enable 'PermitUserEnvironment yes' in /etc/sshd_config
22
+ class MacPort < Installer
23
+ attr_accessor :port #:nodoc:
24
+
25
+ def initialize(parent, port, &block) #:nodoc:
26
+ super parent, &block
27
+ @port = port
28
+ end
29
+
30
+ protected
31
+
32
+ def install_commands #:nodoc:
33
+ "port install #{@port}"
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = Noop Installer
4
+ #
5
+ # This installer does nothing, it's simply useful for running pre / post hooks by themselves.
6
+ #
7
+ class Noop < Installer
8
+ def initialize(parent, name, options = {}, &block) #:nodoc:
9
+ super parent, options, &block
10
+ end
11
+
12
+ protected
13
+
14
+ def install_commands #:nodoc:
15
+ 'echo noop'
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,47 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = OpenBSD Package Installer
4
+ #
5
+ # The Pkg package installer installs OpenBSD packages.
6
+ #
7
+ # == Example Usage
8
+ #
9
+ # Installing the magic_beans package.
10
+ #
11
+ # package :magic_beans do
12
+ # openbsd_pkg 'magic_beans'
13
+ # end
14
+ #
15
+ # You may also specify multiple packages as an array:
16
+ #
17
+ # package :magic_beans do
18
+ # openbsd_pkg %w(magic_beans magic_sauce)
19
+ # end
20
+ #
21
+ # == Notes
22
+ # Before OpenBSD packages can be installed, the PKG_PATH
23
+ # environment variable must be set.
24
+ #
25
+ # You must set PKG_PATH in ~/.ssh/environment on the remote
26
+ # system and enable 'PermitUserEnvironment yes' in /etc/ssh/sshd_config
27
+ #
28
+ # For help on PKG_PATH see section 15.2.2 of the OpenBSD FAQ
29
+ # (http://www.openbsd.org/faq/faq15.html)
30
+ class OpenbsdPkg < Installer
31
+ attr_accessor :packages #:nodoc:
32
+
33
+ def initialize(parent, packages, &block) #:nodoc:
34
+ super parent, &block
35
+ packages = [packages] unless packages.is_a? Array
36
+ @packages = packages
37
+ end
38
+
39
+ protected
40
+
41
+ def install_commands #:nodoc:
42
+ "pkg_add #{@packages.join(' ')}"
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,43 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = OpenSolaris Package Installer
4
+ #
5
+ # The Pkg package installer installs OpenSolaris packages.
6
+ #
7
+ # == Example Usage
8
+ #
9
+ # Installing the magic_beans package.
10
+ #
11
+ # package :magic_beans do
12
+ # opensolaris_pkg 'magic_beans'
13
+ # end
14
+ #
15
+ # You may also specify multiple packages as an array:
16
+ #
17
+ # package :magic_beans do
18
+ # opensolaris_pkg %w(magic_beans magic_sauce)
19
+ # end
20
+ #
21
+ # == Note
22
+ # If you are using capistrano as the deployment method
23
+ # you will need to add the following lines to your deploy.rb
24
+ # set :sudo, 'pfexec'
25
+ # set :sudo_prompt, ''
26
+ class OpensolarisPkg < Installer
27
+ attr_accessor :packages #:nodoc:
28
+
29
+ def initialize(parent, packages, &block) #:nodoc:
30
+ super parent, &block
31
+ packages = [packages] unless packages.is_a? Array
32
+ @packages = packages
33
+ end
34
+
35
+ protected
36
+
37
+ def install_commands #:nodoc:
38
+ "pkg install #{@packages.join(' ')}"
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,45 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # Beware, strange "installer" coming your way.
4
+ #
5
+ # = Text configuration installer
6
+ #
7
+ # This installer pushes simple configuration into a file.
8
+ #
9
+ # == Example Usage
10
+ #
11
+ # Installing magic_beans into apache2.conf
12
+ #
13
+ # package :magic_beans do
14
+ # push_text 'magic_beans', '/etc/apache2/apache2.conf'
15
+ # end
16
+ #
17
+ # If you user has access to 'sudo' and theres a file that requires
18
+ # priveledges, you can pass :sudo => true
19
+ #
20
+ # package :magic_beans do
21
+ # push_text 'magic_beans', '/etc/apache2/apache2.conf', :sudo => true
22
+ # end
23
+ #
24
+ # A special verify step exists for this very installer
25
+ # its known as file_contains, it will test that a file indeed
26
+ # contains a substring that you send it.
27
+ #
28
+ class PushText < Installer
29
+ attr_accessor :text, :path #:nodoc:
30
+
31
+ def initialize(parent, text, path, options={}, &block) #:nodoc:
32
+ super parent, options, &block
33
+ @text = text
34
+ @path = path
35
+ end
36
+
37
+ protected
38
+
39
+ def install_commands #:nodoc:
40
+ "echo -e '#{@text.gsub("'", "'\\\\''").gsub("\n", '\n')}' |#{'sudo ' if option?(:sudo)}tee -a #{@path}"
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,37 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = Rake Installer
4
+ #
5
+ # This installer runs a rake command.
6
+ #
7
+ # == Example Usage
8
+ #
9
+ # The following example runs the command "rake spec" on
10
+ # the remote server.
11
+ #
12
+ # package :spec do
13
+ # rake 'spec'
14
+ # end
15
+ #
16
+ # Specify a Rakefile with the :rakefile option.
17
+ #
18
+ # package :spec, :rakefile => "/var/setup/Rakefile" do
19
+ # rake 'spec'
20
+ # end
21
+
22
+ class Rake < Installer
23
+ def initialize(parent, commands, options = {}, &block) #:nodoc:
24
+ super parent, options, &block
25
+ @commands = commands.to_a
26
+ end
27
+
28
+ protected
29
+
30
+ def install_commands #:nodoc:
31
+ file = @options[:rakefile] ? "-f #{@options[:rakefile]} " : ""
32
+ "rake #{file}#{@commands.join(' ')}"
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = RPM Package Installer
4
+ #
5
+ # The RPM package installer installs RPM packages.
6
+ #
7
+ # == Example Usage
8
+ #
9
+ # Installing the magic_beans RPM. Its all the craze these days.
10
+ #
11
+ # package :magic_beans do
12
+ # rpm 'magic_beans'
13
+ # end
14
+ #
15
+ # You may also specify multiple rpms as an array:
16
+ #
17
+ # package :magic_beans do
18
+ # rpm %w(magic_beans magic_sauce)
19
+ # end
20
+ class Rpm < Installer
21
+ attr_accessor :packages #:nodoc:
22
+
23
+ def initialize(parent, packages, &block) #:nodoc:
24
+ super parent, &block
25
+ packages = [packages] unless packages.is_a? Array
26
+ @packages = packages
27
+ end
28
+
29
+ protected
30
+
31
+ def install_commands #:nodoc:
32
+ "rpm -Uvh #{@packages.join(' ')}"
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ module Sprinkle
2
+ module Installers
3
+ class Smart < Installer
4
+ attr_accessor :packages #:nodoc:
5
+
6
+ def initialize(parent, packages, &block) #:nodoc:
7
+ super parent, &block
8
+ packages = [packages] unless packages.is_a? Array
9
+ @packages = packages
10
+ end
11
+
12
+ protected
13
+
14
+ def install_commands #:nodoc:
15
+ "smart install #{@packages.join(' ')} -y 2>&1 | tee -a /var/log/smart-sprinkle"
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ module Sprinkle
22
+ module Package
23
+ class Package
24
+ def smart(*names, &block)
25
+ @installer = Sprinkle::Installers::Smart.new(self, *names, &block)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,190 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = Source Package Installer
4
+ #
5
+ # The source package installer installs software from source.
6
+ # It handles downloading, extracting, configuring, building,
7
+ # and installing software.
8
+ #
9
+ # == Configuration Options
10
+ #
11
+ # The source installer has many configuration options:
12
+ # * <b>prefix</b> - The prefix directory that is configured to.
13
+ # * <b>archives</b> - The location all the files are downloaded to.
14
+ # * <b>builds</b> - The directory the package is extracted to to configure and install
15
+ #
16
+ # == Pre/Post Hooks
17
+ #
18
+ # The source installer defines a myriad of new stages which can be hooked into:
19
+ # * <b>prepare</b> - Prepare is the stage which all the prefix, archives, and build directories are made.
20
+ # * <b>download</b> - Download is the stage which the software package is downloaded.
21
+ # * <b>extract</b> - Extract is the stage which the software package is extracted.
22
+ # * <b>configure</b> - Configure is the stage which the ./configure script is run.
23
+ # * <b>build</b> - Build is the stage in which `make` is called.
24
+ # * <b>install</b> - Install is the stage which `make install` is called.
25
+ #
26
+ # == Example Usage
27
+ #
28
+ # First, a simple package, no configuration:
29
+ #
30
+ # package :magic_beans do
31
+ # source 'http://magicbeansland.com/latest-1.1.1.tar.gz'
32
+ # end
33
+ #
34
+ # Second, specifying exactly where I want my files:
35
+ #
36
+ # package :magic_beans do
37
+ # source 'http://magicbeansland.com/latest-1.1.1.tar.gz' do
38
+ # prefix '/usr/local'
39
+ # archives '/tmp'
40
+ # builds '/tmp/builds'
41
+ # end
42
+ # end
43
+ #
44
+ # Third, specifying some hooks:
45
+ #
46
+ # package :magic_beans do
47
+ # source 'http://magicbeansland.com/latest-1.1.1.tar.gz' do
48
+ # prefix '/usr/local'
49
+ #
50
+ # pre :prepare { 'echo "Here we go folks."' }
51
+ # post :extract { 'echo "I believe..."' }
52
+ # pre :build { 'echo "Cross your fingers!"' }
53
+ # end
54
+ # end
55
+ #
56
+ # Fourth, specifying a custom archive name because the downloaded file name
57
+ # differs from the source URL:
58
+ #
59
+ # package :gitosis do
60
+ # source 'http://github.com/crafterm/sprinkle/tarball/master' do
61
+ # custom_archive 'crafterm-sprinkle-518e33c835986c03ec7ae8ea88c657443b006f28.tar.gz'
62
+ # end
63
+ # end
64
+ #
65
+ # As you can see, setting options is as simple as creating a
66
+ # block and calling the option as a method with the value as
67
+ # its parameter.
68
+
69
+ class Source < Installer
70
+ attr_accessor :source #:nodoc:
71
+
72
+ def initialize(parent, source, options = {}, &block) #:nodoc:
73
+ @source = source
74
+ super parent, options, &block
75
+ end
76
+
77
+ protected
78
+
79
+ def install_sequence #:nodoc:
80
+ prepare + download + extract + configure + build + install
81
+ end
82
+
83
+ %w( prepare download extract configure build install ).each do |stage|
84
+ define_method stage do
85
+ pre_commands(stage.to_sym) + self.send("#{stage}_commands") + post_commands(stage.to_sym)
86
+ end
87
+ end
88
+
89
+ def prepare_commands #:nodoc:
90
+ raise 'No installation area defined' unless @options[:prefix]
91
+ raise 'No build area defined' unless @options[:builds]
92
+ raise 'No source download area defined' unless @options[:archives]
93
+
94
+ [ "mkdir -p #{@options[:prefix]}",
95
+ "mkdir -p #{@options[:builds]}",
96
+ "mkdir -p #{@options[:archives]}" ]
97
+ end
98
+
99
+ def download_commands #:nodoc:
100
+ [ "wget -cq --directory-prefix='#{@options[:archives]}' #{@source}" ]
101
+ end
102
+
103
+ def extract_commands #:nodoc:
104
+ [ "bash -c 'cd #{@options[:builds]} && #{extract_command} #{@options[:archives]}/#{archive_name}'" ]
105
+ end
106
+
107
+ def configure_commands #:nodoc:
108
+ return [] if custom_install?
109
+
110
+ command = "bash -c 'cd #{build_dir} && ./configure --prefix=#{@options[:prefix]} "
111
+
112
+ extras = {
113
+ :enable => '--enable', :disable => '--disable',
114
+ :with => '--with', :without => '--without',
115
+ :option => '-',
116
+ }
117
+
118
+ extras.inject(command) { |m, (k, v)| m << create_options(k, v) if options[k]; m }
119
+
120
+ [ command << " > #{@package.name}-configure.log 2>&1'" ]
121
+ end
122
+
123
+ def build_commands #:nodoc:
124
+ return [] if custom_install?
125
+ [ "bash -c 'cd #{build_dir} && make > #{@package.name}-build.log 2>&1'" ]
126
+ end
127
+
128
+ def install_commands #:nodoc:
129
+ return custom_install_commands if custom_install?
130
+ [ "bash -c 'cd #{build_dir} && make install > #{@package.name}-install.log 2>&1'" ]
131
+ end
132
+
133
+ def custom_install? #:nodoc:
134
+ !! @options[:custom_install]
135
+ end
136
+
137
+ # REVISIT: must be better processing of custom install commands somehow? use splat operator?
138
+ def custom_install_commands #:nodoc:
139
+ dress @options[:custom_install], :install
140
+ end
141
+
142
+ protected
143
+
144
+ # dress is overriden from the base Sprinkle::Installers::Installer class so that the command changes
145
+ # directory to the build directory first. Also, the result of the command is logged.
146
+ def dress(commands, stage)
147
+ commands.collect { |command| "bash -c 'cd #{build_dir} && #{command} >> #{@package.name}-#{stage}.log 2>&1'" }
148
+ end
149
+
150
+ private
151
+
152
+ def create_options(key, prefix) #:nodoc:
153
+ @options[key].inject(' ') { |m, option| m << "#{prefix}-#{option} "; m }
154
+ end
155
+
156
+ def extract_command #:nodoc:
157
+ case archive_name
158
+ when /(tar.gz)|(tgz)$/
159
+ 'tar xzf'
160
+ when /(tar.bz2)|(tb2)$/
161
+ 'tar xjf'
162
+ when /tar$/
163
+ 'tar xf'
164
+ when /zip$/
165
+ 'unzip'
166
+ else
167
+ raise "Unknown source archive format: #{archive_name}"
168
+ end
169
+ end
170
+
171
+ def archive_name #:nodoc:
172
+ name = @options[:custom_archive] || @source.split('/').last
173
+ raise "Unable to determine archive name for source: #{source}, please update code knowledge" unless name
174
+ name
175
+ end
176
+
177
+ def build_dir #:nodoc:
178
+ "#{@options[:builds]}/#{options[:custom_dir] || base_dir}"
179
+ end
180
+
181
+ def base_dir #:nodoc:
182
+ if archive_name.split('/').last =~ /(.*)\.(tar\.gz|tgz|tar\.bz2|tar|tb2|zip)/
183
+ return $1
184
+ end
185
+ raise "Unknown base path for source archive: #{@source}, please update code knowledge"
186
+ end
187
+
188
+ end
189
+ end
190
+ end