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
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg
2
+ .DS_Store
3
+ .idea
4
+ .*.swp
5
+ sprinkle.gemspec
data/CREDITS ADDED
@@ -0,0 +1,33 @@
1
+ = CREDITS
2
+
3
+ Many thanks to the following people who have submitted ideas, patches, helped with testing
4
+ and/or generally provided support to Sprinkle, I really appreciate your help:
5
+
6
+ Kristin Baumann (http://crafterm.net/kristin/blog/)
7
+ Ben Schwarz (http://germanforblack.com/)
8
+ Jim Freeze (http://www.artima.com/rubycs/articles/ruby_as_dslP.html)
9
+ Matthew Tanase (http://www.slicehost.com)
10
+ Jared Kuolt (http://www.slicehost.com)
11
+ Jamis Buck (http://www.capify.org)
12
+ Matt Allen (http://blog.allen.com.au)
13
+ Eric Hodel (http://blog.segment7.net)
14
+ Pete Yandell (http://notahat.com)
15
+ Adam Meehan (http://duckpunching.com)
16
+ Mitchell Hashimoto (http://mitchellhashimoto.com)
17
+ Ari Lerner (http://www.citrusbyte.com)
18
+ Jorgen Orehøj Erichsen (http://blog.erichsen.net)
19
+ Joshua Sierles (http://diluvia.net)
20
+ Julian Russell (http://github.com/plusplus)
21
+ Dave (Gassto) (http://github.com/gassto)
22
+ Bodaniel Jeanes (http://bjeanes.github.com)
23
+ Jacob Harris (http://open.nytimes.com)
24
+ Justin Pease (http://jit.nuance9.com)
25
+ Tobias Lütke (http://blog.leetsoft.com)
26
+ Josh Reynolds (http://github.com/jreynolds)
27
+ Jan Ulbrich (http://www.ulbrich.net)
28
+ Chris Gaffney (http://github.com/gaffneyc)
29
+ Maxmpz (http://github.com/maxmpz)
30
+ Geoff Garside (http://geoffgarside.co.uk/)
31
+ Oliver Kiessler (http://inceedo.com)
32
+
33
+ The transfer installer contains a piece of exception reporting code copied from the Chef library (http://wiki.opscode.com/display/chef/Home)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Marcus Crafter
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,241 @@
1
+ # SPRINKLE
2
+
3
+ * <http://redartisan.com/2008/5/27/sprinkle-intro>
4
+ * <http://github.com/crafterm/sprinkle>
5
+ * <http://github.com/benschwarz/passenger-stack>
6
+ * <http://www.vimeo.com/2888665>
7
+ * <http://redartisan.lighthouseapp.com/projects/25275-sprinkle/tickets>
8
+
9
+ ## DESCRIPTION:
10
+
11
+ Sprinkle is a software provisioning tool you can use to build remote servers with, after the base operating
12
+ system has been installed. For example, to install a Rails or Merb stack on a brand new slice directly after
13
+ its been created.
14
+
15
+ Properties of packages such as their name, type, dependencies, etc, and what packages apply to what machines
16
+ is described via a domain specific language that Sprinkle executes (in fact one of the aims of Sprinkle is to
17
+ define as concisely as possible a language for installing software).
18
+
19
+ An example package description follows:
20
+
21
+ package :ruby do
22
+ description 'Ruby Virtual Machine'
23
+ version '1.8.6'
24
+ source "ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-#{version}-p111.tar.gz"
25
+ requires :ruby_dependencies
26
+
27
+ verify do
28
+ has_file '/usr/bin/ruby'
29
+ end
30
+ end
31
+
32
+ This defines a package called 'ruby', that uses the source based installer to build Ruby 1.8.6 from source,
33
+ installing the package 'ruby_dependencies' beforehand. Additionally, the package verifies it was installed
34
+ correctly by verifying the file '/usr/bin/ruby' exists after installation. If this verification fails, the
35
+ sprinkle script will gracefully stop.
36
+
37
+ Reasonable defaults are set by sprinkle, such as the install prefix, download area, etc, but can be customized
38
+ globally or per package (see below for an example).
39
+
40
+ Since packages come in many forms (eg. gems, pre-compiled debs, compressed source tar.gz, etc), Sprinkle supports
41
+ many different installer types, giving you the most amount of flexibility of how you'd like software installed.
42
+ New installer types can be added into the system easily.
43
+
44
+ For example, you could install Rails via gems, nginx via source, and mysql via APT, while retaining the flexibility
45
+ of changing installer types as software is updated upstream.
46
+
47
+ Sprinkle also supports dependencies between packages, allowing you specify pre-requisites that need to be
48
+ installed in order.
49
+
50
+ Packages can be grouped into polices to define several packages that should be installed together.
51
+
52
+ An example policy:
53
+
54
+ policy :rails, :roles => :app do
55
+ requires :rails, :version => '2.1.0'
56
+ requires :appserver
57
+ requires :database
58
+ requires :webserver
59
+ end
60
+
61
+ This defines a policy called Rails, that applies to machines of role :app. The policy includes the packages
62
+ rails (version 2.1.0), appserver, database and webserver.
63
+
64
+ appserver, database and webserver can be virtual packages, where the user will be prompted for selection if
65
+ multiple choices for the virtual package exist.
66
+
67
+ Sprinkle is architected to be extendable in many ways, one of those areas is in its deployment of commands to
68
+ remote hosts. Currently Sprinkle supports the use of Capistrano, Vlad, or a direct net/ssh connection to
69
+ issue commands on remote hosts via ssh, but could also be extended to use any other command transport mechanism
70
+ desired. Sprinkle can also be configured to simply issue installation commands to provision the local system.
71
+
72
+ An full example Sprinkle deployment script for deploying Rails (via gems), MySQL (via APT), Apache (via source)
73
+ and Git (via source with dependencies from APT):
74
+
75
+ # Sprinkle Rails deployment script
76
+ #
77
+ # This is an example Sprinkle script, configured to install Rails from gems, Apache, Ruby and Git from source,
78
+ # and mysql and Git dependencies from apt on an Ubuntu system. Installation is configured to run via
79
+ # Capistrano (and an accompanying deploy.rb recipe script). Source based packages are downloaded and built into
80
+ # /usr/local on the remote system.
81
+ #
82
+ # A sprinkle script is separated into 3 different sections. Packages, policies and deployment.
83
+ #
84
+ # Packages
85
+ #
86
+ # Defines the world of packages as we know it. Each package has a name and
87
+ # set of metadata including its installer type (eg. apt, source, gem, etc). Packages can have
88
+ # relationships to each other via dependencies
89
+ #
90
+ # Policies
91
+ #
92
+ # Names a group of packages (optionally with versions) that apply to a particular set of roles.
93
+ #
94
+ # Deployment
95
+ #
96
+ # Defines script wide settings such as a delivery mechanism for executing commands on the target
97
+ # system (eg. capistrano), and installer defaults (eg. build locations, etc).
98
+
99
+ # Packages
100
+
101
+ package :ruby do
102
+ description 'Ruby Virtual Machine'
103
+ version '1.8.6'
104
+ source "ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-#{version}-p111.tar.gz"
105
+ requires :ruby_dependencies
106
+ end
107
+
108
+ package :ruby_dependencies do
109
+ description 'Ruby Virtual Machine Build Dependencies'
110
+ apt %w( bison zlib1g-dev libssl-dev libreadline5-dev libncurses5-dev file )
111
+ end
112
+
113
+ package :mysql, :provides => :database do
114
+ description 'MySQL Database'
115
+ apt %w( mysql-server mysql-client )
116
+ end
117
+
118
+ package :apache, :provides => :webserver do
119
+ description 'Apache 2 HTTP Server'
120
+ version '2.2.9'
121
+ source "http://apache.wildit.net.au/httpd/httpd-#{version}.tar.bz2" do
122
+ enable %w( mods-shared=all proxy proxy-balancer proxy-http rewrite cache headers ssl deflate so )
123
+ prefix "/opt/local/apache2-#{version}"
124
+ post :install, 'install -m 755 support/apachectl /etc/init.d/apache2', 'update-rc.d -f apache2 defaults'
125
+ end
126
+ requires :apache_dependencies
127
+ end
128
+
129
+ package :apache_dependencies do
130
+ description 'Apache 2 HTTP Server Build Dependencies'
131
+ apt %w( openssl libtool mawk zlib1g-dev libssl-dev )
132
+ end
133
+
134
+ package :rubygems do
135
+ description 'Ruby Gems Package Management System'
136
+ version '1.2.0'
137
+ source "http://rubyforge.org/frs/download.php/38646/rubygems-#{version}.tgz" do
138
+ custom_install 'ruby setup.rb'
139
+ end
140
+ requires :ruby
141
+ end
142
+
143
+ package :rails do
144
+ description 'Ruby on Rails'
145
+ gem 'rails'
146
+ version '2.1.0'
147
+ end
148
+
149
+ package :mongrel do
150
+ description 'Mongrel Application Server'
151
+ gem 'mongrel'
152
+ version '1.1.5'
153
+ end
154
+
155
+ package :mongrel_cluster, :provides => :appserver do
156
+ description 'Cluster Management for Mongrel'
157
+ gem 'mongrel_cluster' # :source => 'http://gems.github.com/' for alternate gem server
158
+ version '1.0.5'
159
+ requires :mongrel
160
+ end
161
+
162
+ package :git, :provides => :scm do
163
+ description 'Git Distributed Version Control'
164
+ version '1.5.6.3'
165
+ source "http://kernel.org/pub/software/scm/git/git-#{version}.tar.gz"
166
+ requires :git_dependencies
167
+ end
168
+
169
+ package :git_dependencies do
170
+ description 'Git Build Dependencies'
171
+ apt 'git', :dependencies_only => true
172
+ end
173
+
174
+ # Policies
175
+
176
+ # Associates the rails policy to the application servers. Contains rails, and surrounding
177
+ # packages. Note, appserver, database and webserver are all virtual packages defined above. If
178
+ # there's only one implementation of a virtual package, it's selected automatically, otherwise
179
+ # the user is requested to select which one to use.
180
+
181
+ policy :rails, :roles => :app do
182
+ requires :rails, :version => '2.1.0'
183
+ requires :appserver
184
+ requires :database
185
+ requires :webserver
186
+ requires :scm
187
+ end
188
+
189
+ # Deployment
190
+
191
+ # Configures sprinkle to use capistrano for delivery of commands to the remote machines (via
192
+ # the named 'deploy' recipe). Also configures 'source' installer defaults to put package gear
193
+ # in /usr/local
194
+
195
+ deployment do
196
+
197
+ # mechanism for deployment
198
+ delivery :capistrano do
199
+ recipes 'deploy'
200
+ end
201
+
202
+ # source based package installer defaults
203
+ source do
204
+ prefix '/usr/local' # where all source packages will be configured to install
205
+ archives '/usr/local/sources' # where all source packages will be downloaded to
206
+ builds '/usr/local/build' # where all source packages will be built
207
+ end
208
+
209
+ end
210
+
211
+ Please see the examples directory for more complete examples of Sprinkle deployment scripts, and also the Passenger Stack github page and video by Ben Schwarz (<http://github.com/benschwarz/passenger-stack> and <http://www.vimeo.com/2888665> respectively).
212
+
213
+ Sprinkle is a work in progress and I'm excited to hear if anyone finds it useful - please feel free to
214
+ comment, ask any questions, or send in any ideas, patches, bugs. All most welcome.
215
+
216
+ Marcus Crafter <crafterm@redartisan.com>
217
+
218
+ ## LICENSE:
219
+
220
+ (The MIT License)
221
+
222
+ Copyright (c) 2008-2009 Marcus Crafter <crafterm@redartisan.com>
223
+
224
+ Permission is hereby granted, free of charge, to any person obtaining
225
+ a copy of this software and associated documentation files (the
226
+ 'Software'), to deal in the Software without restriction, including
227
+ without limitation the rights to use, copy, modify, merge, publish,
228
+ distribute, sublicense, and/or sell copies of the Software, and to
229
+ permit persons to whom the Software is furnished to do so, subject to
230
+ the following conditions:
231
+
232
+ The above copyright notice and this permission notice shall be
233
+ included in all copies or substantial portions of the Software.
234
+
235
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
236
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
237
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
238
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
239
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
240
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
241
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "powcloud-sprinkle"
8
+ gem.summary = "Ruby DSL based software provisioning tool"
9
+ gem.description = "Ruby DSL based software provisioning tool"
10
+ gem.email = "drush@powcloud.com"
11
+ gem.rubyforge_project = 'sprinkle'
12
+ gem.homepage = "http://github.com/powcloud/sprinkle"
13
+ gem.authors = ["Marcus Crafter"]
14
+ gem.add_development_dependency "rspec", ">= 1.2.9"
15
+ gem.add_dependency('activesupport', '>= 2.0.2')
16
+ gem.add_dependency('highline', '>= 1.4.0')
17
+ gem.add_dependency('capistrano', '>= 2.5.5')
18
+
19
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
24
+ end
25
+
26
+ require 'spec/rake/spectask'
27
+ Spec::Rake::SpecTask.new(:spec) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.spec_files = FileList['spec/**/*_spec.rb']
30
+ end
31
+
32
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
33
+ spec.libs << 'lib' << 'spec'
34
+ spec.pattern = 'spec/**/*_spec.rb'
35
+ spec.rcov = true
36
+ end
37
+
38
+ task :spec => :check_dependencies
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "sprinkle #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
data/bin/sprinkle ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2008-3-11.
4
+ # Copyright (c) 2008. All rights reserved.
5
+
6
+ begin
7
+ require 'rubygems'
8
+ rescue LoadError
9
+ # no rubygems to load, so we fail silently
10
+ end
11
+
12
+ require 'optparse'
13
+
14
+ # NOTE: the option -p/--path= is given as an example, and should probably be replaced in your application.
15
+
16
+ OPTIONS = {}
17
+ MANDATORY_OPTIONS = %w( path )
18
+
19
+ ARGV.each do |arg|
20
+ ENV[$1] = $2 if arg =~ /^(\w+)=(.*)$/
21
+ end
22
+
23
+ parser = OptionParser.new do |opts|
24
+ opts.banner = <<BANNER
25
+ Sprinkle
26
+ ========
27
+
28
+ http://github.com/crafterm/sprinkle
29
+
30
+ Sprinkle is a software provisioning tool you can use to build remote servers with. eg. to
31
+ install a Rails or Merb stack on a brand new slice directly after its been created. It uses
32
+ a Ruby based domain specific language to describe packages and policies to determine what
33
+ should be installed on particular systems.
34
+
35
+ Please see http://github.com/crafterm/sprinkle/tree/master/README.txt for more information.
36
+
37
+ Usage
38
+ =====
39
+
40
+ $> #{File.basename($0)} [options]
41
+
42
+ Options are:
43
+ BANNER
44
+ opts.separator ""
45
+ opts.on("-s", "--script=PATH", String,
46
+ "Path to a sprinkle script to run") { |OPTIONS[:path]| }
47
+ opts.on("-t", "--test",
48
+ "Process but don't perform any actions") { |OPTIONS[:testing]| }
49
+ opts.on("-v", "--verbose",
50
+ "Verbose output") { |OPTIONS[:verbose]| }
51
+ opts.on("-c", "--cloud",
52
+ "Show powder cloud, ie. package hierarchy and installation order") { |OPTIONS[:cloud]| }
53
+ opts.on("-f", "--force",
54
+ "Force installation of all packages even if it is detected that it has been previously installed") { |OPTIONS[:force]| }
55
+ opts.on("-h", "--help",
56
+ "Show this help message.") { puts opts; exit }
57
+ opts.parse!(ARGV)
58
+
59
+ if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
60
+ puts opts; exit
61
+ end
62
+ end
63
+
64
+ def force_mode(options)
65
+ Sprinkle::OPTIONS[:force] = OPTIONS[:force] || false
66
+ end
67
+
68
+ def operation_mode(options)
69
+ Sprinkle::OPTIONS[:testing] = OPTIONS[:testing] || false
70
+ end
71
+
72
+ def powder_cloud(options)
73
+ Sprinkle::OPTIONS[:cloud] = OPTIONS[:cloud] || false
74
+ end
75
+
76
+ def log_level(options)
77
+ Object.logger.level = ActiveSupport::BufferedLogger::Severity::DEBUG if options[:verbose]
78
+ end
79
+
80
+ require File.dirname(__FILE__) + '/../lib/sprinkle'
81
+
82
+ powder = OPTIONS[:path]
83
+ raise "Sprinkle script is not readable: #{powder}" unless File.readable?(powder)
84
+
85
+ force_mode(OPTIONS)
86
+ operation_mode(OPTIONS)
87
+ powder_cloud(OPTIONS)
88
+ log_level(OPTIONS)
89
+
90
+ Sprinkle::Script.sprinkle File.read(powder), powder