bash/rvm in wayneeseguin-rvm-0.0.9 vs bash/rvm in wayneeseguin-rvm-0.0.15
- old
+ new
@@ -1,11 +1,11 @@
#!/bin/bash
rvm_author="Wayne E. Seguin"
rvm_author_email="wayneeseguin@gmail.com"
rvm_website="http://github.com/wayneeseguin/rvm"
-rvm_version="0.0.9"
+rvm_version="0.0.19"
rvm_updated="2009.08.25"
#
# License: See LICENSE
#
@@ -21,27 +21,34 @@
rvm ${rvm_version} ${rvm_website}
by ${rvm_author} (${rvm_author_email})
+ Installation:
+
+ $ gem install rvm # Install the rvm gem
+ $ rvm-install # Install rvm, adds hooks for bash & zsh
+
Usage:
rvm Action [Implementation] [Options]
Action:
* usage - Show this usage information
- use - Switch to using a specific ruby versio (new login shell)
+ 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 implementation version gems to currently used version
- (expiramental) Example: rvm gemdup ~/.gem/ruby/1.8/
+ 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
- debug - Emit environment and configuration information for debugging
+ reset - Remove default and current settings, exit the shell.
+ (If you experience odd behavior try this first)
+ debug - Emit environment & configuration information for *current* ruby
Implementation:
* ruby - MRI/YARV Ruby (The Standard), defaults to 1.8.6
jruby - jRuby
@@ -61,34 +68,37 @@
Notes:
* Defaults above are denoted with a '*' prefix.
* rvm is intended to be run as an individual user (not root, yet)
* All ruby installation, configuration and source files are in ~/.rvm
- * To manually reset to defaults: "rm -f ~/.rvm/current", then open new shell
- * To preserve previous gem installations for a particular ruby version copy,
- move, symlink or copy the old gem directory to (1.8 for 1.8.X):
- ~/.gem/\$interpreter/\$version
Examples:
- $ gem install rvm # Install the rvm gem
- $ rvm-install # Install rvm, adds hooks for bash & zsh
+ $ rvm -v # RVM version
+ $ rvm list # available rvm versions
+ $ rvm info # ruby information for current shell
$ rvm install jruby # Install jRuby (default version is 1.3.1)
$ rvm use ruby -v 1.9.1 # Use Ruby 1.9.1, installs if necessary
$ rvm use 1.9 # Equivalent to above, due to defaults
$ rvm use 1.8 # Use Ruby 1.8.6, installs if necessary
+ $ rvm gemdir # Switch to gems directory for current ruby
+ $ rvm gemdir system # Switch to the system gems directory
+ $ rvm gemdir system user # Switch to the system user gems directory
+ $ rvm gemdir ruby 1.9 # Switch to gems directory for ruby 1.9.1
$ rvm use default # Use the system default (as if no rvm)
- $ rvm gemdup ~/.gem/ruby/1.8/ # Install gems from ~/.gem/ruby/1.8/
+ $ rvm reset # Reset to pre-rvm state.
+ $ 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 gemdir default
+ * rvm gemdup
* root support
* Settings file, user overridable
* Show current in rvm list, if applicable
- Credits:
+ Many Thanks:
Bash Support Testing
- Daniel Neighman (dneighman@gmail.com)
irc: hassox ; github: http://github.com/hassox
@@ -99,43 +109,55 @@
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
-function log { echo -e "\n $* \e[0m" ; }
-function debug { log "\e[4;34m <d> \e[0m$*" ; }
-function info { log "\e[0;32m <i> \e[0m$*" ; }
-function warn { log "\e[0;33m <w> \e[0m$*" ; }
-function error { log "\e[0;31m <e> \e[0m$*" ; }
-function fail { log "\e[0;31m <e> \e[0m$*" ; return 1 ; }
+function rvm-log { echo -e "\n $* \e[0m" ; }
+function rvm-log-debug { rvm-log "\e[4;34m <d> \e[0m$*" ; }
+function rvm-log-info { rvm-log "\e[0;32m <i> \e[0m$*" ; }
+function rvm-log-warn { rvm-log "\e[0;33m <w> \e[0m$*" ; }
+function rvm-log-error { rvm-log "\e[0;31m <e> \e[0m$*" ; }
+function rvm-log-fail { rvm-log "\e[0;31m <e> \e[0m$*" ; return 1 ; }
function rvm-gi { gem install -q --no-rdoc --no-ri $* ; }
function rvm-info {
- full_version=$(ruby -v)
- ruby_implementation=$(echo "$full_version" | awk '{print $1}')
- ruby_version=$(echo "$full_version" | awk '{print $2}')
- ruby_patchlevel=$(echo "$full_version" | sed 's/^.*(//' | sed 's/).*$//')
- ruby_date=$(echo "$full_version" | sed 's/^.*(\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\).*$/\1/')
- ruby_platform=$(echo "$full_version" | sed 's/^.*\[//' | sed 's/\].*$//')
-
cat <<-Info
+
ruby:
- implementation: "$ruby_implementation"
- version: "$ruby_version"
- date: "$ruby_date"
- platform: "$ruby_platform"
- patchlevel: "$ruby_patchlevel"
- gem_home: "${GEM_HOME-not set}"
- ruby_home: "${ruby_home-not set}"
- full_version: "$full_version"
+ interpreter: "$(ruby -v | awk '{print $1}')"
+ version: "$(ruby -v | awk '{print $2}')"
+ date: "$(ruby -v | sed 's/^.*(\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\).*$/\1/')"
+ 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}"
+
+binaries:
+ ruby: "$(which ruby)"
+ irb: "$(which irb)"
+ gem: "$(which gem)"
+
Info
}
function rvm-install-source {
@@ -144,59 +166,62 @@
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}" ;;
- *) fail "Ruby version '$version' is unknown."
+ *) rvm-log-fail "Ruby version '$version' is unknown."
esac
package_name="ruby-$major.$minor-p$level"
url="ftp://ftp.ruby-lang.org/pub/ruby/$major/$package_name.tar.gz"
- info "Installing Ruby from source to: $install_path/$package_name"
+ 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
else
if [ ! -f "$package_name.tar.gz" ] ; then
- info "\tDownloading $package_name, this may take a while depending on your connection..."
- curl -O -L -s $url
+ rvm-log-info "\tDownloading $package_name, this may take a while depending on your connection..."
+ $curl $url
fi
- info "\tExtracting $package_name..."
+ rvm-log-info "\tExtracting $package_name..."
tar xzf $package_name.tar.gz && cd $package_name
fi
- info "\tConfiguring $package_name using ${configure-'--enable-shared'}, this may take a while depending on your cpu(s)..."
+ 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
- info "\tCompiling $package_name, this may take a while, depending on your cpu(s)..."
+ 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
- info "\tInstalling $package_name"
+ 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/*
+ # Create the ~/.rvm/bin/$package_name
+ ln -fs $install_path/$package_name/bin/ruby $install_path/bin/$package_name
+
# Now install rubygems for this ruby version.
- info "\tInstalling rubygems dedicated to $package_name..."
+ 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
else
- if [ ! -f $gem_package_name.tgz ] ; then curl -O -L -s $gem_url ; fi
+ if [ ! -f $gem_package_name.tgz ] ; then $curl $gem_url ; fi
tar zxf $gem_package_name.tgz && cd $gem_package_name
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
popd > /dev/null
- info "Installation of $package_name complete."
+ rvm-log-info "Installation of $package_name complete."
for gem_name in rake ; do
- info "Installing $gem_name"
+ 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
done
}
function rvm-install-ruby {
@@ -206,45 +231,47 @@
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"
- info "Installing Ruby Enterprise Edition from source to: $install_path/$package_name"
+ 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
else
if [ ! -f "$package_name.tar.gz" ] ; then
- info "\tDownloading $package_name, this may take a while depending on your connection..."
- curl -O -L -s $url
+ rvm-log-info "\tDownloading $package_name, this may take a while depending on your connection..."
+ $curl $url
fi
- info "\tExtracting $package_name..."
+ rvm-log-info "\tExtracting $package_name..."
tar xzf $package_name.tar.gz && cd $package_name
fi
- info "\tInstalling $package_name, this may take a while, depending on your cpu(s)..."
+ 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/*
- info "\tInstalling rubygems dedicated to $package_name..."
+ ln -fs $install_path/$package_name/bin/ruby $install_path/bin/$package_name
+
+ 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
else
- if [ ! -f $gem_package_name.tgz ] ; then curl -O -L -s $gem_url ; fi
+ if [ ! -f $gem_package_name.tgz ] ; then $curl $gem_url ; fi
tar zxf $gem_package_name.tgz && cd $gem_package_name
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
- info "Installation of $package_name complete."
+ rvm-log-info "Installation of $package_name complete."
popd > /dev/null
for gem_name in rake ; do
- info "Installing $gem_name"
+ 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
done
;;
jruby)
@@ -252,47 +279,50 @@
unset patchlevel # No patchlevel for jRuby
zipfile="$implementation-bin-$version"
package_name="$implementation-$version"
url="http://dist.codehaus.org/$implementation/$version/$zipfile.zip"
- info "Installing jRuby to: $install_path/$package_name"
+ 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
else
if [ ! -f "$zipfile.zip" ] ; then
- info "\tDownloading $zipfile, this may take a while depending on your connection..."
- curl -O -L -s $url
+ rvm-log-info "\tDownloading $zipfile, this may take a while depending on your connection..."
+ $curl $url
fi
- info "\tExtracting $zipfile..."
+ rvm-log-info "\tExtracting $zipfile..."
jar xf $zipfile.zip
fi
- info "\tInstalling $package_name..."
+ 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
popd > /dev/null
chmod +x $install_path/$package_name/bin/*
for binary in jruby jgem jirb ; do
- ln -sf $install_path/$package_name/bin/$binary $install_path/$package_name/bin/${binary#j}
+ ln -fs $install_path/$package_name/bin/$binary $install_path/$package_name/bin/${binary#j}
done
+
+ ln -fs $install_path/$package_name/bin/ruby $install_path/bin/$package_name
+
for gem_name in rake jruby-openssl ; do
- info "Installing $gem_name"
+ 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
done
;;
ruby)
rvm-install-source ${version-1.8.6} ${patchlevel-$3}
;;
default)
- fail "please specify a ruby implementation to install."
+ rvm-log-fail "please specify a ruby implementation to install."
;;
- *) fail "Ruby implementation '$implementation' is not known."
+ *) rvm-log-fail "Ruby implementation '$implementation' is not known."
esac
}
@@ -304,20 +334,20 @@
jruby)
version="${version-1.3.1}"
if [ "$version" = "1.2.0" -o "$version" = "1.3.1" ] ; then
package_name="jruby*-$version"
else
- fail "Unknown jRuby version: $version"
+ rvm-log-fail "Unknown jRuby version: $version"
fi
;;
ree)
version=${version-1.8.6}
if [ "$version" = "1.8.6" ] ; then
package_name="$install_path/ruby-enterprise-$version-${3-20090610}"
else
- fail "Unknown Ruby Enterprise Edition version: $version"
+ rvm-log-fail "Unknown Ruby Enterprise Edition version: $version"
fi
;;
ruby)
if [ "$version" = "1.8.7" ] ; then
@@ -331,68 +361,64 @@
elif [ "$version" = "1.9.1" -o "$version" = "1.9" ] ; then
package_name="ruby-1.9.1-p${patchlevel-243}"
else
- fail "Unknown ruby version: $version"
+ rvm-log-fail "Unknown ruby version: $version"
fi
;;
*)
- fail "Ruby implementation '$implementation' is not known."
+ rvm-log-fail "Ruby implementation '$implementation' is not known."
esac
if [ ! -z "$package_name" ] ; then
for path in $source_path $install_path ; do
if [ -d $path/$package_name ] ; then
- info "Removing $path/$package_name"
+ rvm-log-info "Removing $path/$package_name"
rm -rf $path/$package_name
fi
done
else
- fail "Cannot uninstall unknown package '$package_name'"
+ rvm-log-fail "Cannot uninstall unknown package '$package_name'"
fi
}
function rvm-use {
implementation="${1-$implementation}"
case "$implementation" in
default)
- # TODO: There is a reproducible bug here when switching off of 1.8.7...
- # Seems that the path is not reset properly.
- rm -f ~/.rvm/current
- unset MY_RUBY_HOME
- unset GEM_HOME
- unset RUBY_VERSION
- PATH=$original_path ; export PATH
+ rm -f $install_path/current
+ source $install_path/default
+ unset GEM_HOME MY_RUBY_HOME
+ PATH="$default_path" ; export PATH
;;
- #leopard) MY_RUBY_HOME="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr"; GEM_HOME="$HOME/.gem/ruby/1.8" ;;
jruby)
version="${version-1.3.1}"
if [ "$version" = "1.2.0" -o "$version" = "1.3.1" ] ; then
MY_RUBY_HOME="$install_path/jruby-$version"
GEM_HOME="$HOME/.gem/jruby/1.8"
alias ruby_ng="jruby --ng"
alias ruby_ng_server="jruby --ng-server"
else
- fail "Unknown jRuby version: $version"
+ rvm-log-fail "Unknown jRuby version: $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"
GEM_HOME="$HOME/.gem/ruby-enterprise/1.8"
else
- fail "Unknown Ruby Enterprise Edition version: $version"
+ rvm-log-fail "Unknown Ruby Enterprise Edition version: $version"
fi
;;
ruby)
if [ "$version" = "1.8.7" ] ; then
@@ -414,148 +440,193 @@
level="${patchlevel-243}"
MY_RUBY_HOME="$install_path/ruby-1.9.1-p$level"
GEM_HOME="$HOME/.gem/ruby/1.9.1"
else
- fail "Unknown ruby version: $version"
+ rvm-log-fail "Unknown ruby version: $version"
fi
;;
*)
- fail "Ruby implementation '$implementation' is not known."
+ rvm-log-fail "Ruby implementation '$implementation' is not known."
esac
+ # Now actually use it.
if [ ! "$implementation" = "default" ] ; then
+ # Install if not installed
if [ ! -d $MY_RUBY_HOME ] ; then
- warn "$implementation $version is not installed."
+ rvm-log-warn "$implementation $version is not installed."
rvm-install-ruby $implementation $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
- # Setup ~/.rvm/current
- echo "PATH=$MY_RUBY_HOME/bin:$GEM_HOME/bin:\$PATH ; export PATH" > ~/.rvm/current
+ echo "PATH=$MY_RUBY_HOME/bin:$GEM_HOME/bin:$default_path ; export PATH" > $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}" >> ~/.rvm/current
+ echo "${variable}='$value' ; export ${variable}" >> $install_path/current
done
- else
- PATH=$original_path ; export PATH
fi
- info "Switching to $implementation $version $patchlevel ..."
+ rvm-log-info "Switching to $implementation $version $patchlevel ..."
if [ ! -z "$BASH_VERSION" ] ; then
exec bash -l
elif [ ! -z "$ZSH_VERSION" ] ; then
exec zsh -l
else
- fail "Your shell is not supported bash and zsh are currently supported."
+ rvm-log-fail "Your shell is not supported bash and zsh are currently supported."
fi
+
}
function rvm-list {
+
echo -e "\nruby:"
- ls -l ~/.rvm/ | awk '/ ruby-[1-2].*/ { print " - " $NF }'
+ ls -l $install_path/ | awk '/ ruby-[1-2].*/ { print " - " $NF }'
echo
echo "jruby:"
- ls -l ~/.rvm/ | awk '/jruby-.*/ { print " - " $NF }'
+ ls -l $install_path/ | awk '/jruby-.*/ { print " - " $NF }'
echo
echo "ree:"
- ls ~/.rvm/ | awk '/ruby-enterprise-.*/ { print " - " $NF }'
+ ls $install_path/ | awk '/ruby-enterprise-.*/ { print " - " $NF }'
echo
+ echo "default:"
+ echo " - system (`$default_system_ruby -v`)"
+
}
+
+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
+ 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 {
- case "${1-implementation}" in
+ implementation=${1-$implementation}
+ if [ "$implementation" = "" ] ; then implementation="current" ; fi
+
+ case "$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-$version}" = "1.8" -o "${2-$version}" = "1.8.6" ] ; then
GEM_HOME="$HOME/.gem/ruby/1.8"
- elif [ "${2-version}" = "1.9.2" ] ; then
+ elif [ "${2-$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-$version}" = "1.9" -o "${2-$version}" = "1.9.1" ] ; then
GEM_HOME="$HOME/.gem/ruby/1.9.1"
else
- fail "Unknown Version: ${2-version}"
+ rvm-log-fail "Unknown Version: ${2-$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
+ ;;
*)
- fail "Ruby implementation '$implementation' is not known."
+ rvm-log-fail "Ruby implementation '$implementation' is not known."
esac
if [ -d $GEM_HOME ] ; then
echo $GEM_HOME && cd $GEM_HOME
else
- fail "$implementation $version GEM directory does not exist."
+ rvm-log-fail "$implementation $version GEM directory does not exist."
fi
}
function rvm-src-dir {
- case "$implementation" in
+ case "${1-$implementation}" in
jruby)
- version="${version-1.3.1}"
- if [ "$version" = "1.2.0" -o "$version" = "1.3.1" ] ; then
+ version=${version-1.3.1}
+ if [ "${2-$version}" = "1.2.0" -o "${2-$version}" = "1.3.1" ] ; then
src_dir="$source_path/$implementation-$version"
else
- fail "Unknown jRuby version: $version"
+ rvm-log-fail "Unknown jRuby version: $version"
fi
;;
ree)
version=${version-1.8.6}
- if [ "$version" = "1.8.6" ] ; then
- src_dir="$source_path/ruby-enterprise-$version-"${3-20090610}""
+ if [ "${2-$version}" = "1.8.6" -o "${2-$version}" = "1.8" ] ; then
+ src_dir="$source_path/ruby-enterprise-${2-$version}-"${3-20090610}""
else
- fail "Unknown Ruby Enterprise Edition version: $version"
+ rvm-log-fail "Unknown Ruby Enterprise Edition version: ${2-$version}"
fi
;;
ruby)
- if [ "$version" = "1.8.7" ] ; then
+ if [ "${2-$version}" = "1.8.7" ] ; then
src_dir="$source_path/ruby-1.8.7-p${patchlevel-174}"
- elif [ "${version%\.*}" = "1.8" ] ; then
+ elif [ "${2-$version}" = "1.8" -o "${2-$version}" = "1.8.6" ] ; then
src_dir="$source_path/ruby-1.8.6-p${patchlevel-369}"
- elif [ "$version" = "1.9.2" ] ; then
+ elif [ "${2-$version}" = "1.9.2" ] ; then
src_dir="$source_path/ruby-1.9.2-p${patchlevel-review1}"
- elif [ "${version%\.*}" = "1.9" ] ; then
+ elif [ "${2-$version}" = "1.9" -o "${2-$version}" = "1.9.1" ] ; then
src_dir="$source_path/ruby-1.9.1-p${patchlevel-243}"
else
- fail "Unknown ruby version: $version"
+ rvm-log-fail "unknown Ruby version: ${2-$version}"
fi
;;
+ default)
+ rvm-log-warn "Invalid request, rvm cannot change to the default source directory."
+ ;;
+
*)
- fail "Ruby implementation '$implementation' is not known."
+ rvm-log-fail "Ruby implementation '$implementation' is not known."
return 1
esac
if [ -d $src_dir ] ; then
cd $src_dir
else
- fail "$implementation $version source directory does not exist."
+ rvm-log-fail "$implementation $version source directory does not exist."
fi
}
# clones from source implementation/version to current
function rvm-gem-dup {
- gem_dir=$1 # TODO: check for and remove trailing /gems
+ if [ "$1" = "default" ] ; then
+ gem_dir="$default_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
+ fi
+
if [ ! -z "$gem_dir" ] ; then
for gem_name_version in `ls $gem_dir/gems` ; do
gem_name=${gem_name_version%-*}
gem_version=${gem_name_version##*-}
if [ -d $GEM_HOME/gems/$gem_name_version ] ; then
@@ -563,11 +634,11 @@
else
rvm-gi $gem_dir/cache/$gem_name-$gem_version.gem
fi
done
else
- fail "Unknown $implementation version: $version"
+ rvm-log-fail "Unknown $implementation version: $version"
fi
}
function rvm-version { echo "rvm $rvm_version ($rvm_updated) [$rvm_website]" ; }
@@ -576,65 +647,134 @@
# Cleanup, aisle 3
for variable in action implementation patchlevel version source_path install_path manager debug prefix_path ; do
eval "unset $variable"
done
+
while [ $# -gt 0 ] ; do
token="$1" ; shift
case "$token" in
- install|uninstall|use|path|info|gemdir|setup|version|debug|srcdir|list)
- action=$token ;;
+ install|uninstall|use|path|info|setup|version|srcdir|list|reset|debug)
+ action=$token
+ ;;
+
ruby|jruby|ree|default|all)
- implementation="$token" ;;
+ implementation="$token"
+ action="${action-use}"
+ ;;
+
+ gemdir)
+ action=$token
+ if [ "$1" = "system" ] ; then
+ implementation="system" ; shift
+ fi
+ if [ "$1" = "user" ] ; then
+ implementation="user" ; shift
+ fi
+
+ implementation="${implementation-current}"
+ ;;
+
+ gemdup)
+ action=$token
+ if [ -z "$1" ] ; then
+ implementaiton="default"
+ elif [ "$1" = "system" ] ; then
+ implementation=$1 ; shift
+ elif [ "$1" = "default" ] ; then
+ implementation=$1 ; shift
+ else
+ implementation=$1 ; shift
+ 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" ;;
+ version="$token"
+ action="${action-use}"
+ ;;
+
-v|--version)
if [ -z "$1" ] ; then
action="version"
else
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 ;;
- -m|--manager) manager="$1" ; shift ;;
- -u|--gemdup) action="gemdup" ; gem_dir="$1" ; shift ;;
-d|--debug) debug=1 ;;
*) rvm-usage ; return 1
esac
done
-
+
+ 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"
+ fi
+
if [ -z "$implementation" -a -z "$version" ] ; then
implementation="default"
else
implementation=${implementation-'ruby'}
fi
- username=`whoami`
# TODO: Sanitize user input, ensure that there is a / a the end...
- if [ "$username" = "root" ] ; then
- fail "root user support is not yet implemented."
+ if [ "`whoami`" = "root" ] ; then
+ rvm-log-fail "root user support is not yet implemented."
#prefix_path=${prefix-/usr/local/}
else
prefix_path=${prefix-$HOME/.}
fi
- source_path="${source_path-${prefix_path}rvm/src}"
+ source_path="${source_path-"${prefix_path}rvm/src"}"
install_path="${prefix_path}rvm"
- mkdir -p ~/.rvm/ $source_path $install_path
+ mkdir -p $source_path $install_path/bin
- if [ -f ~/.rvm/original_path ] ; then
- original_path=`cat ~/.rvm/original_path`
+ if [ ! -f $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
+ done
fi
- if [ -z "$original_path" ] ; then
- echo $PATH > $install_path/.original_path
- original_path=$PATH
+
+ if [ -s $install_path/default_path ] ; then
+ default_path=`cat $install_path/default_path`
+ else
+ echo $PATH > $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`
+ else
+ ruby -r rubygems -e "puts Gem::default_path.compact.first" > $install_path/default_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`
+ else
+ ruby -r rubygems -e "puts Gem::default_path.compact[1] || Gem::default_path.compact.first" > $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`
+ else
+ default_system_ruby=`which ruby`
+ echo $default_system_ruby > $install_path/default_system_ruby
+ fi
+
if [ "$debug" = "1" ] ; then set -x ; fi
case "$action" in
install)
if [ "$implementation" = "all" ] ; then
@@ -657,27 +797,31 @@
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 ;;
version) rvm-version ;;
+ reset) rvm-reset ;;
debug)
rvm-version
- info "GEM_HOME: $GEM_HOME\nMY_RUBY_HOME: $MY_RUBY_HOME"
- info "ruby: `which ruby`\ngem: `which gem`\nirb: `which irb`"
- info "PATH:$(echo $PATH | awk -F":" '{print $1":"$2":"$3":"$4":"%5}')"
- info "\n.bash_profile: \n$(cat ~/.bash_profile | tail -n 5)\n"
- info "\n.rvm/current: \n$(cat ~/.rvm/current)\n"
+ 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"
return 0
;;
*)
if [ ! -z "$action" ] ; then
- fail "unknown action '$action'"
+ rvm-log-fail "unknown action '$action'"
else
rvm-usage
fi
return 1
esac
- set +x
+ if [ "$debug" = "1" ] ; then set +x ; fi
}