Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the shell to bash for run in Capistrano?

How can I set the shell in the Capistrano run command to use bash instead of sh? I am trying to install RVM and I need to execute the command:

run "bash < <(curl -L http://bit.ly/rvm-install-system-wide)"

as in:

task :install_rvm, :roles => :server do
  apps = %w(bison openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev     libyaml-dev sqlite3 libsqlite3-0 libxml2-dev libxslt-dev autoconf subversion libcurl4-openssl-dev)
  apt.install( {:base => apps}, :stable )
  run "bash < <(curl -L http://bit.ly/rvm-install-system-wide)"
  run "rvm install 1.9.2".sh
  run "rvm use 1.9.2@global"
  run "gem install awesome_print map_by_method wirble bundler builder pg cheat"
  run "gem install -v2.1.2 builder"
  # modify .bashrc
end

But I just can't seem to get it to work because Capistrano is executing:

"sh -c 'bash < <(curl -L http://bit.ly/rvm-install-system-wide)'" on ubuntu@ec2...

I see in the Capistrano gem the command.rb file has some code like

shell = "#{options[:shell] || "sh"} -c"

but it is unclear to me how to pass options[:shell] to the task

like image 847
Charles Avatar asked Oct 12 '11 23:10

Charles


4 Answers

set :shell is not working, but that works:

default_run_options[:shell] = '/bin/bash'

like image 156
hipertracker Avatar answered Oct 09 '22 04:10

hipertracker


It sounds like you need the rvm-capistrano gem. Another option would be to use the mechanism used by rvm-capistrano, that is:

set :default_shell, '/bin/bash -l'
like image 27
adamlamar Avatar answered Oct 09 '22 05:10

adamlamar


Try setting the :shell variable.

set :shell, '/usr/bin/bash'
like image 27
Jonathan Julian Avatar answered Oct 09 '22 05:10

Jonathan Julian


You can also use the following syntax:

execute "bash -c '<command>'"

It is especially useful for setting environment with --login switch, for example:

execute "bash --login -c 'rvm use 1.9.2'"

...and it also works in Capistrano 3.x...!

Be sure to wrap the command in single quotes so that it is passed to bash as a single argument, and so that pathname expansion (globbing), parameter expansion and so on are not performed too early.

like image 40
krzy-wa Avatar answered Oct 09 '22 04:10

krzy-wa