Something went wrong. Try again.
A simplified fork of old Capistrano 2.x - a tool for deploying Ruby applications to a server
Something went wrong. Try again.
2.1 kB · 90 lines
at master
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091#!/usr/bin/env rubyrequire 'optparse'require 'fileutils'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 endendif ARGV.empty? abort "Please specify the directory to capify, e.g. `#{File.basename($0)} .'"elsif !File.exist?(ARGV.first) abort "`#{ARGV.first}' does not exist."elsif !File.directory?(ARGV.first) abort "`#{ARGV.first}' is not a directory."elsif ARGV.length > 1 abort "Too many arguments; please specify only the directory to capify."enddef unindent(string) indentation = string[/\A\s*/] string.strip.gsub(/^#{indentation}/, "") + "\n"endfiles = { "Capfile" => unindent(<<-FILE), load 'deploy' load 'deploy/bundler' # Uncomment if you are using Rails asset pipeline # load 'deploy/assets' load 'config/deploy' FILE "config/deploy.rb" => unindent(<<-FILE), server "host.example.com" set :application, "set your application name here" set :repository, "set your git repository URL here" # customize if needed # set :keep_releases, 5 # set :rake, "RACK_ENV=production bundle exec rake" # append :shared_children, "data" namespace :deploy do task :restart do # implement depending on the Ruby app server you use # e.g. for Passenger: # run "touch \#{current_path}/tmp/restart.txt" end end FILE}base = ARGV.shiftfiles.each do |file, content| file = File.join(base, file) if File.exist?(file) warn "[skip] '#{file}' already exists" elsif File.exist?(file.downcase) warn "[skip] '#{file.downcase}' exists, which could conflict with `#{file}'" else unless File.exist?(File.dirname(file)) puts "[add] making directory '#{File.dirname(file)}'" FileUtils.mkdir(File.dirname(file)) end puts "[add] writing '#{file}'" File.open(file, "w") { |f| f.write(content) } endendputs "[done] capified!"