Skip to content

rbenv:install task? #83

@murb

Description

@murb

Because of the nth time installing rbenv manually I wrote the following lines, which adds cap #{env} rbenv:install to the list of available tasks. It may relate to this request (never tried the 2.x version): #51

namespace :rbenv do
  desc 'Install rbenv'
  task :install do
    on roles(:web) do
      begin
        execute "git clone https://github.com/rbenv/rbenv.git #{fetch(:rbenv_path)}"
      rescue SSHKit::Command::Failed
        puts "rbenv already installed, updating..."
        execute "cd #{fetch(:rbenv_path)} && git pull"
      end        
      # execute "~/.rbenv/bin/rbenv init"
      execute "mkdir -p #{fetch(:rbenv_path)}/plugins"
      begin
        execute "git clone https://github.com/rbenv/ruby-build.git #{fetch(:rbenv_path)}/plugins/ruby-build"
      rescue SSHKit::Command::Failed
        puts "rbenv/ruby-build plugin already installed, updating..."
        execute "cd #{fetch(:rbenv_path)}/plugins/ruby-build && git pull"
      end   
      rbenv_ruby = File.read('.ruby-version').strip
      execute "#{fetch(:rbenv_path)}/bin/rbenv install -s #{fetch(:rbenv_ruby)||rbenv_ruby}"
      execute "#{fetch(:rbenv_path)}/bin/rbenv global #{fetch(:rbenv_ruby)||rbenv_ruby}"
      execute "#{fetch(:rbenv_path)}/shims/gem install bundler --no-document"
      if fetch(:rbenv_ruby).nil?
        puts "\nPlease uncomment the line `# set :rbenv_ruby, File.read('.ruby-version').strip` to enable capistrano rbenv"
      end
    end
  end
end

I'm happy to prepare a pull request...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions