Rvmsh: An easy installer for RVM

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.

Thank you.

···

--
Posted via http://www.ruby-forum.com/.

I would like to see it use sh/.profile instead of bash/.bashrc, actually.
One of the things I don't like about the current installation procedure
for RVM is its reliance on Bash. That is, in fact, the *only* reason I
have Bash installed on a couple of machines.

If it offered the ability to do without Bash when installing RVM, I'd
like to help with testing on FreeBSD.

···

On Thu, Dec 29, 2011 at 11:28:16AM +0900, Bryan Dunsmore 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.

Thank you.

--
Chad Perrin

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.
-latest="https://raw.github.com/dunsmoreb/rvmsh/master/ruby/latest&quot;
+latest="https://raw.github.com/petervandenabeele/rvmsh/master/ruby/latest&quot;
version=$(curl -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

···

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.

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

Just released rvmsh v1.0.1. All it does is fix all bugs mentioned by
Peter. A record of these bugs can be found on our [git
repo](https://github.com/dunsmoreb/rvmsh/issues).

···

--
Posted via http://www.ruby-forum.com/.

Awesome. Thanks for your help.

···

--
Posted via http://www.ruby-forum.com/.

Just released rvmsh v1.0.2. Like the last release it fixes all the bugs
found by Peter (Grr...), nothing new (except for the bug fixes...).

···

--
Posted via http://www.ruby-forum.com/.

-----Messaggio originale-----

···

Da: Chad Perrin [mailto:code@apotheon.net]
Inviato: giovedì 29 dicembre 2011 07:37
A: ruby-talk ML
Oggetto: Re: rvmsh: An easy installer for RVM

On Thu, Dec 29, 2011 at 11:28:16AM +0900, Bryan Dunsmore 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.

Thank you.

I would like to see it use sh/.profile instead of bash/.bashrc, actually.
One of the things I don't like about the current installation procedure for
RVM is its reliance on Bash. That is, in fact, the *only* reason I have
Bash installed on a couple of machines.

If it offered the ability to do without Bash when installing RVM, I'd like
to help with testing on FreeBSD.

--
Chad Perrin

--
Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f

Sponsor:
Conto Arancio al 4,20%. Zero spese e massima liberta', aprilo in due minuti!
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid919&d)-12

Thanks. I just tried your new version and at least for the easy case
(all dpkg packages where already installed), it worked flawlessly.

I added 1 further feature request and 1 probable bug report on github.

Thanks,

Peter

···

On Thu, Dec 29, 2011 at 10:25 PM, Bryan Dunsmore <dunsmoreb@gmail.com>wrote:

Just released rvmsh v1.0.1. All it does is fix all bugs mentioned by
Peter. A record of these bugs can be found on our [git
repo](https://github.com/dunsmoreb/rvmsh/issues\).

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

Chad Perrin wrote in post #1038527:

I would like to see it use sh/.profile instead of bash/.bashrc,
actually.

I would implement this, but there is no use if RVM needs bash anyways.

Peter Vandenabeele wrote in post #1038701:

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

That's strange, it works for me in single mode.

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.

Good point, I'll change this on the main branch.

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.

Good point. I'll probably implement this as a switch instead of making
it the default, though.

@@ -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.

I tested this on Fedora 16 and it worked on there...

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).

Good point, thank you for pointing that out.

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 ?

This works on the yum side, but I'll try to find a similar fix with RPM
to make sure this kind of problem never occurs.

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.

I just grabbed these requirements from the RVM site, but I see where you
are coming from.

@@ -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.

Good point. I'm going to keep the line that adds RVM to `~/.bashrc`
though as I have had to do that every time.

Rvm already adds the line. And also,
when running
rvmsh multiple times, it added the line everytime again.

I'll make sure to check for that line before adding it.

@@ -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.

Okay, seems like a reasonable default.

-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.

I got you Mr. Sarcastic :P. That is a typo though.

# Offer to install latest ruby.
-latest="https://raw.github.com/dunsmoreb/rvmsh/master/ruby/latest&quot;
+latest="https://raw.github.com/petervandenabeele/rvmsh/master/ruby/latest&quot;
version=$(curl -s $latest)

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

Good point, I've always used the `head` branch and never though anything
of other users wanting to have something more stable :P.

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).

I may add that in the future. Sounds more like a cron job though,
running a separate script every three or two months.

+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.

I'm going to check for that return on interactive mode and if that is
present I will display the message.

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

Your welcome and let me thank you for your feedback. There was
certainly a lot of bugs as this was the first shell script I've ever
written.

Bryan Dunsmore
<dunsmoreb@gmail.com>

···

--
Posted via http://www.ruby-forum.com/\.

Chad Perrin wrote in post #1038527:
> I would like to see it use sh/.profile instead of bash/.bashrc,
> actually.

I would implement this, but there is no use if RVM needs bash anyways.

Does RVM itself need Bash, or just the RVM installation process?

I recall (possibly erroneously) the RVM developer saying something about
wanting to make it sh-compatible at some point in the future. I
certainly hope that will be in the works at some point, anyway. If RVM
itself requires it, and not just RVM's installation process, and the
maintainer implements sh support so that Bash is not required, it would
be kind of a bummer if your installer was then the limiting factor.

Peter Vandenabeele wrote in post #1038701:
>
> 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.

Good point. I'll probably implement this as a switch instead of making
it the default, though.

Yeah, that's a good point, and I was thinking of mentioning something
about not requiring sudo. I think the best option would be to make it a
switch so that, depending on what you choose, sudo may not be a
requirement.

···

On Fri, Dec 30, 2011 at 02:24:44AM +0900, Bryan Dunsmore wrote:

Chad Perrin wrote in post #1038774:

Does RVM itself need Bash, or just the RVM installation process?

It's one of the [prerequisites]
(http://beginrescueend.com/rvm/prerequisites/\) listed by RVM.

Yeah, that's a good point, and I was thinking of mentioning something
about not requiring sudo. I think the best option would be to make it a
switch so that, depending on what you choose, sudo may not be a
requirement.

The reason it requires `sudo` is in order to install the requirements
for RVM. The switch will just check for the requirements and tell you
what is missing.

···

--
Posted via http://www.ruby-forum.com/\.

I have been thinking about looking into where RVM might actually require
Bash, and seeing how easy it would be to make it work with sh instead.
If rvmsh offered the ability to eliminate some or all of that dependence
(perhaps by way of eliminating the dependence on Bash in the installation
routine) and did not specifically require sudo either, I would be
interested in using it, toward that end. If nothing else, it would
reduce the amount of work required to eliminate Bash dependence.

Otherwise, it does not seem to offer much for me.

···

On Fri, Dec 30, 2011 at 06:57:09AM +0900, Bryan Dunsmore wrote:

Chad Perrin wrote in post #1038774:
> Does RVM itself need Bash, or just the RVM installation process?

It's one of the [prerequisites]
(http://beginrescueend.com/rvm/prerequisites/\) listed by RVM.

--
Chad Perrin