-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
install
executable file
·700 lines (451 loc) · 14.3 KB
/
install
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
#!/usr/bin/env bash
set -o errtrace
export PS4='+[${BASH_SOURCE}] : ${LINENO} : ${FUNCNAME[0]:+${FUNCNAME[0]}() $ }'
if [[ -z "$rvm_selfcontained" ]]; then
if [[ $(id | sed -e 's/(.*//' | awk -F= '{print $2}') -eq 0 || \
-n "$rvm_prefix" && "$rvm_prefix" != "$HOME"/* ]]; then
export rvm_selfcontained=0
else
export rvm_selfcontained=1
fi
fi
unset rvm_auto_flag
install_source_path="$(dirname "$0" | sed 's#\/scripts$##')"
if [[ -d "$install_source_path/scripts" \
&& -s "$install_source_path/scripts/utility" ]] ; then
builtin cd "$install_source_path"
fi
source scripts/version
source scripts/utility
usage()
{
printf "
Usage:
${0} [options]
options:
--auto : Automatically update shell profile files.
--prefix : Installation prefix directory.
--help : Display help/usage (this) message
--version : display rvm package version
\n"
}
check_rubyopt_conditions()
{
if [[ -n "${RUBYOPT:-""}" ]]; then
printf "
WARNING: You have RUBYOPT set in your current environment.
This may cause rubies to not work as you expect them to as it is not supported
by all of them If errors show up, please try unsetting RUBYOPT first.
"
fi
}
andand_return_instructions()
{
printf "
This means that if you see something like:
'[ -z \"\$PS1\" ] && return'
then you change this line to:
if [[ -n \"\$PS1\" ]] ; then
# ... original content that was below the '&& return' line ...
fi # <= be sure to close the if at the end of the .bashrc.
# This is a good place to source rvm v v v
[[ -s \"\$HOME/.rvm/scripts/rvm\" ]] && source \"\$HOME/.rvm/scripts/rvm\" # This loads RVM into a shell session.
EOF - This marks the end of the .bashrc file
"
}
installation_complete()
{
printf "
You must now complete the install by loading RVM in new shells.
1) Place the folowing line at the end of your shell's loading files
(.bashrc or .bash_profile for bash and .zshrc for zsh),
after all PATH/variable settings:
[[ -s \"\$HOME/.rvm/scripts/rvm\" ]] && source \"\$HOME/.rvm/scripts/rvm\" # This loads RVM into a shell session.
You only need to add this line the first time you install rvm.
2) Ensure that there is no 'return' from inside the ~/.bashrc file,
otherwise rvm may be prevented from working properly.
$(andand_return_instructions)
Be absolutely *sure* to REMOVE the '&& return'.
If you wish to DRY up your config you can 'source ~/.bashrc' at the bottom of your .bash_profile.
Placing all non-interactive (non login) items in the .bashrc,
including the 'source' line above and any environment settings.
3) CLOSE THIS SHELL and open a new one in order to use rvm.
\n"
}
andand_return_warning()
{
printf "
WARNING: you have a 'return' statement in your ~/.bashrc
This could cause some features of RVM to not work.
$(andand_return_instructions)
Even if you are using zsh you should still adjust the ~/.bashrc
If you have any questions about this please visit
#rvm on irc.freenode.net.
\n"
}
thank_you()
{
printf "
${name:-"${USER:-$(id | sed -e 's/^[^(]*(//' -e 's/).*$//')}"},
Thank you very much for using RVM! I sincerely hope that RVM helps to
make your work both easier and more enjoyable.
If you have any questions, issues and/or ideas for improvement please
join#rvm on irc.freenode.net and let me know, note you must register
(http://bit.ly/5mGjlm) and identify (/msg nickserv <nick> <pass>) to
talk, this prevents spambots from ruining our day.
My irc nickname is 'wayneeseguin' and I hang out in #rvm typically
~09:00-17:00EDT and again from ~21:00EDT-~23:00EDT
If I do not respond right away, please hang around after asking your
question, I will respond as soon as I am back. It is best to talk in
#rvm itself as then other users can help out should I be offline.
Be sure to get head often as rvm development happens fast,
you can do this by running 'rvm get head' followed by 'rvm reload'
or opening a new shell
w⦿‿⦿t
~ Wayne
"
}
upgrade_notes()
{
printf "
Upgrade Notes
* rvm_trust_rvmrcs has been changed to rvm_trust_rvmrcs_flag for consistency
* Ruby package dependency list for your OS is given by:
rvm notes
* If you encounter any issues with a ruby 'X' your best bet is to:
rvm remove X ; rvm install X
* If you wish to have the 'pretty colors' again, set in ~/.rvmrc:
export rvm_pretty_print_flag=1
* If you see the following error message: Unknown alias name: 'default'
re-set your default ruby, this is due to a change in how default works.
"
}
set -o noclobber
set -o nounset
while [[ $# -gt 0 ]] ; do
token="$1" ; shift
case "$token" in
--auto) rvm_auto_flag=1 ;;
--prefix) rvm_prefix="$1" ; shift ;;
--version) rvm_path="$PWD" ; __rvm_version ; unset rvm_path ; exit ;;
--debug)
set -o verbose
;;
--trace)
echo "$*"
env | grep '^rvm_'
set -o xtrace
;;
--help)
usage
exit 0
;;
*)
echo "Unrecognized option: $token"
usage
exit 1
;;
esac
done
if [[ -z "${rvm_prefix:-""}" ]] ; then
if [[ $(id | sed -e 's/(.*//' | awk -F= '{print $2}') -eq 0 ]] ; then
if [[ -s /etc/rvmrc ]] ; then
source /etc/rvmrc
fi
if [[ ${rvm_selfcontained:-0} -eq 0 ]] ; then
rvm_prefix="${rvm_prefix:-"/usr/local/"}"
else
rvm_prefix="${rvm_prefix:-"$HOME/."}"
fi
else
rvm_prefix="${rvm_prefix:-"$HOME/."}"
fi
fi
if [[ -z "${rvm_path:-""}" ]] ; then
rvm_path="${rvm_prefix}rvm"
fi
source scripts/initialize
if grep -q 'scripts/rvm' "$HOME"/.bash* 2>/dev/null \
|| grep -q 'scripts/rvm' "$HOME"/.zsh* 2>/dev/null ; then
if [[ -d "$rvm_path" ]] && [[ -s "${rvm_path}/scripts/rvm" ]] ; then
export upgrade_flag=1
else
export upgrade_flag=0
fi
else
export upgrade_flag=0
fi
__rvm_initialize
#
# Setup & Configuration
#
item="* "
question="\n<?>"
cwd="$PWD"
source_path="${source_path:-$cwd}"
if [[ "$rvm_selfcontained" = "0" ]] ; then
rvm_bin_path="${rvm_bin_path:-"${rvm_prefix}bin"}"
rvm_man_path="${rvm_man_path:-"${rvm_prefix}share/man"}"
rvm_rc_files="${rvm_rc_files:-"/etc/profile /etc/zshenv"}"
else
rvm_man_path="${rvm_man_path:-"$rvm_path/man"}"
rvm_bin_path="${rvm_bin_path:-"$rvm_path/bin"}"
rvm_rc_files="${rvm_rc_files:-"$HOME/.bash_profile $HOME/.bashrc $HOME/.zshenv"}"
fi
rvm_gems_path="${rvm_gems_path:-"$rvm_path/gems"}"
rvm_tmp_path="${rvm_tmp_path:-"$rvm_path/tmp"}"
printf "
RVM: Shell scripts enabling management of multiple ruby environments.
RTFM: http://rvm.beginrescueend.com/
HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
"
if [[ ${upgrade_flag:-0} -eq 1 ]] ;then
printf "\nUpgrading the RVM installation in $rvm_path/"
else
printf "\nInstalling RVM to $rvm_path/"
fi
directories=(
"${rvm_archives_path:-"$rvm_path/archives"}"
"${rvm_src_path:-"$rvm_path/src"}"
"${rvm_log_path:-"$rvm_path/log"}"
"$rvm_bin_path"
"${rvm_gems_path:-"$rvm_path/gems"}"
"${rvm_rubies_path:-"$rvm_path/rubies"}"
"$rvm_path/config"
"$rvm_path/user"
"${rvm_tmp_path:-"$rvm_path/tmp"}"
"$rvm_path/bin"
)
for directory in "${directories[@]}" ; do
if [[ ! -d "$directory" ]] ; then
mkdir -p "$directory"
fi
done
files=(README LICENCE)
for file in "${files[@]}"; do
cp -f "$source_path/$file" "$rvm_path/"
done
#
# Scripts
#
for dir_name in config scripts examples lib hooks help patches; do
if [[ -d "$source_path/$dir_name" ]] ; then
if [[ ! -d "$rvm_path/$dir_name" ]] ; then
mkdir -p "$rvm_path/$dir_name"
fi
cp -Rf "$source_path/$dir_name" "$rvm_path"
fi
done
if [[ ! -s "$rvm_path/config/user" ]] ; then
echo '# User settings, overrides db settings and persists across installs.' \
>> "$rvm_path/config/user"
fi
scripts=(monitor match log install color db fetch log set package)
for script_name in "${scripts[@]}" ; do
chmod +x "$rvm_path/scripts/$script_name" 2>/dev/null # Hide errors.
done
#
# Config Scripts
#
(
cd "$rvm_path"
if [[ ! -f config/user ]]; then
mv config/user user/db
fi
if [[ ! -f user/db ]]; then
touch user/db
fi
if [[ -s config/rvmrcs ]] ; then
mv config/rvmrcs user/rvmrcs
else
if [[ ! -f user/rvmrcs ]] ; then
touch user/rvmrcs
fi
fi
)
#
# Bin Scripts
#
# Cleanse and purge...
files=(rvm-prompt rvm rvmsudo rvm-shell rvm-auto-ruby)
for file in "${files[@]}" ; do
rm -f "$rvm_bin_path/$file"
cp -f "$source_path/binscripts/$file" "${rvm_bin_path:-"$rvm_path/bin"}/"
chmod +x "${rvm_bin_path:-"$rvm_path/bin"}/$file"
done
#
# RC Files
#
if [[ ${rvm_auto_flag:-0} -eq 1 ]] ; then
printf "Checking rc files... ($rvm_rc_files)"
if [[ ${rvm_loaded_flag:-0} -ne 1 ]] ; then
for rcfile in $(printf $rvm_rc_files) ; do
if [[ ! -f $rcfile ]] ; then touch $rcfile ; fi
if [[ -s "$HOME/.profile" ]] ; then
if ! grep -q '.profile' "$rcfile" ; then
echo " Adding profile sourcing line to $rcfile."
printf "
# rvm install added line:
[[ -s \"$rvm_path/.profile\" ]] && source \"$rvm_path/.profile\"
" >> "$rcfile"
fi
fi
if ! grep -q "scripts\/rvm" "$rcfile" ; then
echo " Adding rvm loading line to $rcfile."
printf "
# rvm install added:
[[ -s \"$rvm_path/scripts/rvm\" ]] && . \"$rvm_path/scripts/rvm\"
" >> "$rcfile"
fi
done
fi
fi
#
# Initial Interpreter Gemsets.
#
if [[ -d gemsets/ ]] ; then
if [[ ! -d "$rvm_path/gemsets" ]] ; then
mkdir -p "$rvm_path/gemsets"
fi
for gemset_file in $(find "$PWD/gemsets" -iname '*.gems' | sed 's/^\.\///') ; do
cwd="${PWD//\//\\/}\/gemsets\/"
destination="$rvm_path/gemsets/${gemset_file/$cwd}"
destination_path="$(dirname "$destination")"
if [[ ! -s "$destination" ]] ; then
mkdir -p "$destination_path"
cp "$gemset_file" "$destination"
fi
done
fi
if [[ -d patchsets/ ]] ; then
if [[ ! -d "$rvm_path/patchsets" ]] ; then
mkdir -p "$rvm_path/patchsets"
fi
patchsets=($(builtin cd patchsets ; find \. -iname '*' | sed 's/^\.\///'))
for patchset_file in "${patchsets[@]}" ; do
destination="$rvm_path/patchsets/$patchset_file"
if [[ ! -s "$destination" ]] ; then
destination_path="$(dirname "$destination")"
mkdir -p "$destination_path"
cp "patchsets/$patchset_file" "$destination"
fi
done
fi
#
# Migrate ~/.rvm/ruby-X,jruby-X,... to ~/.rvm/rubies/ for 0.1.0.
#
mkdir -p "${rvm_rubies_path:-"$rvm_path/rubies"}/"
for ruby in $rvm_path/ruby-* $rvm_path/jruby-* $rvm_path/goruby\
$rvm_path/rbx-* $rvm_path/maglev-* $rvm_path/ree-* ; do
if [[ -d "$ruby" ]] ; then
mv "$ruby" "${rvm_rubies_path:-"$rvm_path/rubies"}/"
new_path="${rvm_rubies_path:-"$rvm_path/rubies"}/$(basename $ruby)"
for file in gem rake ; do
if [[ -s "$new_path/bin/$file" ]] ; then
sed -e '1,1s=.*=#!'"${new_path}/bin/ruby=" "${new_path}/bin/${file}" \
> "${new_path}/bin/${file}.new"
mv -f "$new_path/bin/$file.new" "$new_path/bin/$file"
chmod +x "$new_path/bin/$file"
fi
done
fi
done
#
# End of rubies migration.
#
if [[ -d "$rvm_path/environments" ]] ; then
#
# Remove BUNDLE_PATH from environment files
#
environments=($( find "$rvm_path/environments" -maxdepth 1 -mindepth 1 -type f ))
for file in "${environments[@]}" ; do
if grep 'BUNDLE_PATH' "$file" > /dev/null ; then
grep -v 'BUNDLE_PATH' "$file" > "$file.new"
mv "$file.new" "$file"
fi
done
fi
#
# Migrate old gemset directories to new gemset pattern.
#
for gemset in "$rvm_path"/gems/*\%* ; do
new_path=${gemset/\%/${rvm_gemset_separator:-"@"}}
if [[ -d "$gemset" ]] && [[ ! -d "$new_path" ]] ; then
printf "\n Renaming $(basename "$gemset") to $(basename "$new_path") for new gemset separator."
mv "$gemset" "$new_path"
fi
done
for gemset in "$rvm_path"/gems/*\+* ; do
new_path=${gemset/\+/${rvm_gemset_separator:-"@"}}
if [[ -d "$gemset" && ! -d "$new_path" ]] ; then
printf "\n Renaming $(basename "$gemset") to $(basename "$new_path") for new gemset separator."
mv $gemset $new_path
fi
done
for gemset in "$rvm_path"/gems/*\@ ; do
new_path=$(echo $gemset | sed -e 's#\@$##')
if [[ -d "$gemset" && ! -d "$new_path" ]] ; then
printf "\n Fixing: $(basename "$gemset") to $(basename "$new_path") for new gemset separator."
mv "$gemset" "$new_path"
fi
done
# Move from legacy defaults to the new, alias based system.
if [[ -s "$rvm_path/config/default" ]]; then
original_version="$(basename "$(grep GEM_HOME "$rvm_path/config/default" \
| awk -F"'" '{print $2}' | sed "s#\%#${rvm_gemset_separator:-"@"}#")")"
if [[ -n "$original_version" ]]; then
"$rvm_path/scripts/alias" create default "$original_version" &> /dev/null
fi ; unset original_version
rm -rf "$rvm_path/config/default"
fi
#
# End of gemset migration.
#
declare -a files
printf "\n Correct permissions for base binaries in $rvm_bin_path..."
mkdir -p "${rvm_bin_path:-"$rvm_path/bin"}"
files=(rvm rvmsudo rvm-shell rvm-auto-ruby)
for file in "${files[@]}" ; do
if [[ -s "${rvm_bin_path:-"$rvm_path/bin"}/$file" ]] ; then
chmod +x "${rvm_bin_path:-"$rvm_path/bin"}/$file"
fi
done
printf "\n Copying manpages into place.\n"
files=($(builtin cd "$install_source_path/man" ; \
find . -maxdepth 1 -mindepth 1 -type f -print))
for file in "${files[@]//.\/}" ; do
rm -rf "$rvm_man_path/$file"
cp -R "$install_source_path/man/$file" "$rvm_man_path/"
done
files=($( find "$rvm_path/" -mindepth 1 -maxdepth 2 -iname '*.swp' -type f ))
if [[ ${#files[@]} -gt 0 ]] ; then
printf "\n Cleanup any .swp files."
for file in "${files[@]}" ; do
if [[ -f "$file" ]] ; then
rm -f "$file"
fi
done
fi
if [[ $upgrade_flag -eq 0 ]] ; then
chmod +x ./scripts/notes # Sometimes things don't clone properly :/
./scripts/notes
fi
if command -v git > /dev/null 2>&1 ; then
name="$(git config user.name 2>/dev/null)"
fi
if [[ ${upgrade_flag:-0} -eq 1 ]] ; then
upgrade_notes
check_rubyopt_conditions
printf "\nUpgrade of RVM in $rvm_path/ is complete.\n\n"
else
if [[ ${rvm_selfcontained:-0} -eq 1 ]] ; then
installation_complete
fi
if [[ -s "$HOME/.bashrc" ]] && grep -q '&& return' "$HOME/.bashrc" ; then
andand_return_warning
fi
check_rubyopt_conditions
printf "\nInstallation of RVM to $rvm_path/ is complete.\n\n"
fi
thank_you
exit 0