#!/bin/bash # # Installer # function __rvm_install-source { if [ -z "$rvm_selected" ] ; then __rvm_select $* ; fi __rvm_log "info" "Installing Ruby from source to: $rvm_ruby_home" mkdir -p $rvm_ruby_log_path pushd $rvm_source_path > /dev/null if [ ! -z "$rvm_force" ] ; then rm -rf $rvm_ruby_home rm -rf $rvm_ruby_src_path fi if [ -z "$rvm_ruby_tag" -a -z "$rvm_ruby_rev" ] ; then if [ ! -d $rvm_ruby_src_path ] ; then rvm_url="${rvm_url:-"ftp://ftp.ruby-lang.org/pub/ruby/1.$rvm_major_version/$rvm_ruby_package_name.tar.gz"}" __rvm_log "info" "\tDownloading $rvm_ruby_package_name, this may take a while depending on your connection..." __rvm_fetch $rvm_url __rvm_log "info" "\tExtracting $rvm_ruby_package_name ..." mkdir -p $rvm_ruby_src_path # Is this line necessary considering -C below? v __rvm_run "extract" tar xzf $rvm_archives_path/$rvm_ruby_package_name.tar.gz -C $rvm_source_path fi else __rvm_log "info" "\tRetrieving Ruby from $rvm_url" if [ ! -z "`echo $rvm_url | grep '^git'`" ] ; then if [ -d "$rvm_ruby_src_path/.git" ] ; then cd $rvm_ruby_src_path if [ -z "$rvm_ruby_rev" ] ; then git pull origin master else git checkout ${rvm_ruby_rev:-HEAD} fi else git clone --depth 1 $rvm_ruby_repo_url $rvm_ruby_src_path fi else if [ -z "$rvm_ruby_rev" ] ; then # TODO: Check if tag v is valid rvm_url=$rvm_ruby_repo_url/tags/$rvm_ruby_tag rvm_rev="" else if [ "$rvm_ruby_rev" = "head" -o "$rvm_ruby_rev" = "trunk" ] ; then rvm_url=$rvm_ruby_repo_url/branches/ruby_1_${rvm_major_version}_${rvm_minor_version} rvm_rev="" else rvm_url=$rvm_ruby_repo_url/branches/ruby_1_${rvm_major_version}_${rvm_minor_version} rvm_rev="-r $rvm_ruby_rev" fi fi if [ -d "$rvm_ruby_src_path/.svn" ] ; then cd $rvm_ruby_src_path svn checkout -q $rvm_rev else svn checkout -q $rvm_rev --force $rvm_url $rvm_ruby_src_path fi fi fi cd $rvm_ruby_src_path if [ $? -gt 0 ] ; then __rvm_log "error" "There was an error, please check $rvm_ruby_log_path/*.error.log" ; popd 2> /dev/null ; return 1 ; fi if [ ! -s "$rvm_ruby_src_path/configure" -a "$rvm_ruby_interpreter" = "ruby" ] ; then rvm_autoconf=`which autoconf` if [ $? -ne 0 ] ; then __rvm_log "fail" "rvm expects autoconf" ; fi __rvm_run "autoconf" $rvm_autoconf fi if [ $? -gt 0 ] ; then __rvm_log "error" "There was an error, please check $rvm_ruby_log_path/*.error.log" ; popd 2> /dev/null ; return 1 ; fi if [ -s ./Makefile -a -z "$rvm_re_configure" ] ; then __rvm_log "warn" "\tSkipping configure step, Makefile exists so configure must have already been run." elif [ -s ./configure ] ; then __rvm_log "info" "\tConfiguring $rvm_ruby_package_name using $rvm_ruby_configure, this may take a while depending on your cpu(s)..." __rvm_run "configure" ./configure --prefix=$rvm_ruby_home $rvm_ruby_configure else __rvm_log "warn" "\tSkipping configure step, 'configure' script does not exist, did autoconf not run successfully?" fi __rvm_log "info" "\tCompiling $rvm_ruby_package_name, this may take a while, depending on your cpu(s)..." if [ -z "$rvm_ruby_make" ] ; then __rvm_run "make" make else __rvm_run "make" $rvm_ruby_make fi if [ -z "$rvm_ruby_make" ] ; then __rvm_log "info" "\tInstalling $rvm_ruby_package_name" __rvm_run "install" make install else __rvm_run "install" $rvm_ruby_make_install fi __rvm_run "chmod.bin" chmod +x $rvm_ruby_home/bin/* __rvm_bin_scripts __rvm_log "info" "Installation of $rvm_ruby_package_name is complete." __rvm_log "info" "\tInstalling rubygems dedicated to $rvm_ruby_package_name..." rvm_gem_package_name="rubygems-1.3.5" rvm_gem_url="http://rubyforge.org/frs/download.php/60718/$rvm_gem_package_name.tgz" if [ -d $rvm_source_path/$rvm_gem_package_name ] ; then cd $rvm_source_path/$rvm_gem_package_name else __rvm_fetch $rvm_gem_url mkdir -p $rvm_source_path/$rvm_gem_package_name __rvm_run "rubygems.extract" tar zxf $rvm_archives_path/$rvm_gem_package_name.tgz -C $rvm_source_path fi # Well this is fun... fix nil error on require_paths: sed -i.orig "s/require_paths\.join/require_paths.to_a.join/" $rvm_source_path/$rvm_gem_package_name/lib/rubygems/gem_path_searcher.rb __rvm_run "rubygems.install" $rvm_ruby_binary $rvm_source_path/$rvm_gem_package_name/setup.rb popd 2> /dev/null for binary in gem irb erb ri rdoc testrb rake ; do if [ -x $rvm_ruby_src_path/bin/$binary ] ; then cp $rvm_ruby_src_path/bin/$binary $rvm_ruby_home/bin/$binary string="ENV['GEM_HOME']=ENV['GEM_HOME'] || '$rvm_gem_home'\nENV['PATH']='$rvm_ruby_home/bin:$rvm_gem_home/bin:' + ENV['PATH']" awk "NR==2 {print \"$string\"} {print}" $rvm_ruby_home/bin/$binary > $rvm_ruby_home/bin/$binary.new mv $rvm_ruby_home/bin/$binary.new $rvm_ruby_home/bin/$binary chmod +x $rvm_ruby_home/bin/$binary else __rvm_log "warn" "$rvm_ruby_home/bin/$binary is missing" fi done for rvm_gem_name in rake ; do __rvm_log "info" "Installing $rvm_gem_name" __rvm_run "gems" $rvm_ruby_home/bin/gem install $rvm_gem_name --no-rdoc --no-ri -q done __rvm_log "info" "Installation of rubygems for $rvm_ruby_package_name is complete." if [ -x $rvm_gem_home/bin/$binary ] ; then string="ENV['GEM_HOME']=ENV['GEM_HOME'] || '$rvm_gem_home'\nENV['PATH']='$rvm_ruby_home/bin:$rvm_gem_home/bin:' + ENV['PATH']" mv $rvm_gem_home/bin/$binary $rvm_gem_home/bin/$binary.orig awk "NR==2 {print \"$string\"} {print}" $rvm_gem_home/bin/$binary.orig > $rvm_gem_home/bin/$binary chmod +x $rvm_gem_home/bin/$binary else __rvm_log "warn" "$rvm_gem_home/bin/$binary is missing" fi binary=rake if [ -x $rvm_ruby_home/bin/$binary ] ; then mv $rvm_ruby_home/bin/$binary $rvm_gem_home/bin/$binary.orig awk "NR==2 {print \"$string\"} {print}" $rvm_gem_home/bin/$binary.orig > $rvm_gem_home/bin/$binary else __rvm_log "warn" "$rvm_gem_home/bin/$binary is missing." fi unset binary } function __rvm_install-ruby { if [ -z "$rvm_selected" ] ; then __rvm_select $* ; fi if [ ! -z "$RUBYOPT" ] ; then ruby_options=$RUBYOPT ; unset RUBYOPT ; fi case "$rvm_ruby_interpreter" in macruby) if [ "`uname`" = "Darwin" ] ; then rvm_ruby_repo_url=$rvm_macruby_repo_url rvm_ruby_configure="" rvm_ruby_make="rake macruby:build framework_instdir=$rvm_path/macruby-head framework_name=/macruby-head --trace" rvm_ruby_make_install="rake framework:install framework_instdir=$rvm_path/macruby-head framework_name=/macruby-head --trace" #rvm_ruby_rev="${rvm_ruby_rev:-head}" # Hard coding this for now DESTDIR="$rvm_ruby_home" ; export DESTDIR if [ -z "$rvm_ruby_rev" ] ; then # TODO: Check if tag v is valid #rvm_ruby_repo_url=$rvm_ruby_repo_url/tags/$rvm_ruby_tag rvm_ruby_rev="head" # For now, until nightly release are available. else if [ "$rvm_ruby_rev" = "head" -o "$rvm_ruby_rev" = "trunk" ] ; then #rvm_ruby_repo_url=$rvm_ruby_repo_url/trunk rvm_ruby_rev="head" else #rvm_ruby_repo_url=$rvm_ruby_repo_url/trunk rvm_ruby_rev="-r $rvm_ruby_rev" fi fi __rvm_fetch $rvm_url __rvm_run /usr/sbin/installer -pkg $rvm_ruby_package_name.pkg -target "$rvm_path/$rvm_ruby_package_name/" #__rvm_install-source unset DESTDIR else __rvm_log "fail" "MacRuby can only be installed on a Darwin OS." fi ;; ruby-enterprise|ree) rvm_url="http://rubyforge.org/frs/download.php/58677/$rvm_ruby_package_name.tar.gz" __rvm_log "info" "Installing Ruby Enterprise Edition from source to: $rvm_ruby_home" pushd $rvm_source_path > /dev/null if [ -d $rvm_ruby_src_path ] ; then cd $rvm_ruby_src_path else __rvm_log "info" "\tDownloading $rvm_ruby_package_name, this may take a while depending on your connection..." __rvm_fetch $rvm_url if [ $? -gt 0 ] ; then __rvm_log "error" "There was an error, please check $rvm_ruby_log_path/*.error.log" ; popd 2> /dev/null ; return 1 ; fi __rvm_log "info" "\tExtracting $rvm_ruby_package_name..." mkdir -p $rvm_ruby_src_path __rvm_run "extract" tar xzf $rvm_archives_path/$rvm_ruby_package_name.tar.gz -C $rvm_source_path fi __rvm_log "info" "\tInstalling $rvm_ruby_package_name, this may take a while, depending on your cpu(s)..." mkdir -p $rvm_ruby_log_path cd $rvm_ruby_src_path __rvm_run "install" ./installer -a $rvm_path/ruby-enterprise-$rvm_ruby_version-$rvm_ruby_patch_level --dont-install-useful-gems --no-tcmalloc chmod +x $rvm_ruby_home/bin/* ln -fs $rvm_ruby_home/bin/ruby $rvm_path/bin/$rvm_ruby_package_name __rvm_log "info" "\tInstalling rubygems dedicated to $rvm_ruby_package_name..." rvm_gem_package_name="rubygems-1.3.5" rvm_gem_url="http://rubyforge.org/frs/download.php/60718/$rvm_gem_package_name.tgz" if [ -d $rvm_source_path/$rvm_gem_package_name ] ; then cd $rvm_source_path/$rvm_gem_package_name else __rvm_fetch $rvm_gem_url mkdir -p $rvm_source_path/$rvm_gem_package_name __rvm_run "extract" tar zxf $rvm_archives_path/$rvm_gem_package_name.tgz -C $rvm_source_path fi # Well this is fun... fix nil error on require_paths: sed -i.orig "s/require_paths\.join/require_paths.to_a.join/" $rvm_source_path/$rvm_gem_package_name/lib/rubygems/gem_path_searcher.rb > $rvm_ruby_log_path/rubygems.install.log 2> $rvm_ruby_log_path/rubygems.install.error.log __rvm_run "rubygems.install" $rvm_ruby_home/bin/ruby $rvm_source_path/$rvm_gem_package_name/setup.rb __rvm_log "info" "Installation of $rvm_ruby_package_name complete." popd 2> /dev/null for rvm_gem_name in rake ; do __rvm_log "info" "Installing $rvm_gem_name" __rvm_run "gems" $rvm_ruby_home/bin/gem install $rvm_gem_name --no-rdoc --no-ri -q done ;; rbx|rubinius) __rvm_reset # Requires 1.8 to install due to parsetree. TOOD: Check for 1.8 + parse-tree rvm_ruby_repo_url=$rvm_rubinius_repo_url rvm_ruby_configure="" rvm_ruby_make="rake" rvm_ruby_make_install="rake install" rvm_ruby_home="$rvm_path/$rvm_ruby_interpreter-$rvm_ruby_version" #rvm_ruby_rev="head" # TODO: Check if already git repo, then git pull origin master && build if [ ! -d $rvm_ruby_home -o ! -d $rvm_ruby_home/.git ] ; then rm -rf $rvm_ruby_home git clone --depth 1 $rvm_ruby_repo_url $rvm_ruby_home fi cd $rvm_ruby_home __rvm_run "build" $rvm_rubinius_jit rake build for binary in ruby irb ; do ln -fs $rvm_ruby_home/bin/rbx $rvm_ruby_home/bin/$binary done ;; jruby) rvm_package_file="$rvm_ruby_interpreter-bin-$rvm_ruby_version" rvm_url="http://dist.codehaus.org/$rvm_ruby_interpreter/$rvm_ruby_version/$rvm_package_file.zip" rvm_jruby_repo_url="${rvm_jruby_repo_url:-"git://kenai.com/jruby~main"}" __rvm_log "info" "Installing jRuby to: $rvm_ruby_home" mkdir -p $rvm_ruby_log_path pushd $rvm_source_path > /dev/null if [ ! -z "$rvm_ruby_rev" ] ; then if [ ! -d $rvm_path/$rvm_ruby_interpreter-$rvm_ruby_version -o ! -d $rvm_path/$rvm_ruby_interpreter-$rvm_ruby_version/.git ] ; then git clone --depth 1 $rvm_jruby_repo_url $rvm_ruby_src_path cd $rvm_ruby_src_path && ant fi else if [ -d $rvm_ruby_src_path ] ; then cd $rvm_ruby_src_path else __rvm_log "info" "\tDownloading $rvm_package_file, this may take a while depending on your connection..." __rvm_fetch $rvm_url __rvm_log "info" "\tExtracting $rvm_package_file..." __rvm_run "extract" unzip -q $rvm_archives_path/$rvm_package_file.zip -d $rvm_source_path cd $rvm_ruby_src_path fi fi __rvm_log "info" "\tInstalling $rvm_ruby_package_name..." mkdir -p $rvm_ruby_home/bin/ __rvm_run "sync" rsync -ag $rvm_ruby_src_path/ $rvm_ruby_home/ __rvm_run "nailgun" cd $rvm_ruby_src_path/tool/nailgun && make popd 2> /dev/null chmod +x $rvm_ruby_home/bin/* for binary in jruby jgem jirb ; do ln -fs $rvm_ruby_home/bin/$binary $rvm_ruby_home/bin/${binary#j} done ln -fs $rvm_ruby_home/bin/ruby $rvm_path/bin/$rvm_ruby_package_name for rvm_gem_name in rake jruby-openssl ; do __rvm_log "info" "Installing $rvm_gem_name" __rvm_run "gems" $rvm_ruby_home/bin/jgem install $rvm_gem_name --no-rdoc --no-ri -q done ;; ruby) if [ -z "rvm_ruby_configure" ] ; then rvm_ruby_configure="--enable-shared=true" ; fi __rvm_install-source $* ;; default) __rvm_log "fail" "please specify a ruby implementation to install." ;; *) __rvm_log "fail" "Ruby implementation '$rvm_ruby_interpreter' is not known." esac if [ ! -z "$ruby_options" ] ; then RUBYOPT=$ruby_options ; export RUBYOPT fi } function __rvm_uninstall { if [ -z "$rvm_selected" ] ; then __rvm_select $* ; fi if [ ! -z "$rvm_ruby_package_name" ] ; then for dir in $rvm_source_path $rvm_path ; do if [ -d $dir/$rvm_ruby_package_name ] ; then __rvm_log "info" "Removing $dir/$rvm_ruby_package_name..." rm -rf $dir/$rvm_ruby_package_name else __rvm_log "info" "it seems that $dir/$rvm_ruby_package_name is already non existent." fi if [ -e $rvm_bin_path/$rvm_ruby_package_name ] ; then rm -f $rvm_bin_path/$rvm_ruby_package_name fi done ; unset dir rm -rf $rvm_gem_path/$rvm_ruby_interpreter/$rvm_ruby_version*/ else __rvm_log "fail" "Cannot uninstall unknown package '$rvm_ruby_package_name'" fi }