2007-03-26 12:36:09 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2007-05-09 01:05:05 -04:00
|
|
|
require 'optparse'
|
2009-05-20 16:03:15 -04:00
|
|
|
require 'fileutils'
|
2007-05-09 01:05:05 -04: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 12:36:09 -04:00
|
|
|
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),
|
2011-06-24 01:06:47 -04:00
|
|
|
|
2012-02-20 17:01:28 -05:00
|
|
|
load 'deploy'
|
2012-02-20 15:06:05 -05:00
|
|
|
|
2011-06-24 01:06:47 -04:00
|
|
|
# Uncomment if you are using Rails' asset pipeline
|
|
|
|
# load 'deploy/assets'
|
|
|
|
|
2009-08-27 09:46:24 -04:00
|
|
|
load 'config/deploy' # remove this line to skip loading any of the default tasks
|
|
|
|
FILE
|
2009-07-27 09:53:49 -04:00
|
|
|
|
2009-08-27 09:47:41 -04:00
|
|
|
"config/deploy.rb" => 'set :application, "set your application name here"
|
|
|
|
set :repository, "set your repository location here"
|
2009-07-27 09:53:49 -04:00
|
|
|
|
2012-06-28 16:28:23 -04:00
|
|
|
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
|
2009-08-27 09:47:41 -04:00
|
|
|
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
|
2009-08-27 09:24:53 -04:00
|
|
|
|
2009-08-27 09:47:41 -04:00
|
|
|
role :web, "your web-server here" # Your HTTP server, Apache/etc
|
|
|
|
role :app, "your app-server here" # This may be the same as your `Web` server
|
|
|
|
role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run
|
|
|
|
role :db, "your slave db-server here"
|
2009-08-27 09:24:53 -04:00
|
|
|
|
2012-03-08 11:01:55 -05:00
|
|
|
# if you want to clean up old releases on each deploy uncomment this:
|
|
|
|
# after "deploy:restart", "deploy:cleanup"
|
|
|
|
|
2011-01-12 09:06:14 -05:00
|
|
|
# if you\'re still using the script/reaper helper you will need
|
2009-08-27 09:47:41 -04:00
|
|
|
# these http://github.com/rails/irs_process_scripts
|
2009-08-27 09:24:53 -04:00
|
|
|
|
2010-11-03 17:31:23 -04:00
|
|
|
# If you are using Passenger mod_rails uncomment this:
|
2009-08-27 09:47:41 -04:00
|
|
|
# namespace :deploy do
|
2009-12-12 21:07:24 -05:00
|
|
|
# task :start do ; end
|
|
|
|
# task :stop do ; end
|
2009-08-27 09:47:41 -04:00
|
|
|
# task :restart, :roles => :app, :except => { :no_release => true } do
|
|
|
|
# run "#{try_sudo} touch #{File.join(current_path,\'tmp\',\'restart.txt\')}"
|
|
|
|
# end
|
|
|
|
# end'}
|
2007-04-19 23:02:30 -04:00
|
|
|
|
|
|
|
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)
|
2009-08-27 09:46:24 -04:00
|
|
|
warn "[skip] '#{file}' already exists"
|
2007-03-26 12:36:09 -04:00
|
|
|
elsif File.exists?(file.downcase)
|
2009-08-27 09:46:24 -04:00
|
|
|
warn "[skip] '#{file.downcase}' exists, which could conflict with `#{file}'"
|
2007-03-26 12:36:09 -04:00
|
|
|
else
|
2009-08-27 09:46:24 -04:00
|
|
|
unless File.exists?(File.dirname(file))
|
|
|
|
puts "[add] making directory '#{File.dirname(file)}'"
|
|
|
|
FileUtils.mkdir(File.dirname(file))
|
|
|
|
end
|
|
|
|
puts "[add] writing '#{file}'"
|
2007-03-26 12:36:09 -04:00
|
|
|
File.open(file, "w") { |f| f.write(content) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-04-19 23:05:34 -04:00
|
|
|
puts "[done] capified!"
|