rbenv-installer/rbenv-doctor at master · rbenv/rbe... https://github.com/rbenv/rbenv-installer/blob/mas...
rbenv / rbenv-installer
Join GitHub today
GitHub is home to over 28 million developers working together to host and
review code, manage projects, and build software together.
Sign up
Branch: master rbenv-installer / bin / rbenv-doctor
stomar Fix typo
3 contributors
Executable File 184 lines (165 sloc) 4.83 KB
1 #!/bin/bash
2 # Usage: rbenv doctor
3 # Summary: Detects common problems in rbenv installation
4
5 set -e
6 [ -n "$RBENV_DEBUG" ] && set -x
7
8 indent() {
9 sed 's/^/ /'
10 }
11
12 printc() {
13 local color_name="color_$1"
14 local fmt="$2"
15 shift 2
16
17 if [[ $fmt == *"\n" ]]; then
18 fmt="${!color_name}${fmt%\\n}${color_reset}\n"
19 else
20 fmt="${!color_name}${fmt}${color_reset}"
21 fi
22
1 of 5 11/16/18, 9:59 AM
rbenv-installer/rbenv-doctor at master · rbenv/rbe... https://github.com/rbenv/rbenv-installer/blob/mas...
23 printf "$fmt" "$@"
24 }
25
26 if [ -t 1 ]; then
27 color_red=$'\e[31m'
28 color_green=$'\e[32m'
29 color_yellow=$'\e[1;33m'
30 color_bright=$'\e[1;37m'
31 color_reset=$'\e[0m'
32 else
33 color_red=""
34 color_green=""
35 color_yellow=""
36 color_bright=""
37 color_reset=""
38 fi
39
40 warnings=0
41
42 if [ $(uname -s) = "Darwin" ]; then
43 bashrc=".bash_profile"
44 else
45 bashrc=".bashrc"
46 fi
47
48 echo -n "Checking for \`rbenv' in PATH: "
49 num_locations="$(which -a rbenv | uniq | wc -l)"
50 if [ $num_locations -eq 0 ]; then
51 printc red "not found\n"
52 { if [ -x ~/.rbenv/bin/rbenv ]; then
53 echo "You seem to have rbenv installed in \`$HOME/.rbenv/bin', but that"
54 echo "directory is not present in PATH. Please add it to PATH by configuring
55 echo "your \`~/${bashrc}', \`~/.zshrc', or \`~/.config/fish/config.fish'."
56 else
57 echo "Please refer to https://github.com/rbenv/rbenv#installation"
58 fi
59 } | indent
60 exit 1
61 elif [ $num_locations -eq 1 ]; then
62 printc green "%s\n" "$(which rbenv)"
63 else
64 printc yellow "multiple\n"
65 { echo "You seem to have multiple rbenv installs in the following locations."
66 echo "Please pick just one installation and remove the others."
2 of 5 11/16/18, 9:59 AM
rbenv-installer/rbenv-doctor at master · rbenv/rbe... https://github.com/rbenv/rbenv-installer/blob/mas...
67 echo
68 which -a rbenv
69 } | indent
70 echo
71 : $((warnings++))
72 fi
73
74 RBENV_ROOT="${RBENV_ROOT:-$(rbenv root)}"
75
76 OLDIFS="$IFS"
77 IFS=:
78 path=($PATH)
79 IFS="$OLDIFS"
80
81 echo -n "Checking for rbenv shims in PATH: "
82 shims_dir="${RBENV_ROOT}/shims"
83 found=""
84 for dir in "${path[@]}"; do [ "$dir" != "$shims_dir" ] || found=true; done
85 if [ -n "$found" ]; then
86 printc green "OK\n"
87 else
88 printc red "not found\n"
89 { echo "The directory \`$shims_dir' must be present in PATH for rbenv to work."
90 echo "Please run \`rbenv init' and follow the instructions."
91 } | indent
92 echo
93 : $((warnings++))
94 fi
95
96 echo -n "Checking \`rbenv install' support: "
97 rbenv_installs="$({ ls "$RBENV_ROOT"/plugins/*/bin/rbenv-install 2>/dev/null || true
98 which -a rbenv-install 2>/dev/null || true
99 } | uniq)"
100 num_installs="$(wc -l <<<"$rbenv_installs")"
101 if [ -z "$rbenv_installs" ]; then
102 printc red "not found\n"
103 { echo "Unless you plan to add Ruby versions manually, you should install ruby-build.
104 echo "Please refer to https://github.com/rbenv/ruby-build#installation"
105 }
106 echo
107 : $((warnings++))
108 elif [ $num_installs -eq 1 ]; then
109 printc green "$rbenv_installs"
110 if [[ $rbenv_installs == "$RBENV_ROOT"/plugins/* ]]; then
3 of 5 11/16/18, 9:59 AM
rbenv-installer/rbenv-doctor at master · rbenv/rbe... https://github.com/rbenv/rbenv-installer/blob/mas...
111 rbenv_install_cmd="${rbenv_installs##*/}"
112 rbenv_install_version="$(rbenv "${rbenv_install_cmd#rbenv-}" --version || true
113 else
114 rbenv_install_version="$("$rbenv_installs" --version || true)"
115 fi
116 printf " (%s)\n" "$rbenv_install_version"
117 else
118 printc yellow "multiple\n"
119 { echo "You seem to have multiple \`rbenv-install' in the following locations."
120 echo "Please pick just one installation and remove the others."
121 echo
122 echo "$rbenv_installs"
123 } | indent
124 echo
125 : $((warnings++))
126 fi
127
128 echo -n "Counting installed Ruby versions: "
129 num_rubies="$(rbenv versions --bare | wc -l)"
130 if [ $num_rubies -eq 0 ]; then
131 printc yellow "none\n"
132 echo "There aren't any Ruby versions installed under \`$RBENV_ROOT/versions'." |
133 [ $num_installs -eq 0 ] || {
134 echo -n "You can install Ruby versions like so: "
135 printc bright "rbenv install 2.2.4\n"
136 } | indent
137 else
138 printc green "%d versions\n" $num_rubies
139 fi
140
141 echo -n "Checking RubyGems settings: "
142 gem_broken=0
143 for gemrc in ~/.gemrc /etc/gemrc; do
144 if grep -v '^#' "$gemrc" 2>/dev/null | grep -q -e --user-install; then
145 [ "$((gem_broken++))" -gt 0 ] || printc yellow "warning\n"
146 echo "Please remove \`--user-install' flag from \`$gemrc'." | indent
147 : $((warnings++))
148 fi
149 done
150 [ "$gem_broken" -gt 0 ] || printc green "OK\n"
151
152 echo -n "Auditing installed plugins: "
153 OLDIFS="$IFS"
154 IFS=$'\n'
4 of 5 11/16/18, 9:59 AM
rbenv-installer/rbenv-doctor at master · rbenv/rbe... https://github.com/rbenv/rbenv-installer/blob/mas...
155 hooks=(`rbenv hooks exec`)
156 IFS="$OLDIFS"
157 plugin_broken=0
158 for hook in "${hooks[@]}"; do
159 plugin_name=
160 message=
161 case "$hook" in
162 */"~gem-rehash.bash" )
163 plugin_name=rbenv-gem-rehash
164 message="functionality is now included in rbenv core. Please remove the plugin.
165 ;;
166 */"bundler.bash" )
167 plugin_name=rbenv-bundler
168 message="is considered harmful. Please remove the plugin and \`rm -rf \$(rbenv root)/shi
169 ;;
170 esac
171
172 if [ -n "$plugin_name" ]; then
173 [ "$((plugin_broken++))" -gt 0 ] || printc yellow "warning\n"
174 { printc bright "$plugin_name"
175 echo " $message"
176 echo " (found in \`${hook}')"
177 } | indent
178 : $((warnings++))
179 fi
180 done
181 [ "$plugin_broken" -gt 0 ] || printc green "OK\n"
182
183 [ $warnings -eq 0 ]
5 of 5 11/16/18, 9:59 AM