bash/rvm-install in rvm-0.0.14 vs bash/rvm-install in rvm-0.0.15

- old
+ new

@@ -1,37 +1,96 @@ #!/bin/bash user=`whoami` if [ "$user" = "root" ] ; then - echo -e "\e[0;31m <e> \e[0mroot user support is not yet implemented." + echo -e "\e[0;31m <e> \e[0mroot user support is not yet implemented.\e[0m" exit 1 fi -mkdir -p ~/.rvm/src ~/.rvm/bin +info="\n\e[0;32m<i>\e[0m" +question="\n\e[0;32m<?>\e[0m" +echo -e "Installing rvm source to ~/.rvm/bin/rvm..." +mkdir -p ~/.rvm/src ~/.rvm/bin cp $(pwd)/bash/rvm ~/.rvm/bin/ -touch ~/.profile -if [ -z "`grep '\.rvm/bin/rvm' ~/.profile`" ] ; then - echo "Adding 'source ~/.rvm/bin/rvm' to your ~/.profile." - echo "source ~/.rvm/bin/rvm" >> ~/.profile -fi +# State what is required to use rvm +echo -e "\n\e[0;32mrvm\e[0m is a shell script that allows a user to manage multiple ruby versions in their own account." +echo -e "$info In order to use rvm two items must occur in your shell's load paths:" +echo -e "\n\e[0;32m (a)\e[0m if [ -f ~/.rvm/bin/rvm ] ; then source ~/.rvm/bin/rvm ; fi" +echo -e "\e[0;32m (b)\e[0m if [ -f ~/.rvm/current ] ; then source ~/.rvm/current ; fi" -if [ -z "`grep '\.rvm/current' ~/.profile`" ] ; then - echo "Adding 'source ~/.rvm/current' ~/.profile." - echo "if [ -f ~/.rvm/current ] ; then source ~/.rvm/current ; fi" >> ~/.profile -fi +echo -n -e "$question Would you like (u)s to set this up for you, or do it (y)ourself (u/y)? " +while : ; do + read response + if [ "${response:0:1}" = "u" ] ; then + echo 'w00t!' + break + elif [ "${response:0:1}" = "f" ] ; then + echo -e "$info Please make sure that both lines (a) and (b) are in place, with (a) sourced *first*." + break + else + echo -n -e "$question Would you like (u)s to set this up for you, or do it yoursel(f) (u/f)? " + fi +done -touch ~/.bash_profile -if [ -z "`grep '\.profile' ~/.bash_profile`" ] ; then - echo "Adding 'source ~/.profile' to the end of ~/.bash_profile." - echo "if [ -f ~/.profile ] ; then source ~/.profile ; fi" >> ~/.bash_profile -fi +if [ "${response:0:1}" = "u" ] ; then -touch ~/.zprofile -if [ -z "`grep '\.profile' ~/.zprofile`" ] ; then - echo "Adding 'source ~/.profile' to the end of ~/.zprofile." - echo "if [ -f ~/.profile ] ; then source ~/.profile ; fi" >> ~/.zprofile + # Find out the user's shell bash / zsh + echo -n -e "$question Do you use (b)ash or (z)sh for your shell (the default on most *nix systems is bash, press control + C to cancel the installation)\n(b/z) ? " + while : ; do + read response + if [ "${response:0:1}" = "b" ] ; then + user_shell="bash" + break + elif [ "${response:0:1}" = "z" ] ; then + user_shell="zsh" + break + else + echo -n -e "$question Do you use (b)ash or (z)sh for your shell (the default on most *nix systems is bash, press control + C to cancel the installation)\n(b/z) ? " + fi + done + + touch ~/.profile + + if [ "$user_shell" = "bash" ] ; then + + touch ~/.bash_profile + if [ -z "`grep '\.rvm/bin/rvm' ~/.bash_profile`" ] ; then + echo "Adding 'if [ -f ~/.rvm/bin/rvm ] ; then source ~/.rvm/bin/rvm ; fi' to your ~/.bash_profile." + echo "if [ -f ~/.rvm/bin/rvm ] ; then source ~/.rvm/bin/rvm ; fi" >> ~/.bash_profile + fi + + if [ -z "`grep '\.rvm/current' ~/.bash_profile`" ] ; then + echo "Adding 'if [ -f ~/.rvm/current ] ; then source ~/.rvm/current ; fi' ~/.bash_profile." + echo "if [ -f ~/.rvm/current ] ; then source ~/.rvm/current ; fi" >> ~/.bash_profile + fi + + elif [ "$user_shell" = "zsh" ] ; then + + touch ~/.zshrc + if [ -z "`grep '\.rvm/bin/rvm' ~/.zshrc`" ] ; then + echo "Adding 'if [ -f ~/.rvm/bin/rvm ] ; then source ~/.rvm/bin/rvm ; fi' to your ~/.zshrc." + echo "if [ -f ~/.rvm/bin/rvm ] ; then source ~/.rvm/bin/rvm ; fi" >> ~/.zshrc + fi + + if [ -z "`grep '\.rvm/current' ~/.zshrc`" ] ; then + echo "Adding 'if [ -f ~/.rvm/current ] ; then source ~/.rvm/current ; fi' ~/.zshrc." + echo "if [ -f ~/.rvm/current ] ; then source ~/.rvm/current ; fi" >> ~/.zshrc + fi + + else + + echo -e "\n\e[0;31m<e> An error has occurred, we were expecting either bash or zsh however we encountered $user_shell \e[0m" + return 1 + + fi fi -echo -e "\n\e[0;32mOpen a new shell and enjoy rvm: rvm usage\e[0m\n" +echo -e "\n$info If you add ~/.rvm/bin/ to your path you will be able to rever to installed ruby binaries using: <implementation>-<version>p<patchlevel>" +echo -e " For example: ~/.ruby-1.9.1p243 -e 'puts \"hello world\"' #=> hello world" +echo -e "$info Contact wayneeseguin on irc.freenod.net in #rvm for any questions / feedback." +echo -e " I truely hope that you find rvm helpful! Thank you very much for using rvm. \n" +echo -e " ~ Wayne" + +echo -e "$info To start using rvm see: \e[0;32m rvm usage\e[0m, Now close this login shell and open a new one."