--20cf3074d8e6668d9404b537ed64
Content-Type: text/plain; charset=UTF-8

On Thu, Dec 29, 2011 at 3:28 AM, Bryan Dunsmore <dunsmoreb / gmail.com> wrote:

> I have recently begun work on a project called [rvmsh]
> (https://github.com/dunsmoreb/rvmsh); an easy installer for RVM.
>
>
> What it does is:
>
>  + Install prerequisites
>  + Download RVM
>  + Load RVM
>  + Source ~/.bashrc
>  + Test for RVM
>  + Offer to install latest ruby
>
> I'm open to any suggestions and even encourage them.  I would also be
> happy if people would try it out on their systems and tell me if it
> works.
>

Thanks you for the work, interesting.

I was trying to use it for single user installation on Ubuntu (10.04) and
had
to make a few tweaks to make it work in single mode. Full code at
https://github.com/petervandenabeele/rvmsh

I'll explain what I changed.

diff --git a/ruby/latest b/ruby/latest
index d72af3d..67b8bc0 100644
--- a/ruby/latest
+++ b/ruby/latest
@@ -1 +1 @@
-ruby-1.9.3-head
+ruby-1.9.3

Assuming this script is intended for quick/easy installs of rvm for users,
I prefer to have the current stable version of ruby as the default install.

diff --git a/rvm b/rvm
index 3359a4c..2a507a4 100755
--- a/rvm
+++ b/rvm
@@ -29,7 +29,8 @@
 for app in bash awk sed grep which ls cp tar curl gunzip bunzip2 git svn;
do
  which $app &> /dev/null

  if [ "$?"  1" ]; then
- sudo $installer install $app
+                echo The app $app is not installed
+                exit 1
  fi
 done

For a single user install and with a "new" script, I prefer not to give sudo
rights to the user. So, when a package is missing, I prefer to let me know,
and then I will go in manually and install it with sudo from my main
account.


@@ -41,11 +42,15 @@
 echo "$installer" | grep -P "(apt-get|apt)" &> /dev/null
 if [ "$?"  0" ]; then
  for app in build-essential openssl libreadline6 libreadline6-dev zlib1g
zlib1g-dev \
            libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3
libxml2-dev \
-           libxslt-dev autoconf libc6-dev ncurses-dev automake libtool
bison; do
- which $app &> /dev/null
+           libxslt1-dev autoconf libc6-dev libncurses5-dev automake
libtool bison; do
+                # which $app &> /dev/null
+                # ONLY works on Debian derived distro's
+                # TODO similar for yum
+ dpkg -l $app | grep ^ii &> /dev/null

This seems a significant bug. I wonder how this passed your testing on
Debian/Ubuntu.

You use `which <command>` to see if a package is installed. But ... e.g.
for the package
'build-essential' there is no 'build-essential' command that is installed
(at least not on
Ubuntu 10.04).

My solution DEBIAN ONLY is to check with dpkl -l | grep ^ii

I did not test the yum side, maybe a similar fix is required there ?

Also, on a recent Ubuntu, the installed packages are installed as
alternatives,
so, 'ncurses-dev' becomes 'libncurses5-dev'. For better robustness, we need
to find a way that checks for either one of the packages (or use the dpkg
system to discover in a more fundamental way if the ncurses-dev dependencies
are met). Same for libxslt-dev.


  if [ "$?"  1" ]; then
- sudo $installer install $app
+                        echo The app $app is not installed
+                        exit 1
  fi
  done
 fi


Same as above, for single-user installs, the script should work without
sudo.


@@ -99,8 +104,8 @@
 case "$mode" in
  touch ~/.bashrc
  fi

- echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"' >>
~/.bashrc
- source ~/.bashrc
+        # do the load here, since the return in top of bash made this fail
+ [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
  ;;


I presume(??), this is the tricky known issue where the line [ref A]

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

returns for non interactive shells and this fails to load rvm. So, as a
quick hack,
I simply ran the line straight from rvmsh.

Also, don't add that line yourself. Rvm already adds the line. And also,
when running
rvmsh multiple times, it added the line everytime again.

@@ -126,15 +131,16 @@ if [ "$mode"  single" ]; then
 fi

 # Test if RVM is installed.
-which rvm &> /dev/null
+echo "rvm is installed here:"
+which rvm

I prefer to actually see where rvm is installed.

-if [ "$?"  0" ]; then
+if [ "$?"  1" ]; then
  echo "There was an error installing RVM!"
  exit
 fi

This seems like a hard bug. You want to bail out when the rvm _failed_, do
you,
and not when it succeeded ? I presume, it actually never passed in your
tests
(because the rvm loading never really happened because of the return in the
top of .bashrc, see [ref A] above). Bailing out on failure seems more
correct to
me, but I may be wrong.

 # Offer to install latest ruby.
-latestttps://raw.github.com/dunsmoreb/rvmsh/master/ruby/latest"
+latestttps://raw.github.com/petervandenabeele/rvmsh/master/ruby/latest"
 versioncurl -s $latest)

I prefer the latest stable version. Rvm will automatically select the
latest stable
version (the one with the [-pxxx] at the end).

Still this method has a flow that we need to update manually when Ruby/rvm
upgrades
and eventually we will forget. An automatic method would be better ...
Maybe rvm has
a proper way to inform us of the latest stable MRI ruby (sorry I didn't
look it up now).

 read -n 1 -p "Would you like rvmsh to install the latest ruby ($version)
for you? (Y/n) " ans
@@ -157,3 +163,4 @@ fi

 # Done, congratulations.
 echo "Congratulations!  RVM was successfully installed."
+echo "run 'source ~/.bashrc' now to activate rvm"

Inside the script, rvm got loaded (with my hack of executing the load line
directly), but
outside of the script, rvm seems not be loaded yet. So, I add a message to
inform the
user about that.

My patches are certainly hackish, but it works and thanks again for this
useful script.

Peter

PS. A log from a successful single-user install

new_user@ASUS:~$ mkdir ruby
new_user@ASUS:~$ cd ruby/
new_user@ASUS:~/ruby$ git clone git://github.com/petervandenabeele/rvmsh.git
...
new_user@ASUS:~/ruby$ cd rvmsh/
new_user@ASUS:~/ruby/rvmsh$ ./rvm
rvm is installed here:
/home/new_user/.rvm/bin/rvm
Would you like rvmsh to install the latest ruby (ruby-1.9.3) for you? (Y/n)
y
Installing Ruby from source to: /home/new_user/.rvm/rubies/ruby-1.9.3-p0,
this may take a while depending on your cpu(s)...
...
Would you like rvmsh to set ruby-1.9.3 as the default ruby for you? (Y/n) y
Using /home/new_user/.rvm/gems/ruby-1.9.3-p0

Congratulations!  RVM was successfully installed.
run 'source ~/.bashrc' now to activate rvm
new_user@ASUS:~/ruby/rvmsh$ source ~/.bashrc
new_user@ASUS:~/ruby/rvmsh$ type rvm | head -1
rvm is a function

-- 
Peter Vandenabeele
http://twitter.com/peter_v
http://rails.vandenabeele.com

--20cf3074d8e6668d9404b537ed64--