Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/branches/cap2-on-netssh2/bin/capify

Revision 6737, 2.0 kB (checked in by minam, 2 years ago)

document the start/finish and load/exit callbacks. Capfile doesn't need capistrano/version.

  • Property svn:executable set to *
Line 
1 #!/usr/bin/env ruby
2
3 require 'optparse'
4
5 OptionParser.new do |opts|
6   opts.banner = "Usage: #{File.basename($0)} [path]"
7
8   opts.on("-h", "--help", "Displays this help info") do
9     puts opts
10     exit 0
11   end
12
13   begin
14     opts.parse!(ARGV)
15   rescue OptionParser::ParseError => e
16     warn e.message
17     puts opts
18     exit 1
19   end
20 end
21
22 if ARGV.empty?
23   abort "Please specify the directory to capify, e.g. `#{File.basename($0)} .'"
24 elsif !File.exists?(ARGV.first)
25   abort "`#{ARGV.first}' does not exist."
26 elsif !File.directory?(ARGV.first)
27   abort "`#{ARGV.first}' is not a directory."
28 elsif ARGV.length > 1
29   abort "Too many arguments; please specify only the directory to capify."
30 end
31
32 def unindent(string)
33   indentation = string[/\A\s*/]
34   string.strip.gsub(/^#{indentation}/, "")
35 end
36
37 files = {
38   "Capfile" => unindent(<<-FILE),
39     load 'deploy' if respond_to?(:namespace) # cap2 differentiator
40     load 'config/deploy'
41   FILE
42
43   "config/deploy.rb" => unindent(<<-FILE),
44     set :application, "set your application name here"
45     set :repository,  "set your repository location here"
46
47     # If you aren't deploying to /u/apps/\#{application} on the target
48     # servers (which is the default), you can specify the actual location
49     # via the :deploy_to variable:
50     # set :deploy_to, "/var/www/\#{application}"
51
52     # If you aren't using Subversion to manage your source code, specify
53     # your SCM below:
54     # set :scm, :subversion
55
56     role :app, "your app-server here"
57     role :web, "your web-server here"
58     role :db,  "your db-server here", :primary => true
59   FILE
60 }
61
62 base = ARGV.shift
63 files.each do |file, content|
64   file = File.join(base, file)
65   if File.exists?(file)
66     warn "[skip] `#{file}' already exists"
67   elsif File.exists?(file.downcase)
68     warn "[skip] `#{file.downcase}' exists, which could conflict with `#{file}'"
69   elsif !File.exists?(File.dirname(file))
70     warn "[skip] directory `#{File.dirname(file)}' does not exist"
71   else
72     puts "[add] writing `#{file}'"
73     File.open(file, "w") { |f| f.write(content) }
74   end
75 end
76
77 puts "[done] capified!"
Note: See TracBrowser for help on using the browser.