2007-03-26 12:36:09 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
if ARGV.empty?
|
2007-04-19 23:05:34 -04:00
|
|
|
abort "Please specify the directory to capify, e.g. `#{File.basename($0)} .'"
|
2007-03-26 12:36:09 -04: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-19 23:05:34 -04:00
|
|
|
abort "Too many arguments; please specify only the directory to capify."
|
2007-03-26 12:36:09 -04:00
|
|
|
end
|
|
|
|
|
2007-04-19 23:02:30 -04:00
|
|
|
def unindent(string)
|
|
|
|
indentation = string[/\A\s*/]
|
|
|
|
string.strip.gsub(/^#{indentation}/, "")
|
|
|
|
end
|
2007-03-26 12:36:09 -04:00
|
|
|
|
2007-04-19 23:02:30 -04:00
|
|
|
files = {
|
|
|
|
"Capfile" => unindent(<<-FILE),
|
|
|
|
require 'capistrano/version'
|
|
|
|
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
|
|
|
|
load 'config/deploy'
|
|
|
|
FILE
|
2007-03-26 12:36:09 -04:00
|
|
|
|
2007-04-19 23:02:30 -04:00
|
|
|
"config/deploy.rb" => unindent(<<-FILE),
|
|
|
|
set :application, "set your application name here"
|
|
|
|
set :repository, "set your repository location here"
|
|
|
|
|
2007-04-27 01:07:42 -04: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-19 23:02:30 -04:00
|
|
|
# If you aren't using Subversion to manage your source code, specify
|
|
|
|
# your SCM below:
|
|
|
|
# set :scm, :subversion
|
2007-03-26 12:36:09 -04:00
|
|
|
|
2007-04-19 23:02:30 -04:00
|
|
|
role :app, "your app-server here"
|
|
|
|
role :web, "your web-server here"
|
|
|
|
role :db, "your db-server here", :primary => true
|
|
|
|
FILE
|
|
|
|
}
|
|
|
|
|
|
|
|
base = ARGV.shift
|
2007-03-26 12:36:09 -04: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))
|
|
|
|
warn "[skip] directory `#{File.dirname(file)}' does not exist"
|
|
|
|
else
|
|
|
|
puts "[add] writing `#{file}'"
|
|
|
|
File.open(file, "w") { |f| f.write(content) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-04-19 23:05:34 -04:00
|
|
|
puts "[done] capified!"
|