lib/rconf/configurators/ruby_configurator.rb in rconf-0.6.10 vs lib/rconf/configurators/ruby_configurator.rb in rconf-0.6.11
- old
+ new
@@ -52,11 +52,10 @@
run
return true
when /^Using /
report_success
check_rvmrc
- post_note "Configuration required switching the active ruby\nPlease run " + 'cd ..;cd -'.blue + ' to activate it and re-run rconf'
aborting(true)
else
report_fatal("Failed to use #{version}:\n#{out}")
end
end
@@ -90,15 +89,17 @@
# true:: Always return true
def run_windows
end
# Set command prefix when already configured
+ # Re-create .rvmrc if needed
#
# === Return
# true:: Always return true
def post_process
Command.set_prefix("rvm #{version}@#{gemset} exec --")
+ check_rvmrc
true
end
protected
@@ -126,14 +127,14 @@
Command.execute('tar', 'zxf', "rvm-#{version}.tar.gz",
:abort_on_failure => "Failed to extract rvm tgz from #{File.join(Dir.getwd, 'rvm-' + version + '.tar.gz')}")
end
Dir.chdir(File.join(rvm_src, "rvm-#{version}")) do
Command.execute('./install', :abort_on_failure => "Failed to install rvm #{version}")
- setup_bashrc
end
report_success
end
+ setup_bashrc
true
end
# Install given ruby version using rvm
#
@@ -191,19 +192,21 @@
# Check .rvmrc and its content
#
# === Return
# true:: Always return true
def check_rvmrc
+ return true if File.exist?('.rvmrc')
report_check('Setting up .rvmrc')
begin
File.open('.rvmrc', 'w') do |f|
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', "#{version}@#{gemset}", 'trust', 'rvmrc')
report_success
+ post_note "Configuration required switching the active ruby\nPlease run " + 'cd ..;cd -'.blue + ' to activate it and re-run rconf'
rescue Exception => e
report_failure
report_error(e.message)
end
true
@@ -218,11 +221,21 @@
candidates.map! { |c| File.join(ENV['HOME'], c) }
bashrc_path = candidates.detect { |c| File.exist?(c) }
if bashrc_path
content = IO.read(bashrc_path)
unless content.include?(rvm_bash_activation)
- content = rvm_bash_activation + "\n" + content
+ i = content.index(/^\s*PATH=[^$PATH]/)
+ if i
+ next_line = content.index("\n", i + 1)
+ if next_line
+ content.insert(next_line + 1, rvm_bash_activation + "\n")
+ else
+ content += "\n" + rvm_bash_activation
+ end
+ else
+ content = rvm_bash_activation + "\n" + content
+ end
FileUtils.mv(bashrc_path, bashrc_path + '.old')
File.open(bashrc_path, 'w') { |f| f.puts content }
post_note 'rvm was installed, please reload your shell to activate it and re-run rconf'
aborting(true)
end
@@ -235,9 +248,10 @@
#
# === Return
# code(String):: Code that needs to be added to bashrc to activate rvm
def rvm_bash_activation
code = <<EOS
+export rvm_trust_rvmrcs_flag=1
if [[ -n "$PS1" ]]; then
if [[ -s $HOME/.rvm/scripts/rvm ]] ; then source $HOME/.rvm/scripts/rvm ; fi
fi
EOS
end