ruby-build/bin/rbenv-install
2012-12-30 15:29:52 -06:00

89 lines
2.2 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Summary: Install a Ruby version using the ruby-build plugin
#
# Usage: rbenv install [-k|--keep] [-v|--verbose] <version>
# rbenv install [-k|--keep] [-v|--verbose] /path/to/definition
# rbenv install -l|--list
#
# -l/--list List all available versions
# -k/--keep Keep source tree in $RBENV_BUILD_ROOT after installation
# (defaults to $RBENV_ROOT/sources)
# -v/--verbose Verbose mode: print compilation status to stdout
#
# For detailed information on installing Ruby versions with
# ruby-build, including a list of environment variables for adjusting
# compilation, see: https://github.com/sstephenson/ruby-build#usage
#
set -e
[ -n "$RBENV_DEBUG" ] && set -x
# Provide rbenv completions
if [ "$1" = "--complete" ]; then
exec ruby-build --definitions
fi
if [ -z "$RBENV_ROOT" ]; then
RBENV_ROOT="${HOME}/.rbenv"
fi
# Load shared library functions
eval "$(ruby-build --lib)"
usage() {
# We can remove the sed fallback once rbenv 0.4.0 is widely available.
rbenv-help install 2>/dev/null || sed -ne '/^#/!q;s/.//;s/.//;1,4d;p' < "$0"
[ -z "$1" ] || exit "$1"
}
unset KEEP
unset VERBOSE
parse_options "$@"
for option in "${OPTIONS[@]}"; do
case "$option" in
"h" | "help" )
usage 0
;;
"l" | "list" )
echo "Available versions:"
ruby-build --definitions | sed 's/^/ /'
exit
;;
"k" | "keep" )
[ -n "${RBENV_BUILD_ROOT}" ] || RBENV_BUILD_ROOT="${RBENV_ROOT}/sources"
;;
"v" | "verbose" )
VERBOSE="-v"
;;
"version" )
exec ruby-build --version
;;
* )
usage 1
;;
esac
done
DEFINITION="${ARGUMENTS[0]}"
[ -n "$DEFINITION" ] || usage 1
for script in $(rbenv-hooks install); do
source "$script"
done
VERSION_NAME="${DEFINITION##*/}"
PREFIX="${RBENV_ROOT}/versions/${VERSION_NAME}"
# If RBENV_BUILD_ROOT is set, then always pass keep options to ruby-build
if [ -n "${RBENV_BUILD_ROOT}" ]; then
export RUBY_BUILD_BUILD_PATH="${RBENV_BUILD_ROOT}/${VERSION_NAME}"
KEEP="-k"
fi
if [ -z "${RUBY_BUILD_CACHE_PATH}" ] && [ -d "${RBENV_ROOT}/cache" ]; then
export RUBY_BUILD_CACHE_PATH="${RBENV_ROOT}/cache"
fi
ruby-build $KEEP $VERBOSE "$DEFINITION" "$PREFIX"
rbenv rehash