lib/rconf/configurators/ruby_configurator.rb in rconf-0.5.3 vs lib/rconf/configurators/ruby_configurator.rb in rconf-0.5.5
- old
+ new
@@ -21,62 +21,66 @@
register :ruby
description "Installs ruby interpreter and rubygems.\n" +
'Installs and uses rvm on supported (i.e. non-Windows) platforms'
- settings :ruby_version => 'Ruby version using rvm notation (see "rvm list known")',
- :rubygems_version => 'Rubygems version, e.g. "1.3.7"',
- :gemset => 'Gemset to be used for platforms supporting rvm'
+ settings :version => 'Ruby version using rvm notation (see "rvm list known")',
+ :rubygems => 'Rubygems version, e.g. "1.3.7"',
+ :gemset => 'Gemset to be used for platforms supporting rvm'
- validate_has_settings :ruby_version, :rubygems_version
+ validate_has_settings :version, :rubygems
# Switch to ruby version defined in settings
# Use rvm and install it if needed
#
# === Return
# true:: Always return true
def run_linux
check_rvm(RVM_VERSION)
- report_check("Checking whether #{ruby_version} is the active ruby")
+ report_check("Checking whether #{version} is the active ruby")
out = Command.execute('rvm', 'list').output
- if out =~ /^=> #{ruby_version.gsub('.', '\\.')}/
+ if out =~ /^=> #{version.gsub('.', '\\.')}/
report_success
else
report_failure
- report_check("Switching to #{ruby_version}")
- out = Command.execute('rvm', 'use', ruby_version).output
+ report_check("Switching to #{version}")
+ out = Command.execute('rvm', 'use', version).output
case out
when /is not installed\./
report_failure
report_fatal "Failed to install #{ruby}: #{@out}" if @out
- @out = install_ruby(ruby_version)
+ @out = install_ruby(version)
run
return true
when /^Using /
report_success
check_rvmrc
- Command.execute('rvm', ruby_version, 'exec', 'gem', 'install', 'rconf',
- :abort_on_failure => "Failed to install rconf gem in #{ruby_version}")
+ Command.execute('rvm', version, 'exec', 'gem', 'install', 'rconf',
+ :abort_on_failure => "Failed to install rconf gem in #{version}")
post_note "Configuration required switching the active ruby\nPlease 'cd' into the project directory again to activate it"
else
- report_fatal("Failed to use #{ruby_version}:\n#{out}")
+ report_fatal("Failed to use #{version}:\n#{out}")
end
end
if gemset
- report_check("Switching to gemset #{gemset}")
- res = Command.execute('rvm', ruby_version, 'gemset', 'list')
- unless res.output =~ /^#{gemset}$/
- report_check("Creating gemset #{gemset} for #{ruby_version}")
- Command.execute('rvm', ruby_version, 'gemset', 'create', gemset,
+ report_check("Checking whether gemset #{gemset} exists")
+ res = Command.execute('rvm', version, 'gemset', 'list')
+ if res.output =~ /^#{gemset}$/
+ report_success
+ else
+ report_fail
+ report_check("Creating gemset #{gemset} for #{version}")
+ Command.execute('rvm', version, 'gemset', 'create', gemset,
:abort_on_failure => "Failed to create gemset '#{gemset}'")
report_success
end
- Command.execute('rvm', ruby_version, 'gemset', 'use', gemset,
+ report_check("Switching to gemset #{gemset}")
+ Command.execute('rvm', version, 'gemset', 'use', gemset,
:abort_on_failure => "Failed to switch to gemset '#{gemset}'")
report_success
end
- Command.set_prefix("rvm #{ruby_version}@#{gemset} exec --")
+ Command.set_prefix("rvm #{version}@#{gemset} exec --")
true
end
alias :run_darwin :run_linux
# Switch to ruby version defined in settings
@@ -128,24 +132,63 @@
# ruby(String):: Ruby version compatible with rvm
#
# === Return
# out(String):: Installation output
def install_ruby(ruby)
+ Platform.dispatch(ruby) { :install_ruby_prerequesites }
report_check("Installing #{ruby} (this will take a while, please be patient)")
res = Command.execute('rvm', 'install', ruby)
report_result(res.success?)
res.output
end
+ # Make sure to install all required linux packages first
+ #
+ # === Return
+ # true:: Always return true
+ def install_ruby_prerequesites_linux_ubuntu(ruby)
+ report_check("Installing required packages, this could take a while")
+ packages = []
+ if ruby =~ /^ree-|^ruby-/
+ packages = %w(build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev)
+ end # TBD Define packages needed for other rubies
+ Command.execute('sudo', 'aptitude', 'install', *packages)
+ report_success
+ end
+
+ # Make sure to install all required CentOS / RedHhat packages first
+ # NOTE: For centos 5.4 final iconv-devel might not be available :(
+ #
+ # === Return
+ # true:: Always return true
+ def install_ruby_prerequesites_linux_centos(ruby)
+ report_check("Installing required packages, this could take a while")
+ packages = []
+ if ruby =~ /^ree-|^ruby-/
+ packages = %w(gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel iconv-devel)
+ end # TBD Define packages needed for other rubies
+ Command.execute('sudo', 'yum', 'install', '-y', *packages)
+ report_success
+ end
+ alias :install_ruby_prerequesites_linux_redhat :install_ruby_prerequesites_linux_centos
+
+ # No pre-requesites to install ree or Matz ruby on Mac (TBD others)
+ #
+ # === Return
+ # true:: Always return true
+ def install_ruby_prerequesites_darwin(ruby)
+ true
+ end
+
# Check .rvmrc and its content
#
# === Return
# true:: Always return true
def check_rvmrc
report_check('Setting up .rvmrc')
begin
File.open('.rvmrc', 'w') do |f|
- f.puts "rvm #{ruby_version}@#{gemset}"
+ f.puts "rvm #{version}@#{gemset}"
f.puts "type -P rconf &>/dev/null && { rconf; }"
f.puts "type -P rconf &>/dev/null || { echo 'rconf not installed, skipping (see .rvmrc)'; }"
end
Command.execute('rvm', 'trust', 'rvmrc')
report_success