#!/bin/bash function __rvm_meta { rvm_meta_author="Wayne E. Seguin" rvm_meta_author_email="wayneeseguin@gmail.com" rvm_meta_website="http://rvm.beginrescueend.com/" rvm_meta_version="`cat $rvm_path/lib/VERSION.yml | tail -n 3 | sed 's/^.*: //g' | tr "\n" '.' | sed 's/\.$//'`" rvm_meta_updated="2009.10.01" } function __rvm_version { __rvm_meta ; echo "rvm $rvm_meta_version ($rvm_meta_updated) [$rvm_meta_website]" ; } function __rvm_usage { __rvm_meta echo -e " rvm ${rvm_meta_version} ${rvm_meta_website} by ${rvm_meta_author} (${rvm_meta_author_email}) Usage rvm Action [Implementation] [Flags] [Options] Action * usage - show this usage information use - setup current shell to use a specific ruby version info - show information for current ruby list - show currently installed versions reload - reload rvm source itself (useful after changing rvm source) implode - removes all ruby installations it manages, everything in ~/.rvm update - upgrades rvm to the latest version. reset - remove default and current settings, exit the shell. (If you experience odd behavior try this first) debug - emit environment & configuration information for *current* ruby install - install one or many ruby versions uninstall - uninstall one or many ruby versions, leaves their sources remove - uninstall one or many ruby versions and remove their sources ruby - runs a named ruby file against specified and/or all rubies gem - runs a gem command using selected ruby's 'gem' rake - runs a rake task against specified and/or all rubies tests - runs 'rake test' across selected ruby versions specs - runs 'rake spec' across selected ruby versions gemsync - sync gems from a specified version to current version gemdir - switch to gem directory for installation (new login shell) srcdir - switch to src directory for the current ruby installation Implementation * ruby - MRI/YARV Ruby (The Standard), defaults to 1.8.6 jruby - jRuby rbx - rubinius ree - ruby Enterprise Edition system - use the system ruby (eg. pre-rvm state) default - use rvm set default ruby and system if it hasn't been set. Flags --self - with update, updates rvm itself --rubygems - with update, updates rubygems for selected ruby --default - with ruby select, sets a default ruby for new shells. --debug - Toggle debug mode on for very verbose output. --force - Force install, removes old install & source before install. --all - Used with 'rvm list' to display 'most' available versions. --dump - Used with gemset to dump the current ruby's gemset. --load - Used with gemset to load a specified gemset file --summary - Used with rubydo to print out a summary of the commands run. --jit - Used with rubinius install to build with JIT --latest - with gemset --dump skips version strings for latest gem. --reconfigure - Force ./configure on install even if Makefile already exists. Options -v|--version - Emit rvm version loaded for current shell -h|--help - Emit this output and exit -l|--level - patch level to use with rvm use / install --tag - subersion tag to use --rev - repository revision # to use or 'head' for --prefix - path for all rvm files (~/.rvm/), with trailing slash! --bin - path for binaries to be placed (~/.rvm/bin/) --source - src directory to use (~/.rvm/src/) --archives - directory for downladed files (~/.rvm/archives/) -S|--script - Specify a script file to attempt to load and run (rubydo) -G|--gems - root gem path to use -C|--configure - custom configure options, comma separated default: --enable-shared=true --reconfigure - Force installer to re-run configure if already run --make - custom make command --make-install - custom make install command --nice - process niceness (for slow computers, default 0) -m|--gem-set - use a named gem set, instead of the default set. --rm-gem-set - Remove a named gem set Resources: http://rvm.beginrescueend.com/ https://www.pivotaltracker.com/projects/26822 " | ${PAGER:-/usr/bin/less} } function __rvm_parse-args { while [ $# -gt 0 ] ; do rvm_token="$1" ; shift case "$rvm_token" in install|uninstall|path|info|setup|version|srcdir|list|reset|debug|reload|implode|update|readline|iconv|use|gemsync|gemset) rvm_action=$rvm_token ;; inspect) rvm_action=$rvm_token rvm_ruby_args=$* rvm_parse_break=1 ;; rm|remove) rvm_action=remove ;; system|default) rvm_action=${rvm_action:-use} rvm_ruby_interpreter="$rvm_token" ;; jruby|ree|macruby|rbx|rubinius|default|all) rvm_ruby_interpreter="$rvm_token" rvm_action="${rvm_action:-use}" ;; gemdir) rvm_action=$rvm_token if [ "$1" = "system" ] ; then rvm_ruby_interpreter="system" ; shift ; fi if [ "$1" = "user" ] ; then rvm_ruby_interpreter="user" ; shift ; fi rvm_ruby_interpreter="${rvm_ruby_interpreter:-current}" ;; --load|load|dump) eval "rvm_${rvm_token}_flag=1" if [ ! -z "$1" ] ; then if [ ! -z "$(echo $1 | awk '/\.gemset$/')" ] ; then rvm_gem_set_name=$(echo $1 | sed 's/\.gemset//') else rvm_gem_set_name=$1 fi shift else rvm_gem_set_name="default" fi rvm_file_name="$rvm_gem_set_name.gemset" rvm_action=$rvm_token ;; gemdup) rvm_action=$rvm_token if [ -z "$1" ] ; then rvm_ruby_interpreter="default" elif [ "$1" = "system" ] ; then rvm_ruby_interpreter=$1 ; shift elif [ "$1" = "user" ] ; then rvm_ruby_interpreter=$1 ; shift elif [ "$1" = "default" ] ; then rvm_ruby_interpreter=$1 ; shift else rvm_ruby_interpreter=$1 ; shift rvm_ruby_version=$2 ; shift fi ;; do|ruby|rake|gem|rubydo|rakedo|gemdo) if [ "$rvm_action" = "do" ] ; then rvm_action="ruby" ; fi rvm_action=$(echo $rvm_token | sed 's/do//g') if [ "$rvm_action" = "rake" -o "$rvm_action" = "gem" ] ; then rvm_action="ruby" rvm_ruby_args="$rvm_token $@" rvm_parse_break=1 else if [ ! -z "$(echo $1 | awk '/^-/')" ] ; then unset rvm_ruby_version else if [ ! -z "$(echo $1 | awk '/^[0-9]/')" ] ; then rvm_ruby_version=$(echo "$1" | tr ',' ' ') ; shift unset rvm_ruby_interpreter else if [ "$1" = "jruby" -o "$1" = "rbx" -o "$1" = "rubinius" -o "$1" = "macruby" -o "$1" = "ree" -o "$1" = "ruby-enterprise" ] ; then rvm_ruby_interpreter=$1 ; shift else unset rvm_ruby_interpreter rvm_ruby_version fi fi fi fi ;; benchmark|bench) rvm_action="benchmark" ;; specs|tests) rvm_action="do" rvm_ruby_args="rake $rvm_token" ;; 1.8|1.8.0|1.8.1|1.8.2|1.8.3|1.8.4|1.8.5|1.8.6|1.8.7|1.9|1.9.1|1.9.2) rvm_ruby_interpreter=${rvm_ruby_interpreter:-ruby} rvm_ruby_version="$rvm_token" rvm_action=${rvm_action:-use} ;; 1.2.0|1.3.1) rvm_ruby_interpreter=${rvm_ruby_interpreter:-jruby} rvm_ruby_version="$rvm_token" rvm_action=${rvm_action:-use} ;; -v|--version) if [ -z "$1" ] ; then rvm_action="version" else rvm_ruby_version="$1" shift fi ;; -t|--tag) rvm_ruby_tag="$1"; rvm_action="${rvm_action:-use}" shift ;; --head) rvm_ruby_rev="head" rvm_head_flag=1 rvm_action="${rvm_action:-use}" ;; --rev|--revision) rvm_ruby_rev="$1"; rvm_action="${rvm_action:-use}" shift ;; -b|--branch) rvm_ruby_branch="$1"; rvm_action="${rvm_action:-use}" shift ;; --bin) if [ "$rvm_action" = "update" ] ; then rvm_bin_flag=1 else rvm_bin_path="$1" ; shift fi ;; -j) if [ ! -z "$1" ] ; then rvm_make_flags="$rvm_make_flags -j$1" shift else rvm_action="error" rvm_error_message="-j *must* be followed by an integer (normally the # of CPU's in your machine)." fi ;; -C|--configure) if [ ! -z "$1" ] ; then rvm_ruby_configure="$(echo $1 | tr ',' ' ')" shift else rvm_action="error" rvm_error_message="--configure *must* be followed by configure flags." fi ;; -r|--require) if [ -z "$1" ] ; then rvm_action="error" rvm_error_message="-r|--require *must* be followed by a library name." else rvm_ruby_require="$rvm_ruby_require -r$1" shift fi ;; -I|--include) if [ -z "$1" ] ; then rvm_action="error" rvm_error_message="-I|--include *must* be followed by a path." else rvm_ruby_load_path="$rvm_ruby_load_path:$1" shift fi ;; -f|--file) rvm_action="ruby" rvm_ruby_file="$1" shift ;; -S|--script|-e|--execute) rvm_action="ruby" rvm_ruby_args="$@" rvm_parse_break=1 ;; default|system) rvm_action="use" rvm_ruby_interpreter="system" ;; --install) rvm_install_on_use_flag=1 ;; --prefix) rvm_prefix_path="$1" ; shift ;; -G|--gems) rvm_gem_path="$1" ; shift ;; --source) rvm_source_path="$1" ; shift ;; --archives) rvm_archives_path="$1" ; shift ;; --make) rvm_ruby_make="$1" ; shift ;; --make-install) rvm_ruby_make_install="$1"; shift ;; --nice) rvm_niceness="$1" ; shift ;; -l|--level) rvm_ruby_patch_level="$1" ; shift ;; -h|--help|usage|help) rvm_action=help ; shift ;; -m|--gem-set) rvm_gem_set_name="$1" ; shift ;; --rm-gem-set) rvm_gem_set_name_rm="$1" ; shift ;; tests|specs) rvm_action="tests" ;; --self|--gem|--rubygems|--reconfigure|--default|--debug|--force|--all|--dump|--summary|--jit|--latest|--yaml|--json|--archive|--shebang|--env|--path|--tail|--trace) eval "rvm_$(echo $rvm_token | sed 's/-//g')_flag=1" ;; reboot|flush|asdf|damnit|wtf|argh|work|workdamnit|BOOM|boom|wth) $rvm_action="reboot" ;; *) if [ ! -z "$rvm_token" ] ; then if [ ! -z "`echo $rvm_token | awk '/,/'`" ] ; then rvm_ruby_version="$rvm_token" if [ -z "$rvm_action" ] ; then rvm_action="ruby" # Not sure if we really want to do this but we'll try it out. fi else if [ ! -z "`echo $rvm_token | awk '/\.rb$/{print}' 2> /dev/null`" ] ; then # we have a specified ruby script rvm_ruby_args=$rvm_token rvm_ruby_file=$rvm_token if [ -z "$rvm_action" ] ; then rvm_action="ruby" # Not sure if we really want to do this but we'll try it out. fi else rvm_action="error" rvm_error_message="Unrecognized command line argument: '$rvm_token'" fi fi else rvm_action="error" rvm_error_message="Unrecognized command line argument(s): '$rvm_token $@'" fi if [ "$rvm_action" = "error" ] ; then break; fi esac if [ ! -z "$rvm_parse_break" -o ! -z "$rvm_error_message" ] ; then unset rvm_parse_break; break; fi done if [ ! -z "$rvm_error_message" ] ; then __rvm_pushpop ; return 1 ; fi } function rvm { __rvm_cleanup_variables __rvm_load-rvmrc __rvm_initialize __rvm_load_defaults __rvm_parse-args $@ if [ -z "$rvm_trace_flag" ] ; then set +x ; else set -x ; fi result=0 case "$rvm_action" in use) __rvm_use ; result=$? ;; gemdir) __rvm_gemdir ; result=$? ;; gemdup) __rvm_gemdup ; result=$? ;; srcdir) __rvm_source_dir ; result=$? ;; list) __rvm_list ; result=$? ;; version) __rvm_version ; result=$? ;; reset) __rvm_reset ; result=$? ;; # TODO: how can we use bin_path here for reload, default file? reload) __rvm_reload ; result=$? ;; implode) __rvm_implode ; result=$? ;; update) __rvm_update ; result=$? ;; readline) __rvm_readline_install ; result=$? ;; iconv) __rvm_iconv_install ; result=$? ;; reboot) __rvm_reboot ; result=$? ;; usage|help) __rvm_usage ; result=$? ;; benchmark) __rvm_benchmark ; result=$? ;; ruby) __rvm_do ; result=$? ;; inspect) __rvm_inspect ; result=$? ;; install|uninstall|remove) __rvm_manage_rubies result=$? ;; load|dump) __rvm_gemset_${rvm_action} ;; gemsync) rvm_source_gem_path=`__rvm_select ; echo $rvm_gem_home` __rvm_gem_sync ;; tests|specs) rvm_summary_flag=1 rvm_action="rake" __rvm_do ;; info|debug) __rvm_version __rvm_info if [ "$rvm_action" = "debug" ] ; then rvm_debug_flag=1 ; __rvm_debug ; fi ;; error) __rvm_log "fail" "$rvm_error_message ( see: 'rvm usage' )" __rvm_pushpop result=1; ;; *) if [ ! -z "$rvm_action" ] ; then __rvm_log "fail" "unknown action '$rvm_action'" else __rvm_usage fi result=1 esac if [ "$rvm_trace_flag" = "1" ] ; then set +x ; unset rvm_trace_flag ; fi return $result }