Skip to content
Permalink
Browse files

Initial rvm, ruby, jruby, leopard functional.

  • Loading branch information...
wayneeseguin committed Aug 22, 2009
0 parents commit 038781c9bbe885f25178145e7dc76f60ba135234
Showing with 362 additions and 0 deletions.
  1. 0 .gitignore
  2. +17 −0 bash/colors
  3. +345 −0 bin/rvm
No changes.
@@ -0,0 +1,17 @@
#!/bin/bash

# Colors from http://wiki.archlinux.org/index.php/Color_Bash_Prompt
NO_COLOR='\e[0m' # Reset / disable colors

# regular colors
BLACK='\e[0;30m' ; RED='\e[0;31m' ; GREEN='\e[0;32m' ; YELLOW='\e[0;33m' ; BLUE='\e[0;34m' ; MAGENTA='\e[0;35m' ; CYAN='\e[0;36m' ; WHITE='\e[0;37m'

# emphasized (bolded) colors
EBLACK='\e[1;30m' ; ERED='\e[1;31m' ; EGREEN='\e[1;32m' ; EYELLOW='\e[1;33m' ; EBLUE='\e[1;34m' ; EMAGENTA='\e[1;35m' ; ECYAN='\e[1;36m' ; EWHITE='\e[1;37m'

# underlined colors
UBLACK='\e[4;30m' ; URED='\e[4;31m' ; UGREEN='\e[4;32m' ; UYELLOW='\e[4;33m' ; UBLUE='\e[4;34m' ; UMAGENTA='\e[4;35m' ; UCYAN='\e[4;36m' ; UWHITE='\e[4;37m'

# background colors
BBLACK='\e[40m' ; BRED='\e[41m' ; BGREEN='\e[42m' ; BYELLOW='\e[43m' ; BBLUE='\e[44m' ; BMAGENTA='\e[45m' ; BCYAN='\e[46m' ; BWHITE='\e[47m'

345 bin/rvm
@@ -0,0 +1,345 @@
#!/bin/bash

#
# Author: Wayne E. Seguin
# Version: 0.0.1
# License: MIT
# Updated: 2009.08.21
#

#
# Functions
#

function usage {
cat <<-Usage
Usage:
$0 Action [Package] [Options]
Action:
install - Install a ruby version, default is from source
use - Switch to using a specific ruby version
path - Set path for current ruby
info - Show information for current ruby
gemdir - Switch to gem directory for installation
gemdup - Clone source package version gems to target package versoin
* usage - Show this usage information
Package:
* ruby - MRI/YARV Ruby (The Standard)
jruby - jRuby
ree - Ruby Enterprise Edition
rubinius - Rubinius
leopard - Leopard's system Ruby ( Mac OS X only )
Options:
-v|--version - Ruby Package Version, defaults to 'latest'
-l|--patchlevel - Ruby version patch level
-s|--source - Source directory, default is $HOME/.src/
-p|--package - Package directory, default is $HOME/.pkg/
-m|--manager - Package Manager to use, one of:
{port,aptitude,apt-get,emerge,yum,pacman}
-d|--debug - Toggle debug mode on
Notes:
* Defaults are denoted with a * prefix.
TODO: (in order)
* Keep source & package files/directories around and test for them.
* gem-dir
* gem-dup
* Package as a gem
* Rubinius
* Package Managers option
Usage
}

# Logging functions based on level
function log { echo -e "\n $* \e[0m\n" ; }
function debug { log "\e[4;34m <d> $*" ; }
function info { log "\e[0;32m <i> $*" ; }
function warn { log "\e[0;33m <w> $*" ; }
function error { log "\e[0;31m <e> $*" ; }
function fail { log "\e[0;31m <e> $*" ; exit 1 ; }

function ruby-gi { gem install -q --no-rdoc --no-ri $* ; }

function package-manager {
case "$manager" in
yum|port|aptitude|apt-get) $manager install $1 ;;
emerge) $manager -ugD $1 ;;
pacman) $manager -Sy $1 ;;
*) usage ; exit 1
esac
}

function ruby-info {
full_version=$(ruby -v)
ruby_package=$(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:
package: "$ruby_package"
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"
Info

# Additionally, if using zsh, set right PS1 with ruby version
if [ "$RPS1" = "" ] ; then # right PS1
RPS1="$ruby_version" ; export RPS1
fi
}

function ruby-install-source {

case "${version-$1}" in
1.9|1.9.1) major="1.9" ; minor="1" ; patchlevel="${2-243}" ;;
1.8.6) major="1.8" ; minor="6" ; patchlevel="${2-369}" ;;
1.8.7) major="1.8" ; minor="7" ; patchlevel="${2-174}" ;;
*) fail "Ruby version '$version' is unknown."
esac

package_name="ruby-$major.$minor-p$patchlevel"
file_name="$package_name.tar.gz"
url="ftp://ftp.ruby-lang.org/pub/ruby/$major/$file_name"

pushd $source_path
if [ -d $package_name ] ; then
cd $package_name
else
if [ ! -f "$file_name" ] ; then $curl $url ; fi
tar xzf $package_name.tar.gz && cd $package_name/
fi
./configure --prefix=$package_path/$package_name --enable-shared && make && make install
popd
}

function ruby-install {

case "$package" in
leopard) # no-op
system_type=`uname`
if [ "$system_type" = "Darwin" ] ; then
echo "Leopard ruby is not installable via rvm."
exit 0
else
fail "leopard ruby is the default ruby installed on Mac OS X (Darwin), you are on: $system_type"
fi
;;

ree)
version=${version2-1.8.6}
patchlevel=${patchlevel-20090610}
package_name="ruby-enterprise-$version-$patchlevel"
url="http://rubyforge.org/frs/download.php/58677/$package_name.tar.gz"
pushd $source_path
if [ -d $package_name ] ; then
cd $package_name
else
if [ ! -f "$package_name.tar.gz" ] ; then $curl $url ; fi
tar xzf $package_name.tar.gz && cd $package_name/
fi
cd ruby-enterprise-$version-$patchlevel && ./installer -a $package_path/ruby-enterprise-$version-$patchlevel --dont-install-useful-gems &&
cd $source_path
popd
;;

jruby)
version=${version-1.3.1} # 1.2.0, 1.3.1
patchlevel="" # No patchlevel for jRuby
package_name="$package-$version"
url="http://dist.codehaus.org/$package/$version/$package-bin-$version.zip"
pushd $source_path
if [ -d $package_name ] ; then
cd $package_name
else
if [ ! -f "$package-bin-$version.zip" ] ; then $curl $url ; fi
jar xf $package-bin-$version.zip && cd $package_name/
fi
mkdir -p $package_path/$package-$version/bin/
for binary in jruby jgem jirb ; do
ln -sf $source_path/$package-$version/bin/$binary $source_path/$package-$version/bin/${binary#j}
done
rsync -ag $source_path/$package-$version/ $package_path/$package-$version/
cd $source_path/$package-$version/tool/nailgun && make
popd
ruby-gi jruby-openssl
;;

ruby)
version=${version-1.8.6}
ruby-install-source $version ${patchlevel-$3}
;;

*) fail "Ruby interpreter '$package' is not known."

esac

ruby-gi rake

export ruby_home GEM_HOME PATH
}

function ruby-use {

case "$package" in

leopard)
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
ruby_home="$package_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"
fi
;;

ree)
version=${version-1.8.6}
if [ "$version" = "1.8.6" ] ; then
patchlevel="${3-20090610}"
ruby_home="$package_path/ruby-enterprise-$version-$patchlevel"
GEM_HOME="$HOME/.gem/ruby/1.8"
else
fail "Unknown Ruby Enterprise Edition version: $version"
fi
;;

ruby)
if [ "$version" = "1.8.6" ] ; then
patchlevel="${patchlevel-369}"
ruby_home="$package_path/ruby-1.8.6-p$patchlevel"
GEM_HOME="$HOME/.gem/ruby/1.8"
elif [ "$version" = "1.8.7" ] ; then
patchlevel="${patchlevel-174}"
ruby_home="$package_path/ruby-1.8.7-p174"
GEM_HOME="$HOME/.gem/ruby/1.8"
elif [ "$version" = "1.9.1" -o "$version" = "1.9" ] ; then
patchlevel="${patchlevel-243}"
ruby_home="$package_path/ruby-1.9.1-p243"
GEM_HOME="$HOME/.gem/ruby/1.9"
else
fail "Unknown ruby version: $version"
fi
;;
# rubinius)

*)
fail "Ruby interpreter '$package' is not known."

esac

if [ ! -d $ruby_home ] ; then
warn "$package $version is not installed, installing."
ruby-install $package $version $patchlevel
fi
export GEM_HOME
PATH="$GEM_HOME/bin:$ruby_home/bin:$ruby_original_path" ; export PATH
RUBY_VERSION="$(ruby -v | ruby -v | sed 's/^\(.*\) (.*$/\1/')" ; export RUBY_VERSION
bash --login
}

function ruby-gem-dir {

case "$package" in
leopard) GEM_HOME="$HOME/.gem/ruby/1.8" ;;
jruby) GEM_HOME="$HOME/.gem/jruby/1.8" ;;
ree) GEM_HOME="$HOME/.gem/ruby/1.8" ;;
ruby)
if [ "$version" = "1.8.6" ] ; then
GEM_HOME="$HOME/.gem/ruby/1.8"
elif [ "$version" = "1.8.7" ] ; then
GEM_HOME="$HOME/.gem/ruby/1.8"
elif [ "$version" = "1.9.1" -o "$version" = "1.9" ] ; then
GEM_HOME="$HOME/.gem/ruby/1.9"
else
fail "Unknown ruby version: $version"
fi
;;
# rubinius)
*)
fail "Ruby interpreter '$package' is not known."
esac

}

# clones from source package/version to current
function ruby-gem-dup {
source_package=$1 ; source_version=$2

# Compile list of all gems with versions from source directory.
# if version is already installed on target version
# skip it
# else
# install it
# fi
}

#
# Setup
#
if [ -z "$ruby_original_path" ] ; then ruby_original_path=$PATH ; export ruby_original_path ; fi

while [ $# -gt 0 ] ; do
arg="$1" ; shift
case "$arg" in
install|use|path|info|gemdir|gemclone)
action=$arg ;;
ruby|jruby|ree|leopard)
package="$arg" ;;
-v|--version) version="$1" ; shift ;;
-l|--patchlevel) patchlevel="$1" ; shift ;;
-s|--source) souce_path="$1" ; shift ;;
-p|--package) package_path="$1" ; shift ;;
-m|--manager) manager="$1" ; shift ;;
-d|--debug) debug=true ;;
*) usage ; exit 1
esac
done

curl="curl -O -L -s "
package=${package-'ruby'}
source_path=${source_path-"$HOME/.rubies/src"}
package_path=${package_path-"$HOME/.rubies"}
#version=${version-}
#patchlevel=${patchlevel-}

mkdir -p $source_path $package_path

#
# Main Program Logic
#
case "$action" in
install) ruby-install $package $version $patchlevel ;;
use) ruby-use $package $version $patchlevel ;;
gemdir) ruby-gem-dir $package $version $patchlevel ;;
gemdup) ruby-gem-dup $package $version $patchlevel ;;
path) ruby-path $package $version $patchlevel ;;
info) ruby-info $package $version $patchlevel ;;
*) usage ; fail "unknown action '$action'"
esac

0 comments on commit 038781c

Please sign in to comment.
You can’t perform that action at this time.