Optimized Capistrano Bundler 0.9 installation task

The recent upgrade for bundler to 0.9.3 requires removing any previous bundler gems, and if you use Capistrano or another deployment system this will bite you if you haven't already upgraded.

This task was built for Ubuntu, but should work fine for any bash environment where Ruby and Rubygems are setup properly.

namespace :bundler do
  set :bundler_ver, '0.9.3'
  desc "install bundler"
  task :install, :roles => :app do 
    run "if ! gem list | grep --silent -e 'bundler.*#{bundler_ver}'; then gem uninstall --ignore-dependencies --executables --all bundler; gem install -y --no-rdoc --no-ri -v #{bundler_ver} bundler; fi"

Capistrano is a systems deployment tool. www.capify.org

Bundler is the new Ruby dependency management gem that is integrated into Rails 3. http://github.com/carlhuda/bundler