From: Bryan Dunsmore Date: 2011-12-30T02:24:44+09:00 Subject: Re: I: rvmsh: An easy installer for RVM 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 ` 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" > +latest="https://raw.github.com/petervandenabeele/rvmsh/master/ruby/latest" > 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 -- Posted via http://www.ruby-forum.com/.