-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
cli
406 lines (367 loc) · 9.98 KB
/
cli
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
#!/usr/bin/env bash
__rvm_fix_selected_ruby()
{
typeset __ret=0
if (( $# ))
then "$@" || __ret=$?
fi
[[ -d "$GEM_HOME" && -d "$MY_RUBY_HOME" ]] ||
{
if [[ -d ${MY_RUBY_HOME%/*}/defaul ]]
then __rvm_use default
else __rvm_use system
fi
}
}
__rvm_path_match_gem_home_check_warning()
{
rvm_warn "\
Warning! PATH is not properly set up, '$GEM_HOME/bin' $1,
usually this is caused by shell initialization files - check them for 'PATH=...' entries,
it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
to fix temporarily in this shell session run: 'rvm use ${GEM_HOME##*/}'."
}
__rvm_path_match_gem_home_check()
{
(( ${rvm_silence_path_mismatch_check_flag:-0} == 0 )) || return 0
[[ -n "${GEM_HOME:-}" ]] || return 0
case "$PATH:" in
($GEM_HOME/bin:*) true ;; # all fine here
(*:$GEM_HOME/bin:*)
__rvm_path_match_gem_home_check_warning "is not at first place"
;;
(*)
__rvm_path_match_gem_home_check_warning "is not available"
;;
esac
}
__rvm_use_ruby_warnings()
{
if [[ "${rvm_ruby_string}" == "system" || "${rvm_ruby_string}" == "" ]]
then return 0
fi
typeset __executable __gem_version
for __executable in ruby gem irb
do
[[ -x "$MY_RUBY_HOME/bin/${__executable}" ]] ||
rvm_warn "Warning! Executable '${__executable}' missing, \
something went wrong with this ruby installation!"
done
if
[[ "${rvm_ruby_interpreter}" == "ruby" ]] &&
{
__rvm_version_compare "${rvm_ruby_version}" -ge 2.0.0 ||
[[ "${rvm_ruby_version}" == "head" ]]
} &&
__rvm_which gem >/dev/null &&
__gem_version="$(gem --version)" &&
[[ -n "${__gem_version}" ]] &&
__rvm_version_compare "${__gem_version}" -lt "2.0.0"
then
rvm_warn "Warning! You have just used ruby 2.0.0 or newer, \
which is not fully compatible with rubygems 1.8.x or older,
consider upgrading rubygems with: 'rvm rubygems latest'."
fi
}
__rvm_cli_posix_check()
{
if
__rvm_has_opt "posix"
then
echo "RVM can not be run with \`set -o posix\`, please turn it off and try again."
return 100
fi
}
__rvm_cli_load_rvmrc()
{
if
(( ${rvm_ignore_rvmrc:=0} == 0 ))
then
[[ -n "${rvm_stored_umask:-}" ]] || export rvm_stored_umask=$(umask)
rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
if
[[ -n "${rvm_prefix:-}" ]] &&
[[ ! "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
then
rvm_rvmrc_files+=( "${rvm_prefix}/.rvmrc" )
fi
for rvmrc in "${rvm_rvmrc_files[@]}"
do
if
[[ -f "$rvmrc" ]]
then
if
__rvm_grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1
then
printf "%b" "
Error:
$rvmrc is for rvm settings only.
rvm CLI may NOT be called from within $rvmrc.
Skipping the loading of $rvmrc"
return 1
else
source "$rvmrc"
fi
fi
done
unset rvm_rvmrc_files
fi
}
__rvm_cli_rvm_reload()
{
__rvm_project_rvmrc_lock=0
rvm_reload_flag=1
source "${rvm_scripts_path:-${rvm_path}/scripts}/rvm"
}
__rvm_cli_version_check()
{
typeset disk_version
disk_version="$(\command \cat "$rvm_path/VERSION") ($(\command \cat "$rvm_path/RELEASE" 2>/dev/null))"
if
[[ -s "$rvm_path/VERSION" &&
"${rvm_version:-}" != "${disk_version:-}" &&
" $* " != *" reload "*
]]
then
if
(( ${rvm_auto_reload_flag:-0} ))
then
__rvm_cli_rvm_reload
else
printf "%b" "
RVM version ${disk_version} is installed yet ${rvm_version} is loaded.
Please do one of the following:
* 'rvm reload'
* open a new shell
* 'echo rvm_auto_reload_flag=1 >> ~/.rvmrc' # for auto reload with msg.
* 'echo rvm_auto_reload_flag=2 >> ~/.rvmrc' # for silent auto reload.
"
return 1
fi
fi
}
__rvm_remote_version()
{
__rvm_curl -s --max-time 10 https://github.com/wayneeseguin/rvm/raw/master/VERSION || true
}
__rvm_cli_autoupdate_version_old()
{
online_version="$( __rvm_remote_version )"
version_release="$(\command \cat "$rvm_path/RELEASE" 2>/dev/null)"
: version_release:"${version_release:=master}"
[[ -s "$rvm_path/VERSION" && -n "${online_version:-}" && "${rvm_version%% *}" != "${online_version:-}" ]] || return $?
}
__rvm_cli_autoupdate_warning()
{
printf "%b" "Warning, new version of rvm available '${online_version}', \
you are using older version '${rvm_version%% *}'.
You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
"
}
# duplication marker flnglfdjkngjndkfjhsbdjgfghdsgfklgg
rvm_install_gpg_setup()
{
rvm_gpg_command="$( \which gpg2 )" ||
rvm_gpg_command="$( \which gpg )" ||
rvm_gpg_command=""
rvm_debug "Detected GPG program: '$rvm_gpg_command'"
[[ -n "$rvm_gpg_command" ]] || return $?
}
# duplication marker rdjgndfnghdfnhgfdhbghdbfhgbfdhbn
verify_package_pgp()
{
if
${rvm_gpg_command} --verify "$2" "$1"
then
rvm_log "GPG verified '$1'"
else
typeset _ret=$?
rvm_error "\
Warning, RVM 1.26.0 introduces signed releases and \
automated check of signatures when GPG software found.
Assuming you trust Michal Papis import the mpapis public \
key (downloading the signatures).
GPG signature verification failed for '$1' - '$3'!
try downloading the signatures:
${SUDO_USER:+sudo }${rvm_gpg_command##*/} --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
or if it fails:
command curl -sSL https://rvm.io/mpapis.asc | ${SUDO_USER:+sudo }${rvm_gpg_command##*/} --import -
the key can be compared with:
https://rvm.io/mpapis.asc
https://keybase.io/mpapis
"
return _ret
fi
}
__rvm_cli_get_and_verify_pgp()
{
typeset rvm_gpg_command
if
rvm_install_gpg_setup
then
pgp_signature_url="$( __rvm_curl -sSI https://get.rvm.io | \tr "\r" " " | __rvm_awk '/Location:/{print $2".asc"}' )"
rvm_log "Downloading $pgp_signature_url"
__rvm_curl -s "${pgp_signature_url}" -o "${rvm_archives_path}/rvm-installer.asc" ||
return $?
rvm_log "Verifying ${rvm_archives_path}/rvm-installer.asc"
verify_package_pgp "${rvm_archives_path}/rvm-installer" "${rvm_archives_path}/rvm-installer.asc" "$pgp_signature_url" ||
return $?
else
rvm_warn "No GPG software exists to validate rvm-installer, skipping."
fi
}
__rvm_cli_get_installer_cleanup()
{
[[ -w "${rvm_archives_path}" ]] ||
{
rvm_error "Archives path '${rvm_archives_path}' not writable, aborting."
return 1
}
[[ ! -e "${rvm_archives_path}/rvm-installer" ]] ||
rm -f "${rvm_archives_path}/rvm-installer" ||
{
rvm_error "Previous installer '${rvm_archives_path}/rvm-installer' exists and can not be removed, aborting."
return 2
}
}
__rvm_cli_get_and_execute_installer()
{
__rvm_cli_get_installer_cleanup || return $?
rvm_log "Downloading https://get.rvm.io"
__rvm_curl -s https://get.rvm.io -o "${rvm_archives_path}/rvm-installer" ||
{
typeset _ret=$?
rvm_error "Could not download rvm-installer, get some help at #rvm IRC channel at freenode servers."
return ${_ret}
}
__rvm_cli_get_and_verify_pgp || return $?
bash "${rvm_archives_path}/rvm-installer" "$@" ||
{
typeset _ret=$?
rvm_error "Could not update RVM, get some help at #rvm IRC channel at freenode servers."
return ${_ret}
}
}
__rvm_cli_rvm_get()
{
case "$1" in
([0-9]*.[0-9]*.[0-9]*)
rvm_warn "
Hi there, it looks like you have requested updating rvm to version $1,
if your intention was ruby installation use instead: rvm install $1
"
;;
esac
case "$1" in
(stable|master|head|branch|latest|latest-*|[0-9]*.[0-9]*.[0-9]*)
__rvm_cli_get_and_execute_installer "$@" || return $?
typeset -x rvm_hook
rvm_hook="after_update"
source "${rvm_scripts_path:-"$rvm_path/scripts"}/hook"
rvm_reload_flag=1
;;
(*)
rvm_help get
;;
esac
}
__rvm_cli_autoupdate_execute()
{
printf "%b" "Found old RVM ${rvm_version%% *} - updating.\n"
__rvm_cli_rvm_get "${version_release}"
__rvm_cli_rvm_reload
}
__rvm_cli_autoupdate()
{
[[ " $* " == *" install "* && " $* " != *" help install "* ]] ||
[[ " $* " == *" list known "* ]] ||
return 0
typeset online_version version_release
case "${rvm_autoupdate_flag:-1}" in
(0|disabled)
true
;;
(1|warn)
if __rvm_cli_autoupdate_version_old
then __rvm_cli_autoupdate_warning
fi
;;
(2|enabled)
if __rvm_cli_autoupdate_version_old
then __rvm_cli_autoupdate_execute
fi
;;
esac
true
}
__rvm_cli_autoreload()
{
if
[[ ${rvm_reload_flag:-0} -eq 1 ]]
then
if
[[ -s "$rvm_scripts_path/rvm" ]]
then
__rvm_project_rvmrc_lock=0
source "$rvm_scripts_path/rvm"
else
echo "rvm not found in $rvm_path, please install and run 'rvm reload'"
__rvm_teardown
fi
else
__rvm_teardown
fi
}
__rvm_cli_install_ruby()
(
if
[[ -n "$1" ]]
then
typeset __rubies __installed __missing __search_list
typeset -a __search
__rvm_custom_separated_array __search , "$1"
__rubies="$1"
__search_list=""
__rvm_cli_rubies_select || return $?
if __rvm_cli_rubies_not_installed
then __rvm_run_wrapper manage install "${__rubies}" || return $?
fi
else
rvm_error "Can not use or install 'all' rubies."
false #report error
fi
)
__rvm_cli_rubies_select()
{
typeset __ruby
for __ruby in "${__search[@]}"
do
rvm_ruby_string="${__ruby}"
__rvm_select &&
if [[ -n "$rvm_ruby_string" ]]
then __search_list+="^$rvm_ruby_string\$|"
else
rvm_error "Could not detect ruby version/name for installation '${__ruby}', please be more specific."
return 1
fi
done
__search_list="${__search_list%|}"
}
__rvm_cli_rubies_not_installed()
{
if
(( ${rvm_force_flag:-0} == 0 )) &&
__installed="$(
__rvm_list_strings | __rvm_grep -E "${__search_list}"
)" &&
[[ -n "${__installed}" ]]
then
rvm_warn "Already installed ${__installed//|/,}.
To reinstall use:
rvm reinstall ${__installed//|/,}
"
return 2
fi
true
}