Browse files

extact extensions, closes #60

  • Loading branch information...
1 parent 0eb6dc1 commit bacfd9cba755ca793f23e74b8b04232b984e5aae @mpapis mpapis committed Jul 2, 2013
View
17 Manifest.yml
@@ -4,6 +4,21 @@
- Rakefile
- LICENSE
- lib/rvm/capistrano.rb
+- lib/rvm/capistrano/base.rb
+- lib/rvm/capistrano/create_gemset.rb
- lib/rvm/capistrano/empty_gemset.rb
-- lib/rvm/capistrano/version.rb
+- lib/rvm/capistrano/gem_install_uninstall.rb
+- lib/rvm/capistrano/gemset_import_export.rb
+- lib/rvm/capistrano/install_pkgs.rb
+- lib/rvm/capistrano/install_ruby.rb
+- lib/rvm/capistrano/install_rvm.rb
- lib/rvm/capistrano/selector.rb
+- lib/rvm/capistrano/selector_mixed.rb
+- lib/rvm/capistrano/version.rb
+- lib/rvm/capistrano/helpers/_cset.rb
+- lib/rvm/capistrano/helpers/base.rb
+- lib/rvm/capistrano/helpers/quote_and_escape.rb
+- lib/rvm/capistrano/helpers/run_silent_curl.rb
+- lib/rvm/capistrano/helpers/rvm_if_sudo.rb
+- lib/rvm/capistrano/helpers/rvm_methods.rb
+- lib/rvm/capistrano/helpers/with_rvm_group.rb
View
315 lib/rvm/capistrano.rb
@@ -1,320 +1,11 @@
# Recipes for using RVM on a server with capistrano.
require 'rvm/capistrano/selector'
-
-module Capistrano
- Configuration.instance(true).load do
-
- unless methods.map(&:to_sym).include?(:_cset)
- # Taken from the capistrano code.
- def _cset(name, *args, &block)
- unless exists?(name)
- set(name, *args, &block)
- end
- end
- end
-
- class << self
- def quote_and_escape(text, quote = "'")
- "#{quote}#{text.gsub(/#{quote}/) { |m| "#{quote}\\#{quote}#{quote}" }}#{quote}"
- end
- end
-
- # this is part of check, search for :rvm_require_role
- unless fetch(:rvm_require_role,nil).nil?
- set :rvm_require_role_was_set_before_require, true
- class << self
- def run(cmd, options={}, &block)
- if options[:eof].nil? && !cmd.include?(sudo)
- options = options.merge(:eof => !block_given?)
- end
- shell = options[:shell]
- options[:shell] = false
-
- parallel(options) do |session|
- if shell.nil?
- session.when "in?(:#{fetch(:rvm_require_role,nil)})", command_with_shell(cmd, fetch(:rvm_shell)), &block
- end
- session.else command_with_shell(cmd, shell), &block
- end
- end
- def command_with_shell(cmd, shell=nil)
- if shell == false
- cmd
- else
- "#{shell || "sh"} -c #{quote_and_escape(cmd)}"
- end
- end
- end
- end
-
- on :load do
-
- # this is part of check, search for :rvm_require_role
- if ! fetch(:rvm_require_role,nil).nil? and fetch(:rvm_require_role_was_set_before_require, nil).nil?
- raise "
-
-ERROR: detected 'set :rvm_require_role, \"#{fetch(:rvm_require_role,nil)}\"' after 'require \"rvm/capistrano\"', please move it above for proper functioning.
-
-"
- end
-
- # Let users configure a path to export/import gemsets
- _cset(:rvm_gemset_path, "#{rvm_path}/gemsets")
-
- # Default sudo state
- _cset(:rvm_install_with_sudo, false)
-
- # Let users set the install type and shell of their choice.
- _cset(:rvm_install_type, :stable)
- _cset(:rvm_install_shell, :bash)
-
- # Let users set the (re)install for ruby.
- _cset(:rvm_install_ruby, :install)
-
- # Pass no special params to the ruby build by default
- _cset(:rvm_install_ruby_params, '')
-
- # Additional rvm packages to install.
- _cset(:rvm_install_pkgs, [])
-
- # By default system installations add deploying user to rvm group. also try :all
- _cset(:rvm_add_to_group, fetch(:user,"$USER"))
-
- end
-
- namespace :rvm do
-
- def run_silent_curl(command)
- run(<<-EOF.gsub(/[\s]+/, ' '), :shell => "#{rvm_install_shell}")
- __LAST_STATUS=0;
- export CURL_HOME="${TMPDIR:-${HOME}}/.rvm-curl-config.$$";
- mkdir ${CURL_HOME}/;
- {
- [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc;
- echo "silent";
- echo "show-error";
- } > $CURL_HOME/.curlrc;
- #{command} || __LAST_STATUS=$?;
- rm -rf $CURL_HOME;
- exit ${__LAST_STATUS}
- EOF
- end
-
- def rvm_if_sudo(options = {})
- case rvm_type
- when :root, :system
- if fetch(:use_sudo, true) == false && rvm_install_with_sudo == false
- explanation = <<-EXPLANATION
-You can enable use_sudo within rvm for use only by this install operation by adding to deploy.rb:
-
- set :rvm_install_with_sudo, true
-
- EXPLANATION
- if options[:deferred]
- <<-DEFERRED_ERROR.gsub(/\n/, " ; ")
-echo "
-Neither :use_sudo or :rvm_install_with_sudo was set and installation would ended up in using 'sudo'
-#{explanation}
-" >&2
-exit 1
- DEFERRED_ERROR
- else
- raise "
-
-:use_sudo is set to 'false' but sudo is needed to install rvm_type: #{rvm_type}.
-#{explanation}
-"
- end
- else
- "#{sudo} "
- end
- else
- ''
- end
- end
-
- def with_rvm_group(command)
- case rvm_type
- when :root, :system
- <<-CODE
-if id | grep ' groups=.*(rvm)' >/dev/null ;
-then #{command} ;
-else #{rvm_if_sudo(:deferred=>true)} sg rvm -c #{quote_and_escape(command)} ;
-fi
- CODE
- else
- command
- end
- end
-
- def rvm_task(name,&block)
- if fetch(:rvm_require_role,nil).nil?
- task name, &block
- else
- task name, :roles => fetch(:rvm_require_role), &block
- end
- end
-
- desc <<-EOF
- Install RVM of the given choice to the server.
- By default RVM "stable" is installed, change with:
-
- set :rvm_install_type, :head
-
- By default BASH is used for installer, change with:
-
- set :rvm_install_shell, :zsh
- EOF
- rvm_task :install_rvm do
- command_fetch = "curl -L get.rvm.io"
- command_install = rvm_if_sudo
- command_install << "#{rvm_install_shell} -s #{rvm_install_type} --path #{rvm_path}"
- case rvm_type
- when :root, :system
- command_install << " --add-to-rvm-group #{[rvm_add_to_group].flatten.map(&:to_s).join(",")}"
- end
- run_silent_curl "#{command_fetch} | #{command_install}"
- end
-
- desc <<-EOF
- Install RVM ruby to the server, create gemset if needed.
- By default ruby is installed, you can reinstall with:
-
- set :rvm_install_ruby, :reinstall
-
- By default ruby is compiled using all CPU cores, change with:
-
- set :rvm_install_ruby_threads, 5
-
- By default BASH is used for installer, change with:
-
- set :rvm_install_shell, :zsh
- EOF
- rvm_task :install_ruby do
- ruby, gemset = fetch(:rvm_ruby_string_evaluated).to_s.strip.split(/@/)
- if %w( release_path default ).include? "#{ruby}"
- raise "
-
-ruby can not be installed when using :rvm_ruby_string => :#{ruby}
-
-"
- else
- command_install = ""
-
- autolibs_flag = fetch(:rvm_autolibs_flag, 2).to_s
- autolibs_flag_no_requirements = %w(
- 0 disable disabled
- 1 read read-only
- 2 fail read-fail
- ).include?( autolibs_flag )
-
- install_ruby_threads = fetch(:rvm_install_ruby_threads,nil).nil? ? '' : "-j #{rvm_install_ruby_threads}"
-
- if autolibs_flag_no_requirements
- command_install << with_rvm_group("#{File.join(rvm_bin_path, "rvm")} --autolibs=#{autolibs_flag} #{rvm_install_ruby} #{ruby} #{install_ruby_threads} #{rvm_install_ruby_params}")
- else
- command_install << "#{rvm_if_sudo} #{File.join(rvm_bin_path, "rvm")} --autolibs=#{autolibs_flag} requirements #{ruby}"
- command_install << "; "
- command_install << with_rvm_group("#{File.join(rvm_bin_path, "rvm")} --autolibs=1 #{rvm_install_ruby} #{ruby} #{install_ruby_threads} #{rvm_install_ruby_params}")
- end
-
- if gemset
- command_install << "; "
- command_install << with_rvm_group("#{File.join(rvm_bin_path, "rvm")} #{ruby} do rvm gemset create #{gemset}")
- end
-
- run_silent_curl command_install
- end
- end
-
- desc <<-EOF
- Install RVM packages to the server.
-
- This must come before the 'rvm:install_ruby' task is called.
-
- The package list is empty by default. Specifiy the packages to install with:
-
- set :rvm_install_pkgs, %w[libyaml curl]
-
- Full list of packages available at https://rvm.io/packages/ or by running 'rvm pkg'.
- EOF
- rvm_task :install_pkgs do
- rvm_install_pkgs.each do |pkg|
- run "#{File.join(rvm_bin_path, "rvm")} pkg install #{pkg}", :shell => "#{rvm_install_shell}"
- end
- end
-
- desc "Create gemset"
- rvm_task :create_gemset do
- ruby, gemset = fetch(:rvm_ruby_string_evaluated).to_s.strip.split(/@/)
- if %w( release_path default ).include? "#{ruby}"
- raise "
-
-gemset can not be created when using :rvm_ruby_string => :#{ruby}
-
-"
- else
- if gemset
- run with_rvm_group("#{File.join(rvm_bin_path, "rvm")} #{ruby} do rvm gemset create #{gemset}"), :shell => "#{rvm_install_shell}"
- end
- end
- end
-
- desc <<-EOF
- Import file contents to the current RVM ruby gemset.
-
- The gemset filename must match :rvm_ruby_string.gems and be located in :rvm_gemset_path.
- :rvm_gemset_path defaults to :rvm_path/gemsets
-
- The gemset can be created with 'cap rvm:gemset_export'.
- EOF
- rvm_task :import_gemset do
- ruby, gemset = fetch(:rvm_ruby_string_evaluated).to_s.strip.split(/@/)
- if %w( release_path default ).include? "#{ruby}"
- raise "gemset can not be imported when using :rvm_ruby_string => :#{ruby}"
- else
- if gemset
- run "#{File.join(rvm_bin_path, "rvm-shell")} #{fetch(:rvm_ruby_string_evaluated)} rvm gemset import #{File.join(rvm_gemset_path, "#{fetch(:rvm_ruby_string_evaluated)}.gems")}", :shell => "#{rvm_install_shell}"
- end
- end
- end
-
- desc <<-EOF
- Export the current RVM ruby gemset contents to a file.
-
- The gemset filename will match :rvm_ruby_string.gems and be located in :rvm_gemset_path.
- :rvm_gemset_path defaults to :rvm_path/gemsets
-
- The gemset can be imported with 'cap rvm:gemset_import'.
- EOF
- rvm_task :export_gemset do
- ruby, gemset = fetch(:rvm_ruby_string_evaluated).to_s.strip.split(/@/)
- if %w( release_path default ).include? "#{ruby}"
- raise "gemset can not be imported when using :rvm_ruby_string => :#{ruby}"
- else
- if gemset
- run "#{File.join(rvm_bin_path, "rvm-shell")} #{fetch(:rvm_ruby_string_evaluated)} rvm gemset export > #{File.join(rvm_gemset_path, "#{fetch(:rvm_ruby_string_evaluated)}.gems")}", :shell => "#{rvm_install_shell}"
- end
- end
- end
-
- desc "Install a gem, 'cap rvm:install_gem GEM=my_gem'."
- rvm_task :install_gem do
- run "#{File.join(rvm_bin_path, "rvm")} #{fetch(:rvm_ruby_string_evaluated)} do gem install #{ENV['GEM']}", :shell => "#{rvm_install_shell}"
- end
-
- desc "Uninstall a gem, 'cap rvm:uninstall_gem GEM=my_gem'."
- rvm_task :uninstall_gem do
- run "#{File.join(rvm_bin_path, "rvm")} #{fetch(:rvm_ruby_string_evaluated)} do gem uninstall --no-executables #{ENV['GEM']}", :shell => "#{rvm_install_shell}"
- end
-
- end
- end if Capistrano.const_defined? :Configuration and Capistrano::Configuration.methods.map(&:to_sym).include? :instance
-end
+require 'rvm/capistrano/install_rvm'
+require 'rvm/capistrano/install_ruby'
+require 'rvm/capistrano/create_gemset'
# E.g, to use ree and rails 3:
#
# require 'rvm/capistrano'
# set :rvm_ruby_string, "ree@rails3"
-#
View
80 lib/rvm/capistrano/base.rb
@@ -0,0 +1,80 @@
+require 'rvm/capistrano/helpers/_cset'
+require 'rvm/capistrano/helpers/rvm_methods'
+
+rvm_with_capistrano do
+
+ on :load do
+ _cset :rvm_shell do
+ shell = File.join(rvm_bin_path, "rvm-shell")
+ ruby = fetch(:rvm_ruby_string_evaluated).strip
+ case ruby
+ when "release_path"
+ shell = "rvm_path=#{rvm_path} #{shell} --path '#{release_path}'"
+ when "local"
+ ruby = (ENV['GEM_HOME'] || "").gsub(/.*\//, "")
+ raise "Failed to get ruby version from GEM_HOME. Please make sure rvm is loaded!" if ruby.empty?
+ shell = "rvm_path=#{rvm_path} #{shell} '#{ruby}'"
+ else
+ shell = "rvm_path=#{rvm_path} #{shell} '#{ruby}'" unless ruby.empty?
+ end
+ shell
+ end
+
+ # Let users set the type of their rvm install.
+ _cset(:rvm_type, :user)
+
+ # Define rvm_path
+ # This is used in the default_shell command to pass the required variable to rvm-shell, allowing
+ # rvm to boostrap using the proper path. This is being lost in Capistrano due to the lack of a
+ # full environment.
+ _cset(:rvm_path) do
+ case rvm_type
+ when :root, :system
+ "/usr/local/rvm"
+ when :local, :user, :default
+ "$HOME/.rvm/"
+ else
+ rvm_type.to_s.empty? ? "$HOME/.rvm" : rvm_type.to_s
+ end
+ end
+
+ # Let users override the rvm_bin_path
+ _cset(:rvm_bin_path) do
+ case rvm_type
+ when :root, :system
+ "/usr/local/rvm/bin"
+ when :local, :user, :default
+ "$HOME/.rvm/bin"
+ else
+ rvm_type.to_s.empty? ? "#{rvm_path}/bin" : rvm_type.to_s
+ end
+ end
+
+ # evaluate :rvm_ruby_string => :local
+ set :rvm_ruby_string_evaluated do
+ value = fetch(:rvm_ruby_string, :default)
+ if value.to_sym == :local
+ value = ENV['GEM_HOME'].gsub(/.*\//,"")
+ end
+ value.to_s
+ end
+
+ # Use the default ruby on the server, by default :)
+ _cset(:rvm_ruby_string, :default)
+
+ end
+
+## not needed in base but are used in many extensions
+
+ on :load do
+ # Let users set the install shell of their choice
+ _cset(:rvm_install_shell, :bash)
+ end
+
+ extend Capistrano::RvmMethods
+
+ namespace :rvm do
+ extend Capistrano::RvmMethods
+ end
+
+end
View
24 lib/rvm/capistrano/create_gemset.rb
@@ -0,0 +1,24 @@
+require 'rvm/capistrano/base'
+require 'rvm/capistrano/helpers/with_rvm_group'
+
+rvm_with_capistrano do
+ namespace :rvm do
+
+ desc "Create gemset"
+ rvm_task :create_gemset do
+ ruby, gemset = fetch(:rvm_ruby_string_evaluated).to_s.strip.split(/@/)
+ if %w( release_path default ).include? "#{ruby}"
+ raise "
+
+gemset can not be created when using :rvm_ruby_string => :#{ruby}
+
+"
+ else
+ if gemset
+ run_rvm("rvm gemset create #{gemset}", :with_rvm_group => true, :with_ruby => ruby)
+ end
+ end
+ end
+
+ end
+end
View
28 lib/rvm/capistrano/empty_gemset.rb
@@ -1,19 +1,21 @@
# Extension to empty gemset.
-module Capistrano extend self
- Configuration.instance(true).load do
- namespace :rvm do
- desc "Empty gemset"
- task :empty_gemset do
- ruby, gemset = rvm_ruby_string.to_s.strip.split /@/
- if %w( release_path default ).include? "#{ruby}"
- raise "gemset can not be emptied when using :rvm_ruby_string => :#{ruby}"
- else
- if gemset
- run "#{File.join(rvm_bin_path, "rvm")} #{ruby} do rvm --force gemset empty #{gemset}", :shell => "#{rvm_install_shell}"
- end
+require 'rvm/capistrano/base'
+
+rvm_with_capistrano do
+ namespace :rvm do
+
+ desc "Empty gemset"
+ task :empty_gemset do
+ ruby, gemset = rvm_ruby_string_evaluated.to_s.strip.split /@/
+ if %w( release_path default ).include? "#{ruby}"
+ raise "gemset can not be emptied when using :rvm_ruby_string => :#{ruby}"
+ else
+ if gemset
+ run_rvm("rvm --force gemset empty #{gemset}", :with_ruby => ruby)
end
end
end
- end if const_defined? :Configuration
+
+ end
end
View
17 lib/rvm/capistrano/gem_install_uninstall.rb
@@ -0,0 +1,17 @@
+require 'rvm/capistrano/base'
+
+rvm_with_capistrano do
+ namespace :rvm do
+
+ desc "Install a gem, 'cap rvm:install_gem GEM=my_gem'."
+ rvm_task :install_gem do
+ run_rvm("gem install #{ENV['GEM']}", :with_ruby => rvm_ruby_string_evaluated)
+ end
+
+ desc "Uninstall a gem, 'cap rvm:uninstall_gem GEM=my_gem'."
+ rvm_task :uninstall_gem do
+ run_rvm("gem uninstall --no-executables #{ENV['GEM']}", :with_ruby => rvm_ruby_string_evaluated)
+ end
+
+ end
+end
View
56 lib/rvm/capistrano/gemset_import_export.rb
@@ -0,0 +1,56 @@
+require 'rvm/capistrano/base'
+
+rvm_with_capistrano do
+
+ on :load do
+
+ # Let users configure a path to export/import gemsets
+ _cset(:rvm_gemset_path, "#{rvm_path}/gemsets")
+
+ end
+
+ namespace :rvm do
+
+ desc <<-EOF
+ Import file contents to the current RVM ruby gemset.
+
+ The gemset filename must match :rvm_ruby_string.gems and be located in :rvm_gemset_path.
+ :rvm_gemset_path defaults to :rvm_path/gemsets
+
+ The gemset can be created with 'cap rvm:gemset_export'.
+ EOF
+ rvm_task :import_gemset do
+ ruby, gemset = fetch(:rvm_ruby_string_evaluated).to_s.strip.split(/@/)
+ if %w( release_path default ).include? "#{ruby}"
+ raise "gemset can not be imported when using :rvm_ruby_string => :#{ruby}"
+ else
+ if gemset
+ ruby = fetch(:rvm_ruby_string_evaluated)
+ run_rvm("rvm gemset import #{File.join(rvm_gemset_path, "#{ruby}.gems")}", :with_ruby => ruby)
+ end
+ end
+ end
+
+ desc <<-EOF
+ Export the current RVM ruby gemset contents to a file.
+
+ The gemset filename will match :rvm_ruby_string.gems and be located in :rvm_gemset_path.
+ :rvm_gemset_path defaults to :rvm_path/gemsets
+
+ The gemset can be imported with 'cap rvm:gemset_import'.
+ EOF
+ rvm_task :export_gemset do
+ ruby, gemset = fetch(:rvm_ruby_string_evaluated).to_s.strip.split(/@/)
+ if %w( release_path default ).include? "#{ruby}"
+ raise "gemset can not be exported when using :rvm_ruby_string => :#{ruby}"
+ else
+ if gemset
+ ruby = fetch(:rvm_ruby_string_evaluated)
+ run_rvm("rvm gemset export > #{File.join(rvm_gemset_path, "#{ruby}.gems")}", :with_ruby => ruby)
+ end
+ end
+ end
+
+ end
+
+end
View
14 lib/rvm/capistrano/helpers/_cset.rb
@@ -0,0 +1,14 @@
+require 'rvm/capistrano/helpers/base'
+
+rvm_with_capistrano do
+
+ unless methods.map(&:to_sym).include?(:_cset)
+ # Taken from the capistrano code.
+ def _cset(name, *args, &block)
+ unless exists?(name)
+ set(name, *args, &block)
+ end
+ end
+ end
+
+end
View
8 lib/rvm/capistrano/helpers/base.rb
@@ -0,0 +1,8 @@
+module Capistrano
+end
+
+def rvm_with_capistrano(&block)
+ if Capistrano.const_defined? :Configuration and Capistrano::Configuration.methods.map(&:to_sym).include? :instance
+ Capistrano::Configuration.instance(true).load(&block)
+ end
+end
View
7 lib/rvm/capistrano/helpers/quote_and_escape.rb
@@ -0,0 +1,7 @@
+require 'rvm/capistrano/helpers/base'
+
+rvm_with_capistrano do
+ def quote_and_escape(text, quote = "'")
+ "#{quote}#{text.gsub(/#{quote}/) { |m| "#{quote}\\#{quote}#{quote}" }}#{quote}"
+ end
+end
View
19 lib/rvm/capistrano/helpers/run_silent_curl.rb
@@ -0,0 +1,19 @@
+require 'rvm/capistrano/base'
+
+rvm_with_capistrano do
+ def run_silent_curl(command)
+ run_without_rvm(<<-EOF.gsub(/[\s]+/, ' '))
+ __LAST_STATUS=0;
+ export CURL_HOME="${TMPDIR:-${HOME}}/.rvm-curl-config.$$";
+ mkdir ${CURL_HOME}/;
+ {
+ [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc;
+ echo "silent";
+ echo "show-error";
+ } > $CURL_HOME/.curlrc;
+ #{command} || __LAST_STATUS=$?;
+ rm -rf $CURL_HOME;
+ exit ${__LAST_STATUS}
+ EOF
+ end
+end
View
43 lib/rvm/capistrano/helpers/rvm_if_sudo.rb
@@ -0,0 +1,43 @@
+require 'rvm/capistrano/base'
+
+rvm_with_capistrano do
+
+ on :load do
+ # Default sudo state
+ _cset(:rvm_install_with_sudo, false)
+ end
+
+ def rvm_if_sudo(options = {})
+ case rvm_type
+ when :root, :system
+ if fetch(:use_sudo, true) == false && rvm_install_with_sudo == false
+ explanation = <<-EXPLANATION
+You can enable use_sudo within rvm for use only by this install operation by adding to deploy.rb:
+
+ set :rvm_install_with_sudo, true
+
+ EXPLANATION
+ if options[:deferred]
+ <<-DEFERRED_ERROR.gsub(/\n/, " ; ")
+echo "
+Neither :use_sudo or :rvm_install_with_sudo was set and installation would ended up in using 'sudo'
+#{explanation}
+" >&2
+exit 1
+ DEFERRED_ERROR
+ else
+ raise "
+
+:use_sudo is set to 'false' but sudo is needed to install rvm_type: #{rvm_type}.
+#{explanation}
+"
+ end
+ else
+ "#{sudo} "
+ end
+ else
+ ''
+ end
+ end
+
+end
View
40 lib/rvm/capistrano/helpers/rvm_methods.rb
@@ -0,0 +1,40 @@
+module Capistrano
+ module RvmMethods
+ # defined depending on which selector was used
+ def rvm_task(name,&block)
+ if fetch(:rvm_require_role,nil).nil?
+ task name, &block
+ else
+ task name, :roles => fetch(:rvm_require_role), &block
+ end
+ end
+
+ # allow running tasks without using rvm_shell
+ def run_without_rvm(command)
+ run command, :shell => "#{rvm_install_shell}"
+ end
+
+ # allow running tasks with forcing rvm_shell
+ def run_with_rvm(command)
+ run command, :shell => "#{rvm_shell}"
+ end
+
+ # shortcut to binary rvm #{command}
+ # - use :with_rvm_group => true - to wrap it all in `with_rvm_group(...)` call
+ # - use :with_ruby => 'with_ruby' - to extend to `.../bin/rvm #{with_ruby} do`
+ def run_rvm(command, options={})
+ if options[:with_rvm_group]
+ run_without_rvm("#{path_to_bin_rvm(options)} #{command}")
+ else
+ run_without_rvm(with_rvm_group("#{path_to_bin_rvm(options)} #{command}"))
+ end
+ end
+
+ # helper to find path to rvm binary
+ def path_to_bin_rvm(options={})
+ result = File.join(rvm_bin_path, "rvm")
+ result << " #{options[:with_ruby]} do" if options[:with_ruby]
+ result
+ end
+ end
+end
View
21 lib/rvm/capistrano/helpers/with_rvm_group.rb
@@ -0,0 +1,21 @@
+require 'rvm/capistrano/helpers/base'
+require 'rvm/capistrano/helpers/rvm_if_sudo'
+require 'rvm/capistrano/helpers/quote_and_escape'
+
+rvm_with_capistrano do
+
+ def with_rvm_group(command)
+ case rvm_type
+ when :root, :system
+ <<-CODE
+if id | grep ' groups=.*(rvm)' >/dev/null ;
+then #{command} ;
+else #{rvm_if_sudo(:deferred=>true)} sg rvm -c #{quote_and_escape(command)} ;
+fi
+ CODE
+ else
+ command
+ end
+ end
+
+end
View
38 lib/rvm/capistrano/install_pkgs.rb
@@ -0,0 +1,38 @@
+require 'rvm/capistrano/base'
+
+rvm_with_capistrano do
+
+ warn "task 'rvm:install_pkgs' is deprecated, please read about autolibs => http://rvm.io/rvm/autolibs especially check the autolibs mode 'rvm_pkg'."
+
+ on :load do
+
+ # Additional rvm packages to install.
+ _cset(:rvm_install_pkgs, [])
+
+ end
+
+ namespace :rvm do
+
+ desc <<-EOF
+ WARNING: Deprecated, please read about autolibs => http://rvm.io/rvm/autolibs especially check the autolibs mode 'rvm_pkg'.
+
+ Install RVM packages to the server.
+
+ This must come before the 'rvm:install_ruby' task is called.
+
+ The package list is empty by default. Specifiy the packages to install with:
+
+ set :rvm_install_pkgs, %w[libyaml curl]
+
+ Full list of packages available at https://rvm.io/packages/ or by running 'rvm pkg'.
+ EOF
+
+ rvm_task :install_pkgs do
+ rvm_install_pkgs.each do |pkg|
+ run_rvm("pkg install #{pkg}")
+ end
+ end
+
+ end
+
+end
View
73 lib/rvm/capistrano/install_ruby.rb
@@ -0,0 +1,73 @@
+require 'rvm/capistrano/base'
+require 'rvm/capistrano/helpers/run_silent_curl'
+require 'rvm/capistrano/helpers/rvm_if_sudo'
+require 'rvm/capistrano/helpers/with_rvm_group'
+
+rvm_with_capistrano do
+
+ on :load do
+
+ # Let users set the (re)install for ruby.
+ _cset(:rvm_install_ruby, :install)
+
+ # Pass no special params to the ruby build by default
+ _cset(:rvm_install_ruby_params, '')
+
+ end
+
+ namespace :rvm do
+
+ desc <<-EOF
+ Install RVM ruby to the server, create gemset if needed.
+ By default ruby is installed, you can reinstall with:
+
+ set :rvm_install_ruby, :reinstall
+
+ By default ruby is compiled using all CPU cores, change with:
+
+ set :rvm_install_ruby_threads, 5
+
+ By default BASH is used for installer, change with:
+
+ set :rvm_install_shell, :zsh
+ EOF
+ rvm_task :install_ruby do
+ ruby, gemset = fetch(:rvm_ruby_string_evaluated).to_s.strip.split(/@/)
+ if %w( release_path default ).include? "#{ruby}"
+ raise "
+
+ruby can not be installed when using :rvm_ruby_string => :#{ruby}
+
+"
+ else
+ command_install = ""
+
+ autolibs_flag = fetch(:rvm_autolibs_flag, 2).to_s
+ autolibs_flag_no_requirements = %w(
+ 0 disable disabled
+ 1 read read-only
+ 2 fail read-fail
+ ).include?( autolibs_flag )
+
+ install_ruby_threads = fetch(:rvm_install_ruby_threads,nil).nil? ? '' : "-j #{rvm_install_ruby_threads}"
+
+ if autolibs_flag_no_requirements
+ command_install << with_rvm_group("#{path_to_bin_rvm} --autolibs=#{autolibs_flag} #{rvm_install_ruby} #{ruby} #{install_ruby_threads} #{rvm_install_ruby_params}")
+ else
+ command_install << "#{rvm_if_sudo} #{path_to_bin_rvm} --autolibs=#{autolibs_flag} requirements #{ruby}"
+ command_install << "; "
+ command_install << with_rvm_group("#{path_to_bin_rvm} --autolibs=1 #{rvm_install_ruby} #{ruby} #{install_ruby_threads} #{rvm_install_ruby_params}")
+ end
+
+ if gemset
+ command_install << "; "
+ command_install << with_rvm_group("#{path_to_bin_rvm(:with_ruby=>ruby)} rvm gemset create #{gemset}")
+ end
+
+ run_silent_curl command_install
+ end
+ end
+
+ end
+
+end
View
42 lib/rvm/capistrano/install_rvm.rb
@@ -0,0 +1,42 @@
+require 'rvm/capistrano/base'
+require 'rvm/capistrano/helpers/run_silent_curl'
+require 'rvm/capistrano/helpers/rvm_if_sudo'
+
+rvm_with_capistrano do
+
+ on :load do
+
+ # Let users set the install type of their choice.
+ _cset(:rvm_install_type, :stable)
+
+ # By default system installations add deploying user to rvm group. also try :all
+ _cset(:rvm_add_to_group, fetch(:user,"$USER"))
+
+ end
+
+ namespace :rvm do
+
+ desc <<-EOF
+ Install RVM of the given choice to the server.
+ By default RVM "stable" is installed, change with:
+
+ set :rvm_install_type, :head
+
+ By default BASH is used for installer, change with:
+
+ set :rvm_install_shell, :zsh
+ EOF
+ rvm_task :install_rvm do
+ command_fetch = "curl -L get.rvm.io"
+ command_install = rvm_if_sudo
+ command_install << "#{rvm_install_shell} -s #{rvm_install_type} --path #{rvm_path}"
+ case rvm_type
+ when :root, :system
+ command_install << " --add-to-rvm-group #{[rvm_add_to_group].flatten.map(&:to_s).join(",")}"
+ end
+ run_silent_curl "#{command_fetch} | #{command_install}"
+ end
+
+ end
+
+end
View
77 lib/rvm/capistrano/selector.rb
@@ -1,71 +1,22 @@
-module Capistrano
- Configuration.instance(true).load do
- on :load do
- _cset :rvm_shell do
- shell = File.join(rvm_bin_path, "rvm-shell")
- ruby = fetch(:rvm_ruby_string_evaluated).strip
- case ruby
- when "release_path"
- shell = "rvm_path=#{rvm_path} #{shell} --path '#{release_path}'"
- when "local"
- ruby = (ENV['GEM_HOME'] || "").gsub(/.*\//, "")
- raise "Failed to get ruby version from GEM_HOME. Please make sure rvm is loaded!" if ruby.empty?
- shell = "rvm_path=#{rvm_path} #{shell} '#{ruby}'"
- else
- shell = "rvm_path=#{rvm_path} #{shell} '#{ruby}'" unless ruby.empty?
- end
- shell
- end
+require 'rvm/capistrano/base'
- # this is part of check, search for :rvm_require_role
- if fetch(:rvm_require_role,nil).nil?
- set :default_shell do
- fetch(:rvm_shell)
- end
- end
+rvm_with_capistrano do
+ on :load do
- # Let users set the type of their rvm install.
- _cset(:rvm_type, :user)
+ # conflicts with rvm/capistrano/selector_mixed
+ unless fetch(:rvm_require_role,nil).nil?
+ raise "
- # Define rvm_path
- # This is used in the default_shell command to pass the required variable to rvm-shell, allowing
- # rvm to boostrap using the proper path. This is being lost in Capistrano due to the lack of a
- # full environment.
- _cset(:rvm_path) do
- case rvm_type
- when :root, :system
- "/usr/local/rvm"
- when :local, :user, :default
- "$HOME/.rvm/"
- else
- rvm_type.to_s.empty? ? "$HOME/.rvm" : rvm_type.to_s
- end
- end
+ ERROR: found: 'set :rvm_require_role, \"#{fetch(:rvm_require_role,nil)}\"',
+ it conflicts with 'require \"rvm/capistrano/selector\"',
+ please remove it.
- # Let users override the rvm_bin_path
- _cset(:rvm_bin_path) do
- case rvm_type
- when :root, :system
- "/usr/local/rvm/bin"
- when :local, :user, :default
- "$HOME/.rvm/bin"
- else
- rvm_type.to_s.empty? ? "#{rvm_path}/bin" : rvm_type.to_s
- end
- end
-
- # evaluate :rvm_ruby_string => :local
- set :rvm_ruby_string_evaluated do
- value = fetch(:rvm_ruby_string, :default)
- if value.to_sym == :local
- value = ENV['GEM_HOME'].gsub(/.*\//,"")
- end
- value.to_s
- end
-
- # Use the default ruby on the server, by default :)
- _cset(:rvm_ruby_string, :default)
+ "
+ end
+ set :default_shell do
+ fetch(:rvm_shell)
end
+
end
end
View
41 lib/rvm/capistrano/selector_mixed.rb
@@ -0,0 +1,41 @@
+require 'rvm/capistrano/base'
+require 'rvm/capistrano/helpers/quote_and_escape'
+
+rvm_with_capistrano do
+
+ if fetch(:rvm_require_role,nil).nil?
+ raise "
+
+ERROR: no 'set :rvm_require_role, \"...\"' declared before 'rvm/capistrano/selector_mixed',
+ it is required for proper functioning, please add it and try again.
+
+"
+ end
+
+ # conflicts with rvm/capistrano/selector
+ class << self
+ def run(cmd, options={}, &block)
+ if options[:eof].nil? && !cmd.include?(sudo)
+ options = options.merge(:eof => !block_given?)
+ end
+ shell = options[:shell]
+ options[:shell] = false
+
+ parallel(options) do |session|
+ if shell.nil?
+ session.when "in?(:#{fetch(:rvm_require_role,nil)})", command_with_shell(cmd, fetch(:rvm_shell)), &block
+ end
+ session.else command_with_shell(cmd, shell), &block
+ end
+ end
+
+ def command_with_shell(cmd, shell=nil)
+ if shell == false
+ cmd
+ else
+ "#{shell || "sh"} -c #{quote_and_escape(cmd)}"
+ end
+ end
+
+ end
+end
View
2 lib/rvm/capistrano/version.rb
@@ -1,5 +1,5 @@
module RVM
class Capistrano
- VERSION="1.4.0.rc1"
+ VERSION="1.4.0.rc2"
end
end

0 comments on commit bacfd9c

Please sign in to comment.