lib/rconf/configurators/ruby_configurator.rb in rconf-1.0.7 vs lib/rconf/configurators/ruby_configurator.rb in rconf-1.0.8

- old
+ new

@@ -20,10 +20,18 @@ description "Installs ruby interpreter and rubygems.\n" + 'Installs and uses rbenv on supported (i.e. non-Windows) platforms' setting 'version', 'Ruby version using rbenv notation (see "rbenv versions")', :required => true + # Message to display to the user when rbenv isn't in the path. + PATH_ADVICE = "You should add 'eval \"$(rbenv init -)\"' to your .bash_profile / .bashrc etc. " + + "so rbenv is properly initialized in new shells.\n\n" + + "If you are a bash user (e.g. Mac OS X), you can add the following to ~/.bash_profile:\n\n" + + " echo 'eval \"$(rbenv init -)\"' >> ~/.bash_profile\n\n" + + "You should also update your PATH environment variable with:\n\n" + + " echo 'export PATH=\"$HOME/.rbenv/shims:$PATH\" >> ~/.bash_profile'\n" + # Let configurator run, it is idempotent # # === Return # false:: Always return false def check_linux @@ -61,47 +69,46 @@ def run_windows end protected - # Make version compatible with RVM + # Make our version specifier compatible with RVM-style specifiers (override base class accessor) def ruby_version @ruby_version ||= version.start_with?('ruby-') ? version[5..-1] : version end # Check whether rbenv and ruby-build are installed and installs it/them if not # # === Return # true:: Always return true def check_rbenv + rbenv_present = File.exist?(File.join(ENV['HOME'], '.rbenv', 'bin', 'rbenv')) + res = Command.execute('rbenv') rbenv_in_path = res.success? - if rbenv_in_path + + if rbenv_present && !rbenv_in_path + # Bail if rbenv isn't correctly initialized (we can't use it in this state) + post_note "rconf detected rbenv is installed in #{rbenv_path} but it is not in the PATH.\n" + PATH_ADVICE + aborting(true) + elsif rbenv_present && rbenv_in_path + # rbenv is installed and initialized; make sure we have a suitable version res.output =~ /^rbenv ([0-9]+)\.([0-9]+)\.([0-9]+)$/ maj, min, build = [$1.to_i, $2.to_i, $3.to_i] if maj == 0 && min < 4 - report_fatal("rconf requires rbenv version 0.4.0 or greater, you have #{maj}.#{min}.#{build} installed, please upgrade (e.g. via brew upgrade rbenv) and try again") + report_fatal("rconf requires rbenv version 0.4.0 or greater, you have #{maj}.#{min}.#{build} installed, "+ + "please upgrade (e.g. via 'brew upgrade rbenv') and try again") end - return true - end - rbenv_present = File.exist?(File.join(ENV['HOME'], '.rbenv', 'bin', 'rbenv')) - update_msg = "You should add 'eval \"$(rbenv init -)\"' to your .bash_profile / .bashrc etc. " + - "so rbenv is properly initialized in new shells, the following assumes ~/.bash_profile is used (Mac OS X):\n\n" + - "echo 'eval \"$(rbenv init -)\"' >> ~/.bash_profile\n\n".blue + - "You should also update your PATH environment variable with:\n\n" + - "echo 'export PATH=\"$HOME/.rbenv/shims:$PATH\" >> ~/.bash_profile'\n".blue - if rbenv_present - post_note "rconf detected rbenv is installed in #{rbenv_path} but it is not in the PATH.\n" + update_msg - aborting(true) - return true else + # No sign of rbenv; try to install it opts = { :report => true, :post_install => update_msg }.merge(abort_option('Failed to install rbenv')) PackageInstaller.install('rbenv', opts) opts = { :report => true }.merge(abort_option('Failed to install ruby-build')) PackageInstaller.install('ruby-build', opts) - true end + + true end # Check .ruby-version and its content # # === Return @@ -110,9 +117,16 @@ unless Command.execute('rbenv', 'local', ruby_version).success? report_check("Installing ruby #{ruby_version} (this will take a while, please be patient)") Platform.dispatch(ruby_version) { :install_ruby } Command.execute('rbenv', 'local', ruby_version) end + + which = Command.execute('which', 'ruby').output.strip + if (which =~ %r(^(/usr)?/bin.*ruby$)) + post_note "Your PATH is not setup correctly for rbenv; ('which ruby' => #{which}).\n" + PATH_ADVICE + aborting(true) + end + true end # Install given ruby version using rbenv # Install any prerequesites first