This repository was archived by the owner on Jul 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbrew-bootstrap-rbenv-ruby
More file actions
executable file
·108 lines (91 loc) · 2.61 KB
/
brew-bootstrap-rbenv-ruby
File metadata and controls
executable file
·108 lines (91 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
#: `Usage: brew bootstrap-rbenv-ruby` [--debug]
#:
#: Installs Ruby and Bundler.
set -e
if [ "$1" = "--debug" ]; then
shift
PRINT_DEBUG="1"
set -x
fi
warn() { echo "$@" >&2; }
abort() { EXPECTED_EXIT="1"; warn "$@"; exit 1; }
abort_for_sh() {
abort 'Error: add `eval "$(rbenv init -)"` to the end of your .bash_profile!'
}
abort_for_zsh() {
abort 'Error: add `eval "$(rbenv init -)"` to the end of your .zshrc!'
}
abort_for_fish() {
abort 'Error: add `status --is-interactive; and . (rbenv init -|psub)` to the end of your .config/fish/config.fish!'
}
abort_with_shell_setup_message() {
case $(basename ${SHELL:-bash}) in
sh|bash)
abort_for_sh
;;
zsh)
abort_for_zsh
;;
fish)
abort_for_fish
;;
# tcsh users are on their own
*)
abort 'Error: you must finish setting up rbenv in your shell; check `rbenv init` for instructions!'
esac
}
cleanup() {
set +e
if [ -n "$EXPECTED_EXIT" ]; then
return
fi
warn "Error: $(basename $0) failed!"
if [ -z "$PRINT_DEBUG" ]; then
warn "For debugging output run:"
warn " $0 --debug"
warn "If you're stuck: file an issue with debugging output at:"
warn " https://github.com/github/homebrew-bootstrap/issues/new"
fi
}
trap "cleanup" EXIT
BASE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
if ! which rbenv &>/dev/null; then
abort "Error: you need to 'brew install rbenv'!"
fi
if ! rbenv version-name &>/dev/null; then
if ! [[ -z "$RBENV_VERSION" ]]; then
RUBY_REQUESTED="$RBENV_VERSION"
else
RUBY_REQUESTED="$(rbenv local)"
fi
RUBY_DEFINITION="$(ruby-build --definitions | grep "^$RUBY_REQUESTED$" || true)"
if [ -z "$RUBY_DEFINITION" ]; then
RUBY_DEFINITION="$BASE_PATH/ruby-definitions/$RUBY_REQUESTED"
if ! [ -f "$RUBY_DEFINITION" ]; then
warn "Error: cannot find Ruby $RUBY_REQUESTED definition in ruby-build or at:"
abort "$RUBY_DEFINITION"
fi
fi
# use workaround for necessary for some Ruby versions
# https://github.com/ffi/ffi/issues/869#issuecomment-752123090
if [ "$(uname -sm)" = "Darwin arm64" ]; then
export RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC
fi
rbenv install --skip-existing "$RUBY_DEFINITION"
fi
if [ "$(rbenv exec ruby --version)" != "$(ruby --version)" ]; then
abort_with_shell_setup_message
fi
(rbenv which bundle &>/dev/null && bundle -v &>/dev/null) || {
# Bundler 2 doesn't support Ruby 2.x or below, but
# Rubygems won't automatically pick a compatible Bundler for us. Boo!
if [[ "$RUBY_REQUESTED" < "2.3" ]]; then
gem install bundler -v '<2'
else
gem install bundler
fi
rbenv rehash
}
EXPECTED_EXIT="1"
exit 0