2011-09-12 20:28:24 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
set -e
|
|
|
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
|
|
|
|
|
2011-09-13 13:16:03 -05:00
|
|
|
# Provide rbenv completions
|
|
|
|
|
if [ "$1" = "--complete" ]; then
|
|
|
|
|
exec ruby-build --definitions
|
|
|
|
|
fi
|
|
|
|
|
|
2011-09-12 20:28:24 -05:00
|
|
|
if [ -z "$RBENV_ROOT" ]; then
|
|
|
|
|
RBENV_ROOT="${HOME}/.rbenv"
|
|
|
|
|
fi
|
|
|
|
|
|
2012-08-15 14:02:23 -05:00
|
|
|
# Load shared library functions
|
2012-08-15 14:43:44 -05:00
|
|
|
eval "$(ruby-build --lib)"
|
2012-08-15 14:02:23 -05:00
|
|
|
|
|
|
|
|
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-12 20:38:48 -05:00
|
|
|
echo
|
2012-08-15 14:02:23 -05: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-12 20:38:48 -05:00
|
|
|
echo
|
|
|
|
|
} >&2
|
2012-08-15 14:02:23 -05: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-12 20:38:48 -05:00
|
|
|
|
2012-08-15 23:49:13 -03:00
|
|
|
for script in $(rbenv-hooks install); do
|
|
|
|
|
source "$script"
|
|
|
|
|
done
|
|
|
|
|
|
2011-09-12 20:38:48 -05:00
|
|
|
VERSION_NAME="${DEFINITION##*/}"
|
|
|
|
|
PREFIX="${RBENV_ROOT}/versions/${VERSION_NAME}"
|
|
|
|
|
|
2012-04-28 14:26:52 -07: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 14:02:23 -05:00
|
|
|
KEEP="-k"
|
2012-04-28 14:26:52 -07:00
|
|
|
fi
|
|
|
|
|
|
2012-11-13 17:34:08 -06:00
|
|
|
if [ -z "${RUBY_BUILD_CACHE_PATH}" ] && [ -d "${RBENV_ROOT}/cache" ]; then
|
|
|
|
|
export RUBY_BUILD_CACHE_PATH="${RBENV_ROOT}/cache"
|
Simple, optional tarball cache support
Rationale:
Both in development and in production, some usage patterns of ruby-build
are slowed down by the download phase. In scenarios such as
troubleshooting failing builds or with provisioning situations (chef,
vagrant...) the repeated download is unnerving, bandwidth wasting and
simply against etiquette towards tarball hosters.
It also happens that some source sites happen to be down and in such
cases it is helpful to be able to sideload sources to rbenv.
Behavior:
By default nothing changes.
If the variable CACHE_PATH is set, then ruby-build will use that
directory to store a successful download, and will check before
downloading if the tarball is already there, in which case downloading
is skipped.
The file is first downloaded as before in the tmp subdirectory and only
moved afterwards, thus ensuring consistency.
There is no default cache path and the optional variable is to be set by
hand, ensuring people know what they're doing when using ruby-build.
Additionnally, rbenv-install will helpfully set CACHE_PATH if and only
if a RBENV_ROOT/cache directory exists. Again, the directory has to be
created manually.
The CACHE_PATH variable internally ends with a slash to mutualize
non-cached cases. Still, consistency is ensured whether or not a slash
is provided externally.
Notes:
I'm not quite sure CACHE_PATH is a good name, maybe
RUBY_BUILD_CACHE_PATH is better and less conflicting.
2012-11-07 16:43:15 +01:00
|
|
|
fi
|
|
|
|
|
|
2012-08-15 14:02:23 -05:00
|
|
|
ruby-build $KEEP $VERBOSE "$DEFINITION" "$PREFIX"
|
2012-04-28 14:26:30 -07:00
|
|
|
rbenv rehash
|