bash/rvm in rvm-0.0.22 vs bash/rvm in rvm-0.0.23

- old
+ new

@@ -1,12 +1,12 @@ #!/bin/bash -rvm_author="Wayne E. Seguin" -rvm_author_email="wayneeseguin@gmail.com" -rvm_website="http://rvm.beginrescueend.com/" -rvm_version="0.0.22" -rvm_updated="2009.08.25" +rvm_meta_author="Wayne E. Seguin" +rvm_meta_author_email="wayneeseguin@gmail.com" +rvm_meta_website="http://rvm.beginrescueend.com/" +rvm_meta_version="0.0.23" +rvm_meta_updated="2009.08.25" # # License: See LICENSE # @@ -38,33 +38,36 @@ use - Switch to using a specific ruby version (new login shell) info - Show information for current ruby list - Show currently installed versions gemdir - Switch to gem directory for installation (new login shell) srcdir - Switch to src directory for the current ruby installation - gemdup - Clone source version gems to current version + gemdup - Clone source version gems to current version (highly expiramental) Example: rvm gemdup ~/.gem/ruby/1.8/ install - Install a ruby version, default is from source uninstall - Uninstall a ruby version reset - Remove default and current settings, exit the shell. (If you experience odd behavior try this first) + reload - Reload rvm source itself (useful after changing rvm source) debug - Emit environment & configuration information for *current* ruby Implementation: * ruby - MRI/YARV Ruby (The Standard), defaults to 1.8.6 jruby - jRuby ree - Ruby Enterprise Edition default - Resets to the default system ruby all - Used with install, installs all latest known versions - - Options: + Options: + -v|--version - Ruby Package Version, defaults to 'latest' -l|--level - Patch level for the specified Ruby version -p|--prefix - Package and source directory prefix, with trailing slash! Default is a users home directory and /usr/local/ for root -c|--configure - Options for source compile (default: --enable-shared) + -a|--archives - Directory to place downladed files into (~/.rvm/archives/) + -n|--nice - Niceness level (default: 0) -d|--debug - Toggle debug mode on for extra messages (NYI) Notes: * Defaults above are denoted with a '*' prefix. @@ -89,40 +92,15 @@ $ rvm uninstall 1.8.7 # Uninstall rvm installed 1.8.7 version $ rvm gemdup default # Install gems from ~/.gem/ruby/1.8/ TODO: (in order) - * rvm gemdup + * rvm gemdup * root support * Settings file, user overridable * Show current in rvm list, if applicable - Many Thanks: - - Bash Support Testing - - - Daniel Neighman (dneighman@gmail.com) - irc: hassox ; github: http://github.com/hassox - - - John Mettraux (jmettraux@openwfe.org) - irc: jmettraux ; github: http://github.com/jmettraux - - ZSH Support Testing - - - Franco Lazzarino (flazzarino@gmail.com) - irc: flazz ; github: http://github.com/flazz - - Ubuntu Linux Support Testing - - - Anita Kuno (anteaya@anteaya.info) - irc: anteaya ; github: http://github.com/anteaya - - Website Design - - - Jim Lindley (jlindley@gmail.com) - irc: jlindley ; github: http://github.com/jlindley - Usage } # Logging functions based on level @@ -146,185 +124,200 @@ platform: "$(ruby -v | sed 's/^.*\[//' | sed 's/\].*$//')" patchlevel: "$(ruby -v | sed 's/^.*(//' | sed 's/).*$//')" full_version: "$(ruby -v)" homes: - gem: "${GEM_HOME-not set}" - ruby: "${MY_RUBY_HOME-not set}" + gem: "${GEM_HOME:-not set}" + ruby: "${MY_RUBY_HOME:-not set}" binaries: ruby: "$(which ruby)" irb: "$(which irb)" gem: "$(which gem)" Info } +function rvm-curl { + pushd $rvm_archives_path > /dev/null + eval $rvm_curl "$1" + popd > /dev/null +} + function rvm-install-source { - version="${1:-1.8.6}" - case "$version" in - 1.9|1.9.1) major="1.9" ; minor="1" ; level="${2-243}" ;; - 1.9.2) major="1.9" ; minor="2" ; level="${2-review1}" ;; - 1.8|1.8.6) major="1.8" ; minor="6" ; level="${2-369}" ;; - 1.8.7) major="1.8" ; minor="7" ; level="${2-174}" ;; - *) rvm-log-fail "Ruby version '$version' is unknown." + rvm_version="${1:-1.8.6}" + case "$rvm_version" in + 1.9|1.9.1) rvm_major="1.9" ; rvm_minor="1" ; rvm_patch_level="${2:-243}" ;; + 1.9.2) rvm_major="1.9" ; rvm_minor="2" ; rvm_patch_level="${2:-review1}" ;; + 1.8|1.8.6) rvm_major="1.8" ; rvm_minor="6" ; rvm_patch_level="${2:-369}" ;; + 1.8.7) rvm_major="1.8" ; rvm_minor="7" ; rvm_patch_level="${2:-174}" ;; + *) rvm-log-fail "Ruby version '$rvm_version' is unknown." esac - package_name="ruby-$major.$minor-p$level" - url="ftp://ftp.ruby-lang.org/pub/ruby/$major/$package_name.tar.gz" - - rvm-log-info "Installing Ruby from source to: $install_path/$package_name" - mkdir -p $install_path/$package_name - - pushd $source_path > /dev/null - if [ -d $package_name ] ; then - cd $package_name + rvm_package_name="ruby-$rvm_major.$rvm_minor-p$rvm_patch_level" + rvm_url="ftp://ftp.ruby-lang.org/pub/ruby/$major/$rvm_package_name.tar.gz" + + rvm-log-info "Installing Ruby from source to: $rvm_install_path/$rvm_package_name" + mkdir -p $rvm_log_path/$rvm_package_name + + pushd $rvm_source_path > /dev/null + if [ -d $rvm_package_name ] ; then + cd $rvm_package_name else - if [ ! -f "$package_name.tar.gz" ] ; then - rvm-log-info "\tDownloading $package_name, this may take a while depending on your connection..." - eval $curl $url + if [ ! -f "$rvm_archives_path/$rvm_package_name.tar.gz" ] ; then + rvm-log-info "\tDownloading $rvm_package_name, this may take a while depending on your connection..." + rvm-curl $rvm_url fi - rvm-log-info "\tExtracting $package_name..." - tar xzf $package_name.tar.gz && cd $package_name + rvm-log-info "\tExtracting $rvm_package_name..." + mkdir -p $rvm_source_path/$rvm_package_name + nice -n $niceness tar xzf $rvm_archives_path/$rvm_package_name.tar.gz -C $rvm_source_path fi - rvm-log-info "\tConfiguring $package_name using ${configure-'--enable-shared'}, this may take a while depending on your cpu(s)..." - ./configure --prefix=$install_path/$package_name ${configure-'--enable-shared'} > $install_path/$package_name/configure.log 2> $install_path/$package_name/configure.error.log + cd $rvm_source_path/$rvm_package_name + rvm-log-info "\tConfiguring $rvm_package_name using ${configure:-"--enable-shared"}, this may take a while depending on your cpu(s)..." + nice -n $niceness ./configure --prefix=$rvm_install_path/$rvm_package_name ${configure:-"--enable-shared"} > $rvm_log_path/$rvm_package_name/configure.log 2> $rvm_log_path/$rvm_package_name/configure.error.log - rvm-log-info "\tCompiling $package_name, this may take a while, depending on your cpu(s)..." - make > $install_path/$package_name/make.log 2> $install_path/$package_name/make.error.log + rvm-log-info "\tCompiling $rvm_package_name, this may take a while, depending on your cpu(s)..." + nice -n $niceness make > $rvm_log_path/$rvm_package_name/make.log 2> $rvm_log_path/$rvm_package_name/make.error.log - rvm-log-info "\tInstalling $package_name" - make install > $install_path/$package_name/install.log 2> $install_path/$package_name/install.error.log - chmod +x $install_path/$package_name/bin/* + rvm-log-info "\tInstalling $rvm_package_name" + nice -n $niceness make install > $rvm_log_path/$rvm_package_name/install.log 2> $rvm_log_path/$rvm_package_name/install.error.log + chmod +x $rvm_install_path/$rvm_package_name/bin/* - # Create the ~/.rvm/bin/$package_name - ln -fs $install_path/$package_name/bin/ruby $install_path/bin/$package_name + ln -fs $rvm_install_path/$rvm_package_name/bin/ruby $rvm_install_path/bin/$rvm_package_name - # Now install rubygems for this ruby version. - rvm-log-info "\tInstalling rubygems dedicated to $package_name..." - gem_package_name="rubygems-1.3.5" - gem_url="http://rubyforge.org/frs/download.php/60718/$gem_package_name.tgz" - if [ -d $gem_package_name ] ; then - cd $gem_package_name + rvm-log-info "\tInstalling rubygems dedicated to $rvm_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 - if [ ! -f $gem_package_name.tgz ] ; then eval $curl $gem_url ; fi - tar zxf $gem_package_name.tgz && cd $gem_package_name + if [ ! -f "$rvm_archives_path/$rvm_gem_package_name.tgz" ] ; then rvm-curl $rvm_gem_url ; fi + mkdir -p $rvm_source_path/$rvm_gem_package_name + nice -n $niceness 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 '' "s/require_paths\.join/require_paths.to_a.join/" $source_path/$package_name/$gem_package_name/lib/rubygems/gem_path_searcher.rb - $install_path/$package_name/bin/ruby ./setup.rb > $install_path/$package_name/rubygems.install.log 2> $install_path/$package_name/rubygems.install.error.log + 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 + + nice -n $niceness $rvm_install_path/$rvm_package_name/bin/ruby $rvm_source_path/$rvm_gem_package_name/setup.rb > $rvm_log_path/$rvm_package_name/rubygems.install.log 2> $rvm_log_path/$rvm_package_name/rubygems.install.error.log popd > /dev/null - rvm-log-info "Installation of $package_name complete." + rvm-log-info "Installation of $rvm_package_name complete." for gem_name in rake ; do rvm-log-info "Installing $gem_name" - $install_path/$package_name/bin/gem install $gem_name --no-rdoc --no-ri -q >> $install_path/$package_name/gems.install.log + nice -n $niceness $rvm_install_path/$rvm_package_name/bin/gem install $gem_name --no-rdoc --no-ri -q >> $rvm_log_path/$rvm_package_name/gems.install.log 2> $rvm_log_path/$rvm_package_name/gems.error.log done } function rvm-install-ruby { - ruby_options=$RUBYOPT ; unset RUBYOPT + if [ -z "$RUBYOPT" ] ; then + ruby_options=$RUBYOPT ; unset RUBYOPT + fi - case "$implementation" in + case "$rvm_implementation" in ree) - version=${version-1.8.6} - patchlevel=${patchlevel-20090610} - package_name="ruby-enterprise-$version-$patchlevel" - url="http://rubyforge.org/frs/download.php/58677/$package_name.tar.gz" - rvm-log-info "Installing Ruby Enterprise Edition from source to: $install_path/$package_name" - pushd $source_path > /dev/null - if [ -d $package_name ] ; then - cd $package_name + rvm_version=${rvm_version:-1.8.6} + rvm_patchlevel=${rvm_patchlevel:-20090610} + rvm_package_name="ruby-enterprise-$rvm_version-$rvm_patchlevel" + rvm_url="http://rubyforge.org/frs/download.php/58677/$rvm_package_name.tar.gz" + rvm-log-info "Installing Ruby Enterprise Edition from source to: $rvm_install_path/$rvm_package_name" + pushd $rvm_source_path > /dev/null + if [ -d $rvm_source_path/$rvm_package_name ] ; then + cd $rvm_source_path/$rvm_package_name else - if [ ! -f "$package_name.tar.gz" ] ; then - rvm-log-info "\tDownloading $package_name, this may take a while depending on your connection..." - eval $curl $url + if [ ! -f "$rvm_archives_path/$rvm_package_name.tar.gz" ] ; then + rvm-log-info "\tDownloading $rvm_package_name, this may take a while depending on your connection..." + rvm-curl $rvm_url fi - rvm-log-info "\tExtracting $package_name..." - tar xzf $package_name.tar.gz && cd $package_name + rvm-log-info "\tExtracting $rvm_package_name..." + mkdir -p $rvm_source_path/$rvm_package_name + nice -n $niceness tar xzf $rvm_archives_path/$rvm_package_name.tar.gz -C $rvm_source_path fi - rvm-log-info "\tInstalling $package_name, this may take a while, depending on your cpu(s)..." - mkdir -p $install_path/$package_name - ./installer -a $install_path/ruby-enterprise-$version-$patchlevel --dont-install-useful-gems > $install_path/$package_name/install.log 2> $install_path/$package_name/install.error.log - chmod +x $install_path/$package_name/bin/* + rvm-log-info "\tInstalling $rvm_package_name, this may take a while, depending on your cpu(s)..." + mkdir -p $rvm_log_path/$rvm_package_name - ln -fs $install_path/$package_name/bin/ruby $install_path/bin/$package_name + cd $rvm_source_path/$rvm_package_name + nice -n $niceness ./installer -a $rvm_install_path/ruby-enterprise-$rvm_version-$rvm_patchlevel --dont-install-useful-gems > $rvm_log_path/$rvm_package_name/install.log 2> $rvm_log_path/$rvm_package_name/install.error.log + chmod +x $rvm_install_path/$rvm_package_name/bin/* - rvm-log-info "\tInstalling rubygems dedicated to $package_name..." - gem_package_name="rubygems-1.3.5" - gem_url="http://rubyforge.org/frs/download.php/60718/$gem_package_name.tgz" - if [ -d $gem_package_name ] ; then - cd $gem_package_name + ln -fs $rvm_install_path/$rvm_package_name/bin/ruby $rvm_install_path/bin/$rvm_package_name + + rvm-log-info "\tInstalling rubygems dedicated to $rvm_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 - if [ ! -f $gem_package_name.tgz ] ; then eval $curl $gem_url ; fi - tar zxf $gem_package_name.tgz && cd $gem_package_name + if [ ! -f "$rvm_archives_path/$rvm_gem_package_name.tgz" ] ; then rvm-curl $rvm_gem_url ; fi + mkdir -p $rvm_source_path/$rvm_gem_package_name + nice -n $niceness 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 '' "s/require_paths\.join/require_paths.to_a.join/" $source_path/$package_name/$gem_package_name/lib/rubygems/gem_path_searcher.rb - $install_path/$package_name/bin/ruby ./setup.rb > $install_path/$package_name/rubygems.install.log 2> $install_path/$package_name/rubygems.install.error.log - rvm-log-info "Installation of $package_name complete." + 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_log_path/$rvm_package_name/rubygems.install.log 2> $rvm_log_path/$rvm_package_name/rubygems.install.error.log + + nice -n $niceness $rvm_install_path/$rvm_package_name/bin/ruby $rvm_source_path/$rvm_gem_package_name/setup.rb > $rvm_log_path/$rvm_package_name/rubygems.install.log 2> $rvm_log_path/$rvm_package_name/rubygems.install.error.log + rvm-log-info "Installation of $rvm_package_name complete." popd > /dev/null - + for gem_name in rake ; do rvm-log-info "Installing $gem_name" - $install_path/$package_name/bin/gem install $gem_name --no-rdoc --no-ri -q >> $install_path/$package_name/gems.install.log + nice -n $niceness $rvm_install_path/$rvm_package_name/bin/gem install $gem_name --no-rdoc --no-ri -q >> $rvm_log_path/$rvm_package_name/gems.install.log 2> $rvm_log_path/$rvm_package_name/gems.error.log done ;; jruby) - version=${version-1.3.1} # 1.2.0, 1.3.1 - unset patchlevel # No patchlevel for jRuby - zipfile="$implementation-bin-$version" - package_name="$implementation-$version" - url="http://dist.codehaus.org/$implementation/$version/$zipfile.zip" + rvm_version=${rvm_version:-1.3.1} # 1.2.0, 1.3.1 + unset rvm_patchlevel # No patchlevel for jRuby + rvm_package_file="$rvm_implementation-bin-$rvm_version" + rvm_package_name="$rvm_implementation-$rvm_version" + rvm_url="http://dist.codehaus.org/$rvm_implementation/$rvm_version/$rvm_package_file.zip" - rvm-log-info "Installing jRuby to: $install_path/$package_name" - mkdir -p $install_path/$package_name - pushd $source_path > /dev/null - if [ -d $zipfile ] ; then - cd $zipfile + rvm-log-info "Installing jRuby to: $rvm_install_path/$rvm_package_name" + mkdir -p $rvm_log_path/$rvm_package_name + pushd $rvm_source_path > /dev/null + if [ -d $rvm_package_name ] ; then + cd $rvm_source_path/$rvm_package_name else - if [ ! -f "$zipfile.zip" ] ; then - rvm-log-info "\tDownloading $zipfile, this may take a while depending on your connection..." - eval $curl $url + if [ ! -f "$rvm_archives_path/$rvm_package_file.zip" ] ; then + rvm-log-info "\tDownloading $rvm_package_file, this may take a while depending on your connection..." + rvm-curl $rvm_url fi - rvm-log-info "\tExtracting $zipfile..." - jar xf $zipfile.zip + rvm-log-info "\tExtracting $rvm_package_file..." + nice -n $niceness unzip -q $rvm_archives_path/$rvm_package_file.zip -d $rvm_source_path fi - rvm-log-info "\tInstalling $package_name..." - mkdir -p $install_path/$package_name/bin/ - rsync -ag $source_path/$package_name/ $install_path/$package_name/ - cd $source_path/$package_name/tool/nailgun && make > $install_path/$package_name/install.nailgun.log 2> $install_path/$package_name/install.error.nailgun.log + rvm-log-info "\tInstalling $rvm_package_name..." + mkdir -p $rvm_install_path/$rvm_package_name/bin/ + rsync -ag $rvm_source_path/$rvm_package_name/ $rvm_install_path/$rvm_package_name/ + cd $rvm_source_path/$rvm_package_name/tool/nailgun && make > $rvm_log_path/$rvm_package_name/install.nailgun.log 2> $rvm_log_path/$rvm_package_name/install.error.nailgun.log popd > /dev/null - chmod +x $install_path/$package_name/bin/* + chmod +x $rvm_install_path/$rvm_package_name/bin/* for binary in jruby jgem jirb ; do - ln -fs $install_path/$package_name/bin/$binary $install_path/$package_name/bin/${binary#j} + ln -fs $rvm_install_path/$rvm_package_name/bin/$binary $rvm_install_path/$rvm_package_name/bin/${binary#j} done - ln -fs $install_path/$package_name/bin/ruby $install_path/bin/$package_name + ln -fs $rvm_install_path/$rvm_package_name/bin/ruby $rvm_install_path/bin/$rvm_package_name for gem_name in rake jruby-openssl ; do rvm-log-info "Installing $gem_name" - $install_path/$package_name/bin/jgem install $gem_name --no-rdoc --no-ri -q >> $install_path/$package_name/gems.install.log + nice -n $niceness $rvm_install_path/$rvm_package_name/bin/jgem install $gem_name --no-rdoc --no-ri -q >> $rvm_log_path/$rvm_package_name/gems.install.log 2> $rvm_log_path/$rvm_package_name/gems.error.log done ;; ruby) - rvm-install-source ${version-1.8.6} ${patchlevel-$3} + rvm-install-source ${rvm_version:-1.8.6} ${rvm_patchlevel:-$3} ;; default) rvm-log-fail "please specify a ruby implementation to install." ;; - *) rvm-log-fail "Ruby implementation '$implementation' is not known." + *) rvm-log-fail "Ruby implementation '$rvm_implementation' is not known." esac if [ ! -z "$ruby_options" ] ; then RUBYOPT=$ruby_options ; export RUBYOPT @@ -332,154 +325,154 @@ } function rvm-uninstall { - implementation="${1-$implementation}" - case "$implementation" in + rvm_implementation="${1:-$rvm_implementation}" + case "$rvm_implementation" in jruby) - version="${version-1.3.1}" - if [ "$version" = "1.2.0" -o "$version" = "1.3.1" ] ; then - package_name="jruby*-$version" + rvm_version="${rvm_version:-1.3.1}" + if [ "$rvm_version" = "1.2.0" -o "$rvm_version" = "1.3.1" ] ; then + rvm_package_name="jruby*-$rvm_version" else - rvm-log-fail "Unknown jRuby version: $version" + rvm-log-fail "Unknown jRuby version: $rvm_version" fi ;; ree) - version=${version-1.8.6} - if [ "$version" = "1.8.6" ] ; then - package_name="ruby-enterprise-$version-${3-20090610}" + rvm_version=${rvm_version:-1.8.6} + if [ "$rvm_version" = "1.8.6" ] ; then + rvm_package_name="ruby-enterprise-$rvm_version-${3:-20090610}" else - rvm-log-fail "Unknown Ruby Enterprise Edition version: $version" + rvm-log-fail "Unknown Ruby Enterprise Edition version: $rvm_version" fi ;; ruby) - if [ "$version" = "1.8.7" ] ; then - package_name="ruby-1.8.7-p${patchlevel-174}" + if [ "$rvm_version" = "1.8.7" ] ; then + rvm_package_name="ruby-1.8.7-p${rvm_patchlevel:-174}" - elif [ "$version" = "1.8.6" -o "$version" = "1.8" ] ; then - package_name="ruby-1.8.6-p${patchlevel-369}" + elif [ "$rvm_version" = "1.8.6" -o "$rvm_version" = "1.8" ] ; then + rvm_package_name="ruby-1.8.6-p${rvm_patchlevel:-369}" - elif [ "$version" = "1.9.2" ] ; then - package_name="ruby-1.9.2-p${patchlevel-review1}" + elif [ "$rvm_version" = "1.9.2" ] ; then + rvm_package_name="ruby-1.9.2-p${rvm_patchlevel:-review1}" - elif [ "$version" = "1.9.1" -o "$version" = "1.9" ] ; then - package_name="ruby-1.9.1-p${patchlevel-243}" + elif [ "$rvm_version" = "1.9.1" -o "$rvm_version" = "1.9" ] ; then + rvm_package_name="ruby-1.9.1-p${rvm_patchlevel:-243}" else - rvm-log-fail "Unknown ruby version: $version" + rvm-log-fail "Unknown ruby version: $rvm_version" fi ;; *) - rvm-log-fail "Ruby implementation '$implementation' is not known." + rvm-log-fail "Ruby implementation '$rvm_implementation' is not known." esac - if [ ! -z "$package_name" ] ; then - for path in $source_path $install_path ; do - if [ -d $path/$package_name ] ; then - rvm-log-info "Removing $path/$package_name..." - rm -rf $path/$package_name + if [ ! -z "$rvm_package_name" ] ; then + for path in $rvm_source_path $rvm_install_path ; do + if [ -d $path/$rvm_package_name ] ; then + rvm-log-info "Removing $path/$rvm_package_name..." + rm -rf $path/$rvm_package_name fi done else - rvm-log-fail "Cannot uninstall unknown package '$package_name'" + rvm-log-fail "Cannot uninstall unknown package '$rvm_package_name'" fi } function rvm-use { - implementation="${1-$implementation}" - case "$implementation" in + rvm_implementation="${1:-$rvm_implementation}" + case "$rvm_implementation" in default) - rm -f $install_path/current - source $install_path/default + rm -f $rvm_install_path/current unset GEM_HOME MY_RUBY_HOME + source $rvm_install_path/default PATH="$default_path" ; export PATH ;; jruby) - version="${version-1.3.1}" - if [ "$version" = "1.2.0" -o "$version" = "1.3.1" ] ; then - MY_RUBY_HOME="$install_path/jruby-$version" + rvm_version="${rvm_version:-1.3.1}" + if [ "$rvm_version" = "1.2.0" -o "$rvm_version" = "1.3.1" ] ; then + MY_RUBY_HOME="$rvm_install_path/jruby-$rvm_version" GEM_HOME="$HOME/.gem/jruby/1.8" alias ruby_ng="jruby --ng" alias ruby_ng_server="jruby --ng-server" else - rvm-log-fail "Unknown jRuby version: $version" + rvm-log-fail "Unknown jRuby version: $rvm_version" fi ;; ree) - version=${version-1.8.6} - if [ "$version" = "1.8.6" ] ; then - patchlevel="${3-20090610}" - MY_RUBY_HOME="$install_path/ruby-enterprise-$version-$patchlevel" + rvm_version=${rvm_version:-1.8.6} + if [ "$rvm_version" = "1.8.6" ] ; then + rvm_patchlevel="${3:-20090610}" + MY_RUBY_HOME="$rvm_install_path/ruby-enterprise-$rvm_version-$rvm_patchlevel" GEM_HOME="$HOME/.gem/ruby-enterprise/1.8" else - rvm-log-fail "Unknown Ruby Enterprise Edition version: $version" + rvm-log-fail "Unknown Ruby Enterprise Edition version: $rvm_version" fi ;; ruby) - if [ "$version" = "1.8.7" ] ; then - level="${patchlevel-174}" - MY_RUBY_HOME="$install_path/ruby-1.8.7-p$level" - GEM_HOME="$HOME/.gem/ruby/1.8" + if [ "$rvm_version" = "1.8.7" ] ; then + level="${rvm_patchlevel:-174}" + MY_RUBY_HOME="$rvm_install_path/ruby-1.8.7-p$level" + GEM_HOME="$HOME/.gem/ruby/1.8.7" - elif [ "$version" = "1.8.6" -o "$version" = "1.8" ] ; then - level="${patchlevel-369}" - MY_RUBY_HOME="$install_path/ruby-1.8.6-p$level" - GEM_HOME="$HOME/.gem/ruby/1.8" + elif [ "$rvm_version" = "1.8.6" -o "$rvm_version" = "1.8" ] ; then + level="${rvm_patchlevel:-369}" + MY_RUBY_HOME="$rvm_install_path/ruby-1.8.6-p$level" + GEM_HOME="$HOME/.gem/ruby/1.8.6" - elif [ "$version" = "1.9.2" ] ; then - level="${patchlevel-review1}" - MY_RUBY_HOME="$install_path/ruby-1.9.2-p$level" + elif [ "$rvm_version" = "1.9.2" ] ; then + level="${rvm_patchlevel:-review1}" + MY_RUBY_HOME="$rvm_install_path/ruby-1.9.2-p$level" GEM_HOME="$HOME/.gem/ruby/1.9.2" - elif [ "$version" = "1.9.1" -o "$version" = "1.9" ] ; then - level="${patchlevel-243}" - MY_RUBY_HOME="$install_path/ruby-1.9.1-p$level" + elif [ "$rvm_version" = "1.9.1" -o "$rvm_version" = "1.9" ] ; then + level="${rvm_patchlevel:-243}" + MY_RUBY_HOME="$rvm_install_path/ruby-1.9.1-p$level" GEM_HOME="$HOME/.gem/ruby/1.9.1" else - rvm-log-fail "Unknown ruby version: $version" + rvm-log-fail "Unknown ruby version: $rvm_version" fi ;; *) - rvm-log-fail "Ruby implementation '$implementation' is not known." + rvm-log-fail "Ruby implementation '$rvm_implementation' is not known." esac # Now actually use it. - if [ ! "$implementation" = "default" ] ; then + if [ ! "$rvm_implementation" = "default" ] ; then # Install if not installed if [ ! -d $MY_RUBY_HOME ] ; then - rvm-log-warn "$implementation $version is not installed." - rvm-install-ruby $implementation $version $level + rvm-log-warn "$rvm_implementation $rvm_version is not installed." + rvm-install-ruby $rvm_implementation $rvm_version $level fi # Set as 'current' RUBY_VERSION="$($MY_RUBY_HOME/bin/ruby -v | sed 's/^\(.*\) (.*$/\1/')" export GEM_HOME MY_RUBY_HOME RUBY_VERSION - echo "PATH=$MY_RUBY_HOME/bin:$GEM_HOME/bin:$default_path ; export PATH" > $install_path/current + echo "PATH=$MY_RUBY_HOME/bin:$GEM_HOME/bin:$default_path ; export PATH" > $rvm_install_path/current for variable in RUBY_VERSION GEM_HOME MY_RUBY_HOME ; do eval "export $variable" eval value=\$${variable} - echo "${variable}='$value' ; export ${variable}" >> $install_path/current + echo "${variable}='$value' ; export ${variable}" >> $rvm_install_path/current done fi - rvm-log-info "Switching to $implementation $version $patchlevel ...\n" + rvm-log-info "Switching to $rvm_implementation $rvm_version $rvm_patchlevel ...\n" if [ ! -z "$BASH_VERSION" ] ; then exec bash -l elif [ ! -z "$ZSH_VERSION" ] ; then exec zsh -l else @@ -487,161 +480,156 @@ fi } function rvm-symlinks { - mkdir -p ${install_path}/bin - for release in `ls $install_path | grep 'ruby-'` ; do + + mkdir -p ${rvm_install_path}/bin + for release in `ls $rvm_install_path | grep 'ruby-'` ; do for binary in ruby irb gem rdoc ri erb ; do - if [ -x $install_path/$release/bin/$binary ] ; then - ln -fs $install_path/$release/bin/$binary $install_path/bin/$binary-${release#ruby-} + if [ -x $rvm_install_path/$release/bin/$binary ] ; then + ln -fs $rvm_install_path/$release/bin/$binary $rvm_install_path/bin/$binary-${release#ruby-} fi done done + } function rvm-list { - echo -e "\nruby:" - ls -l $install_path/ | awk '/ ruby-[1-2].*/ { print " - " $NF }' - echo - echo "jruby:" - ls -l $install_path/ | awk '/jruby-.*/ { print " - " $NF }' - echo - echo "ree:" - ls $install_path/ | awk '/ruby-enterprise-.*/ { print " - " $NF }' - echo - echo "default:" - echo " - system (`$default_system_ruby -v`)" + echo -e "\nruby:\n$(ls -l $rvm_install_path/ | awk '/ ruby-[1-2].*/ { print " - " $NF }')\n" + echo -e "jruby:\n$(ls -l $rvm_install_path/ | awk '/jruby-.*/ { print " - " $NF }')\n" + echo -e "ree:\n$(ls $rvm_install_path/ | awk '/ruby-enterprise-.*/ { print " - " $NF }')\n" + echo -e "system:\n - ($($default_system_ruby -v))\n" } function rvm-reset { PATH="$default_path" ; export PATH for variable in RUBY_VERSION GEM_HOME MY_RUBY_HOME ; do unset $variable done - rm -f $install_path/default* $install_path/current + rm -f $rvm_install_path/default* $rvm_install_path/current if [ ! -z "$BASH_VERSION" ] ; then exec bash -l elif [ ! -z "$ZSH_VERSION" ] ; then exec zsh -l else rvm-log-fail "Your shell is not supported bash and zsh are currently supported." fi - + } - + function rvm-gem-dir { - implementation=${1-$implementation} - if [ "$implementation" = "" ] ; then implementation="current" ; fi + rvm_implementation=${1:-$rvm_implementation} + if [ -z "$rvm_implementation" ] ; then rvm_implementation="current" ; fi - case "$implementation" in + case "$rvm_implementation" in jruby) GEM_HOME="$HOME/.gem/jruby/1.8" ;; ree) GEM_HOME="$HOME/.gem/ruby-enterprise/1.8" ;; ruby) - if [ "${2-$version}" = "1.8" -o "${2-$version}" = "1.8.6" ] ; then + if [ "${2:-$rvm_version}" = "1.8" -o "${2:-$rvm_version}" = "1.8.6" ] ; then GEM_HOME="$HOME/.gem/ruby/1.8" - elif [ "${2-$version}" = "1.9.2" ] ; then + elif [ "${2:-$rvm_version}" = "1.9.2" ] ; then GEM_HOME="$HOME/.gem/ruby/1.9.2" - elif [ "${2-$version}" = "1.9" -o "${2-$version}" = "1.9.1" ] ; then + elif [ "${2:-$rvm_version}" = "1.9" -o "${2:-$rvm_version}" = "1.9.1" ] ; then GEM_HOME="$HOME/.gem/ruby/1.9.1" else - rvm-log-fail "Unknown Version: ${2-$version}" + rvm-log-fail "Unknown Version: ${2:-$rvm_version}" fi ;; current) GEM_HOME=$(ruby -r rubygems -e "puts Gem::default_path.compact.first") ;; system) GEM_HOME=$default_system_gem_path ;; user) - GEM_HOME=$default_gem_path + GEM_HOME=$default_user_gem_path ;; *) - rvm-log-fail "Ruby implementation '$implementation' is not known." + rvm-log-fail "Ruby implementation '$rvm_implementation' is not known." esac if [ -d $GEM_HOME ] ; then echo $GEM_HOME && cd $GEM_HOME else - rvm-log-fail "$implementation $version GEM directory does not exist." + rvm-log-fail "$rvm_implementation $rvm_version GEM directory does not exist." fi } function rvm-src-dir { - case "${1-$implementation}" in + case "${1:-$rvm_implementation}" in jruby) - version=${version-1.3.1} - if [ "${2-$version}" = "1.2.0" -o "${2-$version}" = "1.3.1" ] ; then - src_dir="$source_path/$implementation-$version" + rvm_version=${rvm_version:-1.3.1} + if [ "${2:-$rvm_version}" = "1.2.0" -o "${2:-$rvm_version}" = "1.3.1" ] ; then + src_dir="$rvm_source_path/$rvm_implementation-$rvm_version" else - rvm-log-fail "Unknown jRuby version: $version" + rvm-log-fail "Unknown jRuby version: $rvm_version" fi ;; ree) - version=${version-1.8.6} - if [ "${2-$version}" = "1.8.6" -o "${2-$version}" = "1.8" ] ; then - src_dir="$source_path/ruby-enterprise-${2-$version}-"${3-20090610}"" + rvm_version=${rvm_version:-1.8.6} + if [ "${2:-$rvm_version}" = "1.8.6" -o "${2:-$rvm_version}" = "1.8" ] ; then + src_dir="$rvm_source_path/ruby-enterprise-${2:-$rvm_version}-"${3:-20090610}"" else - rvm-log-fail "Unknown Ruby Enterprise Edition version: ${2-$version}" + rvm-log-fail "Unknown Ruby Enterprise Edition version: ${2:-$rvm_version}" fi ;; ruby) - if [ "${2-$version}" = "1.8.7" ] ; then - src_dir="$source_path/ruby-1.8.7-p${patchlevel-174}" + if [ "${2:-$rvm_version}" = "1.8.7" ] ; then + src_dir="$rvm_source_path/ruby-1.8.7-p${rvm_patchlevel:-174}" - elif [ "${2-$version}" = "1.8" -o "${2-$version}" = "1.8.6" ] ; then - src_dir="$source_path/ruby-1.8.6-p${patchlevel-369}" + elif [ "${2:-$rvm_version}" = "1.8" -o "${2:-$rvm_version}" = "1.8.6" ] ; then + src_dir="$rvm_source_path/ruby-1.8.6-p${rvm_patchlevel:-369}" - elif [ "${2-$version}" = "1.9.2" ] ; then - src_dir="$source_path/ruby-1.9.2-p${patchlevel-review1}" + elif [ "${2:-$rvm_version}" = "1.9.2" ] ; then + src_dir="$rvm_source_path/ruby-1.9.2-p${rvm_patchlevel:-review1}" - elif [ "${2-$version}" = "1.9" -o "${2-$version}" = "1.9.1" ] ; then - src_dir="$source_path/ruby-1.9.1-p${patchlevel-243}" + elif [ "${2:-$rvm_version}" = "1.9" -o "${2:-$rvm_version}" = "1.9.1" ] ; then + src_dir="$rvm_source_path/ruby-1.9.1-p${rvm_patchlevel:-243}" else - rvm-log-fail "unknown Ruby version: ${2-$version}" + rvm-log-fail "unknown Ruby version: ${2:-$rvm_version}" fi ;; default) rvm-log-warn "Invalid request, rvm cannot change to the default source directory." ;; *) - rvm-log-fail "Ruby implementation '$implementation' is not known." + rvm-log-fail "Ruby implementation '$rvm_implementation' is not known." return 1 esac if [ -d $src_dir ] ; then cd $src_dir else - rvm-log-fail "$implementation $version source directory does not exist." + rvm-log-fail "$rvm_implementation $rvm_version source directory does not exist." fi } # clones from source implementation/version to current function rvm-gem-dup { if [ "$1" = "default" ] ; then - gem_dir="$default_gem_path" + gem_dir="$default_user_gem_path" elif [ "$1" = "system" ] ; then gem_dir="$default_system_gem_path" else - gem_dir=${1-$default_gem_path} # TODO: check for and remove trailing /gems + gem_dir=${1:-$default_user_gem_path} # TODO: check for and remove trailing /gems fi if [ ! -z "$gem_dir" ] ; then for gem_name_version in `ls $gem_dir/gems` ; do gem_name=${gem_name_version%-*} @@ -651,195 +639,214 @@ else rvm-gi $gem_dir/cache/$gem_name-$gem_version.gem fi done else - rvm-log-fail "Unknown $implementation version: $version" + rvm-log-fail "Unknown $rvm_implementation version: $rvm_version" fi } -function rvm-version { echo "rvm $rvm_version ($rvm_updated) [$rvm_website]" ; } +function rvm-version { echo "rvm $rvm_meta_version ($rvm_meta_updated) [$rvm_meta_website]" ; } function rvm { # Cleanup, aisle 3 - for variable in action implementation patchlevel version source_path install_path manager debug prefix_path ; do - eval "unset $variable" - done - + for variable in rvm_action rvm_implementation rvm_patchlevel rvm_version rvm_source_path rvm_install_path rvm_debug rvm_prefix_path rvm_package_name; do + eval "unset $variable" + done ; unset variable + + # NOW load defaults settings. TODO: root user loads /etc/rvmrc + if [ -f ~/.rvmrc ] ; then source ~/.rvmrc ; fi + while [ $# -gt 0 ] ; do - token="$1" ; shift - case "$token" in - install|uninstall|use|path|info|setup|version|srcdir|list|symlinks|reset|debug) - action=$token + rvm_token="$1" ; shift + case "$rvm_token" in + install|uninstall|use|path|info|setup|version|srcdir|list|symlinks|reset|debug|reload) + rvm_action=$rvm_token ;; ruby|jruby|ree|default|all) - implementation="$token" - action="${action-use}" + rvm_implementation="$rvm_token" + rvm_action="${rvm_action:-use}" ;; gemdir) - action=$token + rvm_action=$rvm_token if [ "$1" = "system" ] ; then - implementation="system" ; shift + rvm_implementation="system" ; shift fi - if [ "$1" = "user" ] ; then - implementation="user" ; shift + if [ "$1" = "user" ] ; then + rvm_implementation="user" ; shift fi - implementation="${implementation-current}" + rvm_implementation="${rvm_implementation:-current}" ;; gemdup) - action=$token + rvm_action=$rvm_token if [ -z "$1" ] ; then - implementaiton="default" + rvm_implementation="default" elif [ "$1" = "system" ] ; then - implementation=$1 ; shift + rvm_implementation=$1 ; shift elif [ "$1" = "default" ] ; then - implementation=$1 ; shift + rvm_implementation=$1 ; shift else - implementation=$1 ; shift - version=$2 ; shift + rvm_implementation=$1 ; shift + rvm_version=$2 ; shift fi ;; 1.8|1.8.6|1.8.7|1.9|1.9.1|1.9.2|1.2.0|1.3.1) - version="$token" - action="${action-use}" + rvm_version="$rvm_token" + rvm_action="${rvm_action:-use}" ;; - -v|--version) - if [ -z "$1" ] ; then - action="version" - else - version="$1" + -v|--version) + if [ -z "$1" ] ; then + rvm_action="version" + else + rvm_version="$1" fi shift ;; - -l|--level) patchlevel="$1" ; shift ;; - -p|--prefix) install_path="$1" ; shift ;; - -s|--source) source_path="$1" ; shift ;; # Undocumented / untested "feature" - -c|--configure) configure="$1" ; shift ;; - -d|--debug) debug=1 ;; + -l|--level) rvm_patchlevel="$1" ; shift ;; + -p|--prefix) rvm_prefix_path="$1" ; shift ;; + -b|--bin) rvm_bin_path="$1" ; shift ;; # Undocumented / untested "feature" + -s|--source) rvm_source_path="$1" ; shift ;; # Undocumented / untested "feature" + -a|--archive) rvm_archives_path="$1" ; shift ;; + -c|--configure) configure="$1" ; shift ;; + -n|--nice) niceness="$1" ; shift ;; + -d|--debug) rvm_debug=1 ;; *) rvm-usage ; return 1 - esac - done - - curl=`which curl` + esac + done + + if [ "$rvm_debug" = "1" ] ; then set -x ; fi + + rvm_curl=`which curl` if [ $? -ne 0 ] ; then rvm-log-fail "rvm expects that curl is available, which curl shows no curl :(" else - curl="$curl -O -L -s" + rvm_curl="$rvm_curl -O -L -s" fi - if [ -z "$implementation" -a -z "$version" ] ; then - implementation="default" + if [ -z "$rvm_implementation" -a -z "$rvm_version" ] ; then + rvm_implementation="default" else - implementation=${implementation-'ruby'} + rvm_implementation=${rvm_implementation:-ruby} fi + niceness=${niceness:-0} + # TODO: Sanitize user input, ensure that there is a / a the end... - if [ "`whoami`" = "root" ] ; then + if [ "`whoami`" = "root" ] ; then rvm-log-fail "root user support is not yet implemented." - #prefix_path=${prefix-/usr/local/} + #rvm_prefix_path=${rvm_prefix_path:-/usr/local/} else - prefix_path=${prefix-$HOME/.} + rvm_prefix_path=${rvm_prefix_path:-"$HOME/."} fi - source_path="${source_path-"${prefix_path}rvm/src"}" - install_path="${prefix_path}rvm" - - mkdir -p $source_path $install_path/bin + if [ "${rvm_prefix_path#${rvm_prefix_path%?}}" = '.' -o "${rvm_prefix_path#${rvm_prefix_path%?}}" = '/' ] ; then + rvm_install_path="${rvm_prefix_path}rvm" + else + rvm_install_path="${rvm_prefix_path}/rvm" + fi + rvm_archives_path="${rvm_archives_path:-"${rvm_install_path}/archives"}" + rvm_source_path="${rvm_source_path:-"${rvm_install_path}/src"}" + rvm_log_path=${rvm_log_path:-"${rvm_install_path}/log"} + rvm_bin_path=${rvm_bin_path:-"${rvm_install_path}/bin"} - if [ ! -f $install_path/default ] ; then + PATH=$rvm_bin_path:$PATH ; export PATH + + mkdir -p $rvm_source_path $rvm_install_path/bin $rvm_archives_path + + if [ ! -f $rvm_install_path/default ] ; then for variable in RUBY_VERSION GEM_HOME MY_RUBY_HOME PATH ; do eval "export $variable" eval value=\$${variable} - echo "${variable}='$value' ; export ${variable}" >> $install_path/default + echo "${variable}='$value' ; export ${variable}" >> $rvm_install_path/default done fi - if [ -s $install_path/default_path ] ; then - default_path=`cat $install_path/default_path` + if [ -s $rvm_install_path/default_path ] ; then + default_path=`cat $rvm_install_path/default_path` else - echo $PATH > $install_path/default_path + echo $PATH > $rvm_install_path/default_path default_path=$PATH fi - # default (user) gem path - if [ -s $install_path/default_gem_path ] ; then - default_gem_path=`cat $install_path/default_gem_path` + if [ -s $rvm_install_path/default_user_gem_path ] ; then + default_user_gem_path=`cat $rvm_install_path/default_user_gem_path` else - ruby -r rubygems -e "puts Gem::default_path.compact.first" > $install_path/default_gem_path + ruby -r rubygems -e "puts Gem::default_path.compact.first" > $rvm_install_path/default_user_gem_path fi - # system gem path - if [ -s $install_path/default_system_gem_path ] ; then - default_system_gem_path=`cat $install_path/default_system_gem_path` + if [ -s $rvm_install_path/default_system_gem_path ] ; then + default_system_gem_path=`cat $rvm_install_path/default_system_gem_path` else - ruby -r rubygems -e "puts Gem::default_path.compact[1] || Gem::default_path.compact.first" > $install_path/default_system_gem_path + ruby -r rubygems -e "puts Gem::default_path.compact[1] || Gem::default_path.compact.first" > $rvm_install_path/default_system_gem_path fi - # system ruby version - if [ -s $install_path/default_system_ruby ] ; then - default_system_ruby=`cat $install_path/default_system_ruby` + if [ -s $rvm_install_path/default_system_ruby ] ; then + default_system_ruby=`cat $rvm_install_path/default_system_ruby` else default_system_ruby=`which ruby` - echo $default_system_ruby > $install_path/default_system_ruby + echo $default_system_ruby > $rvm_install_path/default_system_ruby fi - if [ "$debug" = "1" ] ; then set -x ; fi - - case "$action" in - install) - if [ "$implementation" = "all" ] ; then - for implementation in ruby jruby ree ; do - if [ "$implementation" = "ruby" ] ; then - for version in 1.8.6 1.8.7 1.9.1 1.9.2 ; do - rvm-install-ruby $implementation $version $patchlevel + case "$rvm_action" in + install) + if [ "$rvm_implementation" = "all" ] ; then + for rvm_implementation in ruby jruby ree ; do + if [ "$rvm_implementation" = "ruby" ] ; then + for rvm_version in 1.8.6 1.8.7 1.9.1 1.9.2 ; do + rvm-install-ruby $rvm_implementation $rvm_version done + unset rvm_version else - rvm-install-ruby $implementation $version $patchlevel + rvm-install-ruby $rvm_implementation $rvm_version fi done else - rvm-install-ruby $implementation $version $patchlevel + rvm-install-ruby $rvm_implementation $rvm_version $rvm_patchlevel fi ;; - uninstall) rvm-uninstall $implementation $version $patchlevel ;; - use) rvm-use $implementation $version $patchlevel ;; - list) rvm-list ;; - gemdir) rvm-gem-dir $implementation $version $patchlevel ;; - srcdir) rvm-src-dir $implementation $version $patchlevel ;; - gemdup) rvm-gem-dup $implementation $version $patchlevel ;; - info) rvm-info $implementation $version $patchlevel ;; - symlinks) rvm-symlinks ;; - version) rvm-version ;; - reset) rvm-reset ;; - debug) + uninstall) rvm-uninstall $rvm_implementation $rvm_version $rvm_patchlevel ;; + use) rvm-use $rvm_implementation $rvm_version $rvm_patchlevel ;; + list) rvm-list ;; + gemdir) rvm-gem-dir $rvm_implementation $rvm_version $rvm_patchlevel ;; + srcdir) rvm-src-dir $rvm_implementation $rvm_version $rvm_patchlevel ;; + gemdup) rvm-gem-dup $rvm_implementation $rvm_version $rvm_patchlevel ;; + info) rvm-info $rvm_implementation $rvm_version $rvm_patchlevel ;; + symlinks) rvm-symlinks ;; + version) rvm-version ;; + reset) rvm-reset ;; + reload) source ~/.rvm/bin/rvm ;; # TODO: how can we use bin_path here, default file? + debug) rvm-version rvm-info rvm-log-info "PATH:$(echo $PATH | awk -F":" '{print $1":"$2":"$3":"$4":"$5}')" for file in .bash_profile .zshrc ; do if [ -s $file ] ; then rvm-log-info "~/$file: \n$(cat ~/$file| tail -n 5)\n" fi done - rvm-log-info "$install_path/current: \n$(cat $install_path/current)\n" + rvm-log-info "$rvm_install_path/current: \n$(cat $rvm_install_path/current)\n" return 0 ;; - *) - if [ ! -z "$action" ] ; then - rvm-log-fail "unknown action '$action'" + *) + if [ ! -z "$rvm_action" ] ; then + rvm-log-fail "unknown action '$rvm_action'" else - rvm-usage + rvm-usage fi return 1 esac - if [ "$debug" = "1" ] ; then set +x ; fi + if [ "$rvm_debug" = "1" ] ; then set +x ; unset rvm_debug ; fi } + +# TODO: Make this optional: +if [ -f ~/.rvm/current ] ; then source ~/.rvm/current ; fi # magic :)