2011-09-13 03:28:24 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
|
|
|
|
2011-09-13 20:16:03 +02:00
|
|
|
# Provide rbenv completions
|
|
|
|
if [ "$1" = "--complete" ]; then
|
|
|
|
exec ruby-build --definitions
|
|
|
|
fi
|
|
|
|
|
2011-09-13 03:28:24 +02:00
|
|
|
if [ -z "$RBENV_ROOT" ]; then
|
|
|
|
RBENV_ROOT="${HOME}/.rbenv"
|
|
|
|
fi
|
|
|
|
|
2012-08-15 21:02:23 +02:00
|
|
|
# Load shared library functions
|
|
|
|
eval "$(ruby-build --lib)" && lib
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
{ echo "usage: rbenv install [-k|--keep] [-v|--verbose] VERSION"
|
|
|
|
echo " rbenv install [-k|--keep] [-v|--verbose] /path/to/definition"
|
|
|
|
echo " rbenv install -l|--list"
|
2011-09-13 03:38:48 +02:00
|
|
|
echo
|
2012-08-15 21:02:23 +02:00
|
|
|
echo " -l/--list List all available versions"
|
|
|
|
echo " -k/--keep Keep source tree in \$RBENV_BUILD_ROOT after installation"
|
|
|
|
echo " (defaults to ${RBENV_ROOT}/sources)"
|
|
|
|
echo " -v/--verbose Verbose mode: print compilation status to stdout"
|
2011-09-13 03:38:48 +02:00
|
|
|
echo
|
|
|
|
} >&2
|
2012-08-15 21:02:23 +02:00
|
|
|
|
|
|
|
[ -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
|
2011-09-13 03:38:48 +02:00
|
|
|
|
|
|
|
VERSION_NAME="${DEFINITION##*/}"
|
|
|
|
PREFIX="${RBENV_ROOT}/versions/${VERSION_NAME}"
|
|
|
|
|
2012-04-28 23:26:52 +02:00
|
|
|
# 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}"
|
2012-08-15 21:02:23 +02:00
|
|
|
KEEP="-k"
|
2012-04-28 23:26:52 +02:00
|
|
|
fi
|
|
|
|
|
2012-08-15 21:02:23 +02:00
|
|
|
ruby-build $KEEP $VERBOSE "$DEFINITION" "$PREFIX"
|
2012-04-28 23:26:30 +02:00
|
|
|
rbenv rehash
|