rbenv-ruby-build/bin/rbenv-install

75 lines
1.7 KiB
Text
Raw Normal View History

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
# 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
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
[ -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}"
# 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
ruby-build $KEEP $VERBOSE "$DEFINITION" "$PREFIX"
rbenv rehash