-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
rvm-installer
executable file
·512 lines (430 loc) · 10.7 KB
/
rvm-installer
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
#!/usr/bin/env bash
BASH_MIN_VERSION="3.2.25"
if
[[ -n "${BASH_VERSION:-}" &&
"$(printf "%b" "${BASH_VERSION:-}\n${BASH_MIN_VERSION}\n" | LC_ALL=C sort -n -t"." | head -n1)" != "${BASH_MIN_VERSION}"
]]
then
echo "BASH ${BASH_MIN_VERSION} required (you have $BASH_VERSION)"
exit 1
fi
export HOME PS4
export rvm_trace_flag rvm_debug_flag rvm_user_install_flag rvm_ignore_rvmrc rvm_prefix rvm_path
shopt -s extglob
PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()} \${LINENO} > "
set -o errtrace
set -o errexit
log() { printf "%b\n" "$*" ; return $? ; }
fail() { log "\nERROR: $*\n" ; exit 1 ; }
if [[ -z "${rvm_tar_command:-}" ]] && builtin command -v gtar >/dev/null
then
rvm_tar_command=gtar
else
rvm_tar_command=tar
fi
if [[ ! " ${rvm_tar_options:-} " =~ " --no-same-owner " ]] && \
$rvm_tar_command --help 2>&1 | GREP_OPTIONS="" \grep -- --no-same-owner >/dev/null
then
rvm_tar_options="${rvm_tar_options:-} --no-same-owner"
rvm_tar_options="${rvm_tar_options## }"
fi
usage()
{
printf "%b" "
Usage
rvm-installer [options] [action]
Options
[[--]version] <latest|latest-x|latest-x.y|x.y.z> - Install RVM version
[--]branch <name> - Install RVM head, from named branch
--trace - used to debug the installer script
Actions
master - Install RVM master branch from wayneeseguin rvm repo (Default).
stable - Install RVM stable branch from wayneeseguin rvm repo.
help - Display CLI help (this output)
Branches:
branch <branch>
branch /<branch>
branch <repo>/
branch <repo>/<branch>
Defaults:
branch: master
repo: wayneeseguin
"
}
#Searches for highest available version for the given pattern
# fetch_version 1.10. -> 1.10.3
# fetch_version 1. -> 1.11.0
# fetch_version "" -> 2.0.1
fetch_version()
{
curl -s https://api.github.com/repos/wayneeseguin/rvm/tags |
sed -n '/"name": / {s/^.*".*": "\(.*\)".*$/\1/; p;}' |
sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n |
GREP_OPTIONS="" \grep "^${1:-}" | tail -n 1
}
install_release()
{
typeset _version
_version=$1
log "Downloading RVM version ${_version}"
get_and_unpack \
https://github.com/wayneeseguin/rvm/tarball/${_version} \
rvm-${_version}.tar.gz \
wayneeseguin-rvm-
}
install_head()
{
typeset _repo _branch
case "$1" in
(/*)
_repo=wayneeseguin
_branch=${1#/}
;;
(*/)
_repo=${1%/}
_branch=master
;;
(*/*)
_repo=${1%%/*}
_branch=${1#*/}
;;
(*)
_repo=wayneeseguin
_branch=$1
;;
esac
log "Downloading RVM from ${_repo} branch ${_branch}"
get_and_unpack \
https://github.com/${_repo}/rvm/tarball/${_branch} \
${_repo}-rvm-${_branch//\//_}.tgz \
${_repo}-rvm-
}
# duplication marker dfkjdjngdfjngjcszncv
# Drop in cd which _desotn't_ respect cdpath
__rvm_cd()
{
typeset old_cdpath ret
ret=0
old_cdpath="${CDPATH}"
CDPATH="."
chpwd_functions="" builtin cd "$@" || ret=$?
CDPATH="${old_cdpath}"
return $ret
}
get_and_unpack()
{
typeset _url _file _patern
_url=$1
_file=$2
_patern=$3
if curl -L ${_url} -o ${rvm_archives_path}/${_file}
then
true
else
typeset ret=$?
case $ret in
(60)
log "
Could not download '${_url}'.
Make sure your certificates are up to date as described above.
To continue in insecure mode run 'echo insecure >> ~/.curlrc'.
"
return 60
;;
(*)
log "
Could not download '${_url}'.
curl returned status '$ret'.
"
return 1
;;
esac
fi
[[ -d "${rvm_src_path}/rvm" ]] || \mkdir -p "${rvm_src_path}/rvm"
if ! __rvm_cd "${rvm_src_path}/rvm"
then
log "Could not change directory '${rvm_src_path}/rvm'."
return 2
fi
rm -rf ${rvm_src_path}/rvm/*
if ! $rvm_tar_command xzf ${rvm_archives_path}/${_file} ${rvm_tar_options:-}
then
log "Could not extract RVM sources."
return 3
fi
if ! mv ${_patern}*/* .
then
log "Could not move RVM sources path."
return 4
fi
rm -rf ${_patern}*
}
# Tracing, if asked for.
if [[ "$*" =~ --trace ]] || (( ${rvm_trace_flag:-0} > 0 ))
then
set -o xtrace
rvm_trace_flag=1
fi
# Variable initialization, remove trailing slashes if they exist on HOME
true \
${rvm_trace_flag:=0} ${rvm_debug_flag:=0} ${rvm_user_install_flag:=0}\
${rvm_ignore_rvmrc:=0} HOME="${HOME%%+(\/)}"
if (( rvm_ignore_rvmrc == 0 ))
then
for rvmrc in /etc/rvmrc "$HOME/.rvmrc"
do
if [[ -s "$rvmrc" ]]
then
if GREP_OPTIONS="" \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
"
exit 1
else
source "$rvmrc"
fi
fi
done
fi
if [[ -z "${rvm_path:-}" ]]
then
if (( UID == 0 ))
then
rvm_user_install_flag=0
rvm_prefix="/usr/local"
rvm_path="${rvm_prefix}/rvm"
else
rvm_user_install_flag=1
rvm_prefix="$HOME"
rvm_path="${rvm_prefix}/.rvm"
fi
fi
if [[ -z "${rvm_prefix}" ]]
then
rvm_prefix=$( dirname $rvm_path )
fi
install_rubies=()
install_gems=()
# Parse CLI arguments.
while (( $# > 0 ))
do
token="$1"
shift
case "$token" in
--trace)
set -o xtrace
rvm_trace_flag=1
;;
--path)
if [[ -n "${1:-}" ]]
then
rvm_path="$1"
shift
else
fail "--path must be followed by a path."
fi
;;
--branch|branch) # Install RVM from a given branch
if [[ -n "${1:-}" ]]
then
version="head"
branch="$1"
shift
else
fail "--branch must be followed by a branchname."
fi
;;
--user-install|--auto-dotfiles|--ignore-dotfiles)
token=${token#--}
token=${token//-/_}
export "rvm_${token}_flag"=1
printf "%b" "Turning on ${token/_/ } mode.\n"
;;
--auto)
export "rvm_auto_dotfiles_flag"=1
printf "%b" "Warning, --auto is deprecated in favor of --auto-dotfiles.\n"
;;
--with-gems=*)
export rvm_with_gems="${token#--with-gems=}"
printf "%b" "Installing RVM with gems: ${rvm_with_gems}.\n"
;;
--without-gems=*)
export rvm_without_gems="${token#--without-gems=}"
printf "%b" "Installing RVM without gems: ${rvm_without_gems}.\n"
;;
--version|version)
version="$1"
shift
;;
head)
version="head"
branch="master"
;;
stable|master)
version="head"
branch="$token"
;;
latest|latest-*|+([[:digit:]]).+([[:digit:]]).+([[:digit:]]))
version="$token"
;;
--ruby)
install_rubies+=( ruby )
;;
--ruby=*)
token=${token#--ruby=}
install_rubies+=( ${token//,/ } )
;;
--rails)
install_gems+=( rails )
;;
--gems=*)
token=${token#--gems=}
install_gems+=( ${token//,/ } )
;;
(--add-to-rvm-group)
export rvm_add_users_to_rvm_group="$1"
shift
;;
help|usage)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
case "$rvm_path" in
*[[:space:]]*)
printf "%b" "
It looks you are one of the happy *space* users(in home dir name),
RVM is not yet fully ready for it, use this trick to fix it:
sudo ln -s \"$HOME/.rvm/\" /$USER.rvm
echo \"export rvm_path=/$USER.rvm\" >> \"$HOME/.rvmrc\"
and start installing again.
"
exit 2
;;
/usr/share/ruby-rvm)
printf "%b" "
It looks you are one of the happy Ubuntu users,
RVM packaged by Ubuntu is old and broken,
follow this link for details how to fix:
http://stackoverflow.com/a/9056395/497756
"
[[ "${rvm_uses_broken_ubuntu_path:-no}" == "yes" ]] || exit 3
;;
esac
if (( ${#install_gems[@]} > 0 && ${#install_rubies[@]} == 0 ))
then
install_rubies=( ruby )
fi
if (( ${#install_rubies[@]} > 0 ))
then
echo "Please read and follow further instructions."
echo "Press ENTER to continue."
builtin read -n 1 -s -r anykey
fi
true "${version:=head}"
if [[ "$rvm_path" != /* ]]
then
fail "The rvm install path must be fully qualified. Tried $rvm_path"
fi
rvm_src_path="$rvm_path/src"
rvm_archives_path="$rvm_path/archives"
rvm_releases_url="https://rvm.io/releases"
for dir in "$rvm_src_path" "$rvm_archives_path"
do
if [[ ! -d "$dir" ]]
then
mkdir -p "$dir"
fi
done
# Perform the actual installation, first we obtain the source using whichever
# means was specified, if any. Defaults to head.
case "${version}" in
(head)
echo "${branch}" > "$rvm_path/RELEASE"
install_head ${branch:-master} || exit $?
;;
(latest)
echo "${version}" > "$rvm_path/RELEASE"
install_release $(fetch_version "") || exit $?
;;
(latest-*)
echo "${version}" > "$rvm_path/RELEASE"
install_release $(fetch_version "${version#latest-}") || exit $?
;;
(+([[:digit:]]).+([[:digit:]]).+([[:digit:]])) # x.y.z
echo "version" > "$rvm_path/RELEASE"
install_release ${version} || exit $?
;;
(*)
fail "Something went wrong, unrecognized version '$version'"
;;
esac
# required flag - path to install
flags=( --path "$rvm_path" )
if (( rvm_trace_flag == 1 ))
then flags+=("--trace")
fi
if (( rvm_debug_flag == 1 ))
then flags+=("--debug")
fi
if (( rvm_auto_dotfiles_flag == 1 ))
then flags+=("--auto-dotfiles")
fi
if [[ -n "${rvm_with_gems:-}" ]]
then flags+=("--with-gems=${rvm_with_gems}")
fi
if [[ -n "${rvm_without_gems:-}" ]]
then flags+=("--without-gems=${rvm_without_gems}")
fi
if [[ -n "${rvm_add_users_to_rvm_group:-}" ]]
then flags+=(--add-to-rvm-group "${rvm_add_users_to_rvm_group}")
fi
chmod +x ./scripts/install
./scripts/install "${flags[@]}"
if (( ${#install_rubies[@]} > 0 ))
then
(
source ${rvm_scripts_path:-${rvm_path}/scripts}/rvm
source ${rvm_scripts_path:-${rvm_path}/scripts}/version
__rvm_version
{
echo "Ruby (and needed base gems) for your selection will be installed shortly."
echo "Before it happens, please read and execute the instructions below."
echo "Please use a separate terminal to execute any additional commands."
echo "(use keyboard arrows to navigate)"
echo "Press 'q' to continue."
} | less
for _ruby in ${install_rubies[@]}
do
command rvm install ${_ruby} -j 2
done
for _ruby in ${install_rubies[@]}
do
# set the first one as default, skip rest
rvm alias create default ${_ruby}
break
done
for _gem in ${install_gems[@]}
do
rvm all do gem install ${_gem}
done
printf "%b" "
* To start using RVM you need to run \`source $rvm_path/scripts/rvm\`
in all your open shell windows, in rare cases you need to reopen all shell windows.
"
if [[ "${install_gems[*]}" =~ "rails" ]]
then
printf "%b" "
* To start using rails you need to run \`rails new <project_dir>\`.
"
fi
)
fi