Rails 2.3 Template for Dreamhost

I’ve started playing with Rails 2.3 after a bit of a break (Ruby hasn’t been my main programming language until very recently) and I have to say that Templates ROCK!

Working from Casper Fabricus’ script to setup a new git repository on Dreamhost and John Nunemaker’s tutorial on getting your rails app running on dreamhost with passenger and combined them into one template:

#Get the applicaiton name from the current working directory
app_name = File.basename( FileUtils.pwd )

#Ask some leading questions
ssh_domain = ask( "What is the domain of you git repository (ie. example.com)?")
ssh_user = ask( "What is the shell user name to access your git repository?" )
ssh_location = "#{ssh_user}@#{ssh_domain}"
#There is probably a better way to write these two lines
project_domain = app_name
project_domain = ask( "What is the domain to which your application will be deployed?" ) if no?( "Use #{app_name} as the deployment domain for your application?") 

#Setup Capistrano
capify!

#Need an odd mixture of variable substitution.
deploy_file = "default_run_options[:pty] = true
# be sure to change these
set :user, '#{ssh_user}'
set :ssh_domain, '#{ssh_domain}'
set :application, '#{app_name}'
set :domain, '#{project_domain}'
"
deploy_file <<
%q{ # the rest should be good
set :repository,  "#{user}@#{ssh_domain}:git/#{application}.git" 
set :deploy_to, "/home/#{user}/#{domain}" 
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false

server domain, :app, :web
role :db, domain, :primary => true

namespace :deploy do
  task :restart do
    run "touch #{current_path}/tmp/restart.txt" 
  end
end
}
file 'config/deploy.rb', deploy_file

# rails:rm_tmp_dirs
["./tmp/pids", "./tmp/sessions", "./tmp/sockets", "./tmp/cache"].each do |f|
  run("rmdir ./#{f}")
end

run "ssh #{ssh_location} 'mkdir -p ~/git/'#{app_name}'.git && cd ~/git/'#{app_name}'.git && git --bare init'"
git :init
git :remote => "add origin ssh://#{ssh_location}/~/git/#{app_name}.git"

initializer '.gitignore', <<-CODE
log/\\*.log
log/\\*.pid
db/\\*.db
db/\\*.sqlite3
db/schema.rb
tmp/\\*\\*/\\*
.DS_Store
doc/api
doc/app
config/database.yml
CODE

git :add => "."
git :commit => "-a -m 'Created #{app_name}'" 
git :push => "origin master"

initializer '.git/config', <<-CODE
[branch "master"]
  remote = origin
  merge = refs/heads/master
CODE