-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·103 lines (90 loc) · 2.56 KB
/
install.sh
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
#!/bin/bash
set -e
homebrew=
type -p brew >/dev/null && homebrew=1
if ! type -p git >/dev/null; then
git() {
echo "Error: git is required to proceed. Please install git and try again." >&2
exit 1
}
fi
rbenv="$(command -v rbenv ~/.rbenv/bin/rbenv | head -1)"
if [ -n "$rbenv" ]; then
echo "rbenv already seems installed in \`$rbenv'."
cd "${rbenv%/*}"
if [ -x ./brew ]; then
echo "Trying to update with Homebrew..."
brew update >/dev/null
if brew list rbenv | grep -q rbenv/HEAD; then
brew reinstall rbenv
else
brew upgrade rbenv
fi
elif git remote -v 2>/dev/null | grep -q rbenv; then
echo "Trying to update with git..."
git pull --tags origin master
cd ..
fi
else
if [ -n "$homebrew" ]; then
echo "Installing rbenv with Homebrew..."
brew update
brew install rbenv
rbenv="$(brew --prefix)/bin/rbenv"
else
echo "Installing rbenv with git..."
mkdir -p ~/.rbenv
cd ~/.rbenv
git init
git remote add -f -t master origin https://github.com/rbenv/rbenv.git
git checkout -b master origin/master
rbenv=~/.rbenv/bin/rbenv
fi
fi
rbenv_root="$("$rbenv" root)"
ruby_build="$(command -v "$rbenv_root"/plugins/*/bin/rbenv-install rbenv-install | head -1)"
echo
if [ -n "$ruby_build" ]; then
echo "\`rbenv install' command already available in \`$ruby_build'."
cd "${ruby_build%/*}"
if [ -x ./brew ]; then
echo "Trying to update with Homebrew..."
brew update >/dev/null
brew upgrade ruby-build
elif git remote -v 2>/dev/null | grep -q ruby-build; then
echo "Trying to update with git..."
git pull origin master
fi
else
if [ -n "$homebrew" ]; then
echo "Installing ruby-build with Homebrew..."
brew update
brew install ruby-build
else
echo "Installing ruby-build with git..."
mkdir -p "${rbenv_root}/plugins"
git clone https://github.com/rbenv/ruby-build.git "${rbenv_root}/plugins/ruby-build"
fi
fi
# Enable caching of rbenv-install downloads
mkdir -p "${rbenv_root}/cache"
# Detect the type of shell that invoked the installer:
shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)"
shell="${shell%% *}"
shell="${shell##-}"
shell="${shell:-$SHELL}"
shell="${shell##*/}"
case "$shell" in
bash | zsh| ksh | ksh93 | mksh | fish )
# allow known shells to be configured
;;
* )
# default to bash in case the parent process is not a known shell
shell=bash
;;
esac
echo
echo "Setting up your shell with \`rbenv init $shell' ..."
"$rbenv" init "$shell"
echo
echo "All done! After reloading your terminal window, rbenv should be good to go."