2007-03-26 16:36:09 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2007-05-09 05:05:05 +00:00
|
|
|
require 'optparse'
|
2009-05-20 21:03:15 +01:00
|
|
|
require 'fileutils'
|
2007-05-09 05:05:05 +00:00
|
|
|
|
|
|
|
OptionParser.new do |opts|
|
|
|
|
opts.banner = "Usage: #{File.basename($0)} [path]"
|
|
|
|
|
|
|
|
opts.on("-h", "--help", "Displays this help info") do
|
|
|
|
puts opts
|
|
|
|
exit 0
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
opts.parse!(ARGV)
|
|
|
|
rescue OptionParser::ParseError => e
|
|
|
|
warn e.message
|
|
|
|
puts opts
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-03-26 16:36:09 +00:00
|
|
|
if ARGV.empty?
|
2007-04-20 03:05:34 +00:00
|
|
|
abort "Please specify the directory to capify, e.g. `#{File.basename($0)} .'"
|
2007-03-26 16:36:09 +00:00
|
|
|
elsif !File.exists?(ARGV.first)
|
|
|
|
abort "`#{ARGV.first}' does not exist."
|
|
|
|
elsif !File.directory?(ARGV.first)
|
|
|
|
abort "`#{ARGV.first}' is not a directory."
|
|
|
|
elsif ARGV.length > 1
|
2007-04-20 03:05:34 +00:00
|
|
|
abort "Too many arguments; please specify only the directory to capify."
|
2007-03-26 16:36:09 +00:00
|
|
|
end
|
|
|
|
|
2007-04-20 03:02:30 +00:00
|
|
|
def unindent(string)
|
|
|
|
indentation = string[/\A\s*/]
|
|
|
|
string.strip.gsub(/^#{indentation}/, "")
|
|
|
|
end
|
2007-03-26 16:36:09 +00:00
|
|
|
|
2007-04-20 03:02:30 +00:00
|
|
|
files = {
|
|
|
|
"Capfile" => unindent(<<-FILE),
|
|
|
|
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
|
2007-09-01 15:03:58 +00:00
|
|
|
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
|
2007-04-20 03:02:30 +00:00
|
|
|
load 'config/deploy'
|
|
|
|
FILE
|
2007-03-26 16:36:09 +00:00
|
|
|
|
2007-04-20 03:02:30 +00:00
|
|
|
"config/deploy.rb" => unindent(<<-FILE),
|
|
|
|
set :application, "set your application name here"
|
|
|
|
set :repository, "set your repository location here"
|
|
|
|
|
2009-05-20 21:03:15 +01:00
|
|
|
# If you have previously been relying upon the code to start, stop
|
|
|
|
# and restart your mongrel application, or if you rely on the database
|
|
|
|
# migration code, please uncomment the lines you require below
|
|
|
|
|
2009-05-26 23:13:45 +01:00
|
|
|
# If you are deploying a rails app you probably need these:
|
|
|
|
|
|
|
|
# load 'ext/rails-database-migrations.rb'
|
|
|
|
# load 'ext/rails-shared-directories.rb'
|
2009-05-20 21:03:15 +01:00
|
|
|
|
|
|
|
# There are also new utility libaries shipped with the core these
|
|
|
|
# include the following, please see individual files for more
|
2009-05-26 23:13:45 +01:00
|
|
|
# documentation, or run `cap -vT` with the following lines commented
|
|
|
|
# out to see what they make available.
|
2009-05-20 21:03:15 +01:00
|
|
|
|
2009-05-26 23:13:45 +01:00
|
|
|
# load 'ext/spinner.rb' # Designed for use with script/spin
|
|
|
|
# load 'ext/passenger-mod-rails.rb' # Restart task for use with mod_rails
|
|
|
|
# load 'ext/web-disable-enable.rb' # Gives you web:disable and web:enable
|
2009-05-20 21:03:15 +01:00
|
|
|
|
2007-04-27 05:07:42 +00:00
|
|
|
# If you aren't deploying to /u/apps/\#{application} on the target
|
|
|
|
# servers (which is the default), you can specify the actual location
|
|
|
|
# via the :deploy_to variable:
|
|
|
|
# set :deploy_to, "/var/www/\#{application}"
|
|
|
|
|
2007-04-20 03:02:30 +00:00
|
|
|
# If you aren't using Subversion to manage your source code, specify
|
|
|
|
# your SCM below:
|
|
|
|
# set :scm, :subversion
|
2009-05-26 23:13:45 +01:00
|
|
|
# see a full list by running "gem contents capistrano | grep 'scm/'"
|
2007-03-26 16:36:09 +00:00
|
|
|
|
2007-04-20 03:02:30 +00:00
|
|
|
role :web, "your web-server here"
|
2009-05-26 23:13:45 +01:00
|
|
|
|
2007-04-20 03:02:30 +00:00
|
|
|
FILE
|
|
|
|
}
|
|
|
|
|
|
|
|
base = ARGV.shift
|
2007-03-26 16:36:09 +00:00
|
|
|
files.each do |file, content|
|
|
|
|
file = File.join(base, file)
|
|
|
|
if File.exists?(file)
|
|
|
|
warn "[skip] `#{file}' already exists"
|
|
|
|
elsif File.exists?(file.downcase)
|
|
|
|
warn "[skip] `#{file.downcase}' exists, which could conflict with `#{file}'"
|
|
|
|
elsif !File.exists?(File.dirname(file))
|
2009-05-20 21:03:15 +01:00
|
|
|
FileUtils.mkdir(File.dirname(file))
|
|
|
|
retry
|
|
|
|
warn "[skip] directory `#{File.dirname(file)}' did not exist, created."
|
2007-03-26 16:36:09 +00:00
|
|
|
else
|
|
|
|
puts "[add] writing `#{file}'"
|
|
|
|
File.open(file, "w") { |f| f.write(content) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-04-20 03:05:34 +00:00
|
|
|
puts "[done] capified!"
|