/
installer
1024 lines (864 loc) · 23.3 KB
/
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
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
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
#Handle Solaris Hosts
if [[ "$(uname -sr)" == "SunOS 5.11" ]]
then
export PATH
PATH="/usr/gnu/bin:$PATH"
fi
if [[ -n "${rvm_user_path_prefix:-}" ]]
then
PATH="${rvm_user_path_prefix}:$PATH"
fi
install_setup()
{
set -o errtrace
export HOME="${HOME%%+(\/)}" # Remove trailing slashes if they exist on HOME
case "$MACHTYPE" in
*aix*) name_opt=-name ;;
*) name_opt=-iname ;;
esac
if (( ${rvm_ignore_rvmrc:=0} == 0 ))
then
for file in /etc/rvmrc "$HOME/.rvmrc"
do
if [[ -s "$file" ]]
then
. $file
fi
done
fi
export PS4 PATH
PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()} \${LINENO} > "
if [[ -n "${rvm_user_path_prefix:-}" ]]
then
PATH="${rvm_user_path_prefix}:$PATH"
fi
# TODO: Figure out a much better name for 'rvm_user_install_flag'
# mpapis: self contained was a quite good name
if (( UID == 0 )) ||
[[ -n "${rvm_prefix:-}" && "${rvm_prefix:-}" != "${HOME}" ]]
then
true "${rvm_user_install_flag:=0}"
else
true "${rvm_user_install_flag:=1}"
fi
export rvm_user_install_flag
unset rvm_auto_flag
}
install_usage()
{
printf "
Usage:
${0} [options]
options:
--auto : Automatically update shell profile files.
--prefix : Installation prefix directory (rvm_path).
--help : Display help/usage (this) message
--version : display rvm package version
\n"
}
check_rubyopt_conditions()
{
if [[ -n "${RUBYOPT:-""}" ]]
then
printf "\nWARNING: 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.\n"
fi
}
installation_complete()
{
printf "
You must now complete the install by loading RVM in new shells.
If you wish to use RVM in an interactive fashion in your shells then
Place the following 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 \"$rvm_path/scripts/rvm\" ]] && source \"$rvm_path/scripts/rvm\" # This loads RVM into a shell session.
You only need to add this line the first time you install RVM.
If you are choosing to source RVM into your environment to switch current
shell environments, be sure to close this shell and open a new one so that
the RVM functions load.
\n"
}
display_thank_you()
{
printf "
${name:-"${USER:-$(id | sed -e 's/^[^(]*(//' -e 's/).*$//')}"},
If you have any questions, issues and/or ideas for improvement please
fork the project and issue a pull request.
If you wish to disable the project .rvmrc file functionality, set
rvm_project_rvmrc=0 in either /etc/rvmrc or ~/.rvmrc.
NOTE: To Multi-User installers, please do NOT forget to add your users to the 'rvm' group.
The installer no longer auto-adds root or users to the rvm group. Admins must do this.
Also, please note that group memberships are ONLY evaluated at login time.
This means that users must log out then back in before group membership takes effect!
Thank you for using RVM!
I sincerely hope that RVM helps to make your life easier and more enjoyable!!!
~Wayne
"
}
upgrade_notes()
{
printf "
Upgrade Notes
* rvm_trust_rvmrcs has been changed to rvm_trust_rvmrcs_flag for consistency
* Project rvmrc files are now checked for trust whenever they change, as
promised by the note displayed during the review process
* Ruby package dependency list for your OS is given by:
rvm requirements
* If you encounter any issues with a ruby 'X' your best bet is to:
rvm get head && rvm reinstall X
* 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.
* after_use and after_cd hook now supports multiple files with after_*_*
the custom hooks can be easily turned on/off by:
chmod +x $rvm_path/hooks/after_cd_[hook_name]
chmod -x $rvm_path/hooks/after_use_[hook_name]
* If your shell exits on entering directory with freshly checked out sources
you should update .rvmrc file, and replace any \`exit \` with \`return \`.
"
}
determine_install_path()
{
export HOME="${HOME%%+(\/)}" # Remove trailing slashes if they exist on HOME
if (( ${rvm_ignore_rvmrc:=0} == 0 ))
then
for rvmrc in /etc/rvmrc "$HOME/.rvmrc"
do
if [[ -f "$rvmrc" ]]
then
if \grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1
then
printf "\nError: $rvmrc is for rvm settings only.\nrvm CLI may NOT be called from within $rvmrc. \nSkipping the loading of $rvmrc"
return 1
else
source "$rvmrc"
fi
fi
done
fi
if [[ -z "${rvm_path:-}" ]]
then
if (( UID == 0 ))
then
rvm_path="/usr/local/rvm"
else
rvm_path="${HOME}/.rvm"
fi
fi
export rvm_path
}
determine_install_or_upgrade()
{ # TODO: Improve this...
upgrade_flag=0
if grep 'scripts/rvm' "${HOME}"/.bash* "${HOME}"/.zsh* >/dev/null 2>&1
then
if [[ -d "$rvm_path" && -s "${rvm_path}/scripts/rvm" ]]
then
upgrade_flag=1
fi
fi
export upgrade_flag
}
print_install_header()
{
printf "
RVM: Shell scripts enabling management of multiple ruby environments.
RTFM: https://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
}
configure_installation()
{
install_source_path="$(dirname "$0" | sed 's#\/scripts$##')"
if [[ -d "$install_source_path/scripts" \
&& -s "$install_source_path/scripts/functions/utility" ]] ; then
builtin cd "$install_source_path"
fi
# Save scripts path
scripts_path=${rvm_scripts_path:-""}
rvm_scripts_path="${PWD%%+(\/)}/scripts"
# Load scripts.
source "$PWD/scripts/initialize"
source "$PWD/scripts/functions/init"
source "$PWD/scripts/version"
# What does this do that scripts/initialize not do?:
__rvm_initialize
# Restore Scripts Path
rvm_scripts_path=${scripts_path:-"$rvm_path/scripts"}
#
item="* "
question="\n<?>"
cwd="${PWD%%+(\/)}"
true "${source_path:=$cwd}"
return 0
}
create_install_paths()
{
install_paths=(
archives src log bin gems man rubies config
user tmp gems environments wrappers
)
for install_path in "${install_paths[@]}"
do
if [[ ! -d "$rvm_path/$install_path" ]]
then
mkdir -p "$rvm_path/$install_path"
fi
done
if [[ "$rvm_bin_path" != "" ]]
then
if [[ ! -d "$rvm_bin_path" ]]
then
mkdir -p "$rvm_bin_path"
fi
fi
return 0
}
cleanse_old_entities()
{
#
# Remove old files that no longer exist.
#
for script in utility array ; do
if [[ -f "$rvm_path/scripts/${script}" ]]
then
rm -f "$rvm_path/scripts/${script}"
fi
done
return 0
}
install_rvm_files()
{
files=(README LICENCE VERSION)
for file in "${files[@]}"
do
cp -f "$source_path/${file}" "$rvm_path/${file}"
done
directories=(config contrib scripts examples lib help patches)
for directory in ${directories[@]}
do
for entry in $(find $directory 2>/dev/null)
do
if [[ -f "$source_path/$entry" ]]
then
# Target is supposed to be a file, remove if it is a directory.
if [[ -d "$rvm_path/$entry" ]]
then
__rvm_rm_rf "$rvm_path/$entry"
fi
cp -f "$source_path/$entry" "$rvm_path/$entry"
elif [[ -d "$source_path/$entry" ]]
then
# Target is supposed to be a directory, remove if it is a file.
if [[ -f "$rvm_path/$entry" ]]
then
rm -f "$rvm_path/$entry"
fi
if [[ ! -d "$rvm_path/$entry" ]]
then
mkdir -p "$rvm_path/$entry"
fi
fi
done
done
return 0
}
install_rvm_hooks()
{
local hook_x_flag entry
for entry in $(find hooks 2>/dev/null)
do
if [[ -f "$source_path/$entry" ]]
then
# Target is supposed to be a file, remove if it is a directory.
if [[ -d "$rvm_path/$entry" ]]
then
__rvm_rm_rf "$rvm_path/$entry"
fi
# Source is first level hook (after_use) and target is custom user hook, preserve it
if echo "$entry" | \grep -E '^hooks/[[:alpha:]]+_[[:alpha:]]+$' >/dev/null &&
[[ -f "$rvm_path/$entry" ]] &&
! grep "$(basename ${entry})_\*" "$rvm_path/$entry" >/dev/null
then
mv -f "$rvm_path/$entry" "$rvm_path/${entry}_custom"
fi
if [[ -x "$rvm_path/$entry" ]]
then hook_x_flag=$?
else hook_x_flag=$?
fi
cp -f "$source_path/$entry" "$rvm_path/$entry"
if (( hook_x_flag == 0 ))
then
[[ -x "$rvm_path/$entry" ]] || chmod +x "$rvm_path/$entry"
fi
elif [[ -d "$source_path/$entry" ]]
then
# Target is supposed to be a directory, remove if it is a file.
if [[ -f "$rvm_path/$entry" ]]
then
rm -f "$rvm_path/$entry"
fi
if [[ ! -d "$rvm_path/$entry" ]]
then
mkdir -p "$rvm_path/$entry"
fi
fi
done
#fix broken copy of after_use to after_use_custom
if [[ -f "$rvm_path/hooks/after_use_custom" ]] &&
grep "after_use_\*" "$rvm_path/hooks/after_use_custom" >/dev/null
then
rm -f "$rvm_path/hooks/after_use_custom"
fi
return 0
}
setup_configuration_files()
{
pushd "$rvm_path" >/dev/null
if [[ -f config/user ]]
then
mv config/user user/db
fi
if [[ -f config/installs ]]
then
mv config/installs user/installs
fi
if [[ ! -s user/db ]]
then
echo '# User settings, overrides db settings and persists across installs.' \
>> user/db
fi
if [[ -s config/rvmrcs ]]
then
mv config/rvmrcs user/rvmrcs
else
if [[ ! -f user/rvmrcs ]]
then
touch user/rvmrcs
fi
fi
if [[ ! -f user/md5 ]]
then
touch user/md5
fi
# Prune old (keyed-by-hash) trust entries
grep '^_' user/rvmrcs > user/rvmrcs.new || true
mv user/rvmrcs.new user/rvmrcs
popd >/dev/null
}
ensure_scripts_are_executable()
{
scripts=(monitor match log install color db fetch log set package)
for script_name in "${scripts[@]}"
do
if [[ -s "$rvm_scripts_path/$script_name" && ! -x "$rvm_scripts_path/$script_name" ]]
then
chmod +x "$rvm_scripts_path/$script_name"
fi
done
return 0
}
install_binscripts()
{
files=(rvm-prompt rvm-installer rvm rvmsudo rvm-shell rvm-exec rvm-auto-ruby)
if [[ ! -d "${rvm_bin_path}" ]]
then
mkdir -p "${rvm_bin_path}"
fi
for file in "${files[@]}"
do
# Ensure binscripts are always available in rvm_path/bin first.
if [[ -f "${rvm_bin_path}/${file}" ]]
then
rm -f "${rvm_bin_path}/${file}"
fi
cp -f "${source_path}/binscripts/${file}" "${rvm_bin_path}/${file}"
[[ -x "${rvm_bin_path}/${file}" ]] || chmod +x "${rvm_bin_path}/${file}"
if [[ "${source_path}/binscripts" != "${rvm_bin_path}" ]]
then
cp -f "${source_path}/binscripts/${file}" "${rvm_bin_path}/${file}"
fi
done
return 0
}
automatic_profile_setup()
{
true ${rvm_auto_flag:=0} ${rvm_loaded_flag:=0}
if (( rvm_auto_flag == 1 ))
then
printf "Checking rc files... ($rvm_rc_files)"
if (( rvm_loaded_flag == 0 ))
then
for rcfile in "${rvm_rc_files[@]}"
do
if [[ ! -f $rcfile ]]
then
touch "$rcfile"
fi
if [[ -s "${HOME}/.profile" ]]
then
if ! grep '.profile' "$rcfile" >/dev/null 2>&1
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 "scripts\/rvm" "$rcfile" >/dev/null 2>&1
then
echo " Adding rvm loading line to $rcfile."
printf "
# rvm install added:
[[ -s \"$rvm_scripts_path/rvm\" ]] && . \"$rvm_scripts_path/rvm\"
" >> "$rcfile"
fi
done
fi
fi
}
install_gemsets()
{
local gemset_files
if [[ -d gemsets/ ]]
then
if [[ ! -d "$rvm_path/gemsets" ]]
then
mkdir -p "$rvm_path/gemsets"
fi
gemset_files=($(
find "${PWD%%+(\/)}/gemsets" "${name_opt}" '*.gems' | sed 's/^\.\///'
))
for gemset_file in "${gemset_files[@]}"
do
cwd="${PWD//\//\\/}\/gemsets\/"
destination="$rvm_path/gemsets/${gemset_file/$cwd}"
destination_path="$(dirname "$destination")"
if [[ ! -s "$destination" ]]
then
if [[ ! -d "$destination_path" ]]
then
mkdir -p "$destination_path"
fi
cp "$gemset_file" "$destination"
fi
done
fi
}
install_patchsets()
{
if [[ -d patchsets/ ]]
then
if [[ ! -d "$rvm_path/patchsets" ]]
then
mkdir -p "$rvm_path/patchsets"
fi
patchsets=($(
builtin cd patchsets
find \. -type f "${name_opt}" '*' | sed 's/^\.\///'
))
for patchset_file in "${patchsets[@]}"
do
destination="$rvm_path/patchsets/$patchset_file"
if [[ ! -s "$destination" || "${patchset_file##*/}" == "default" ]]
then
destination_path="${destination%/*}"
if [[ ! -d "$destination_path" ]]
then
mkdir -p "$destination_path"
fi
if [[ -f "$destination" ]]
then
rm -f "$destination"
fi
cp "patchsets/$patchset_file" "$destination"
fi
done
fi
}
cleanse_old_environments()
{
if [[ -d "$rvm_path/environments" ]]
then
# Remove BUNDLE_PATH from environment files
environments=($(
find "$rvm_path/environments/" -maxdepth 1 -mindepth 1 -type f
))
if (( ${#environments[@]} > 0 ))
then
for file in "${environments[@]}"
do
if grep 'BUNDLE_PATH' "$file" > /dev/null 2>&1
then
grep -v 'BUNDLE_PATH' "$file" > "$file.new"
mv "$file.new" "$file"
fi
done
fi
fi
}
migrate_old_gemsets()
{
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
}
migrate_defaults()
{
# 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_scripts_path/alias" create default "$original_version" &> /dev/null
fi
unset original_version
__rvm_rm_rf "$rvm_path/config/default"
fi
}
correct_binary_permissions()
{
declare -a files
printf "\n Correct permissions for base binaries in $rvm_bin_path..."
mkdir -p "${rvm_bin_path}"
files=(rvm rvmsudo rvm-shell rvm-auto-ruby)
for file in "${files[@]}"
do
if [[ -s "${rvm_bin_path}/${file}" && ! -x "${rvm_bin_path}/${file}" ]]
then
chmod +x "${rvm_bin_path}/${file}"
fi
done
files=(
manage alias cleanup color current db disk-usage docs env environment-convertor
fetch gemsets get hash help hook info install list maglev match md5 migrate
monitor notes override_gem package patchsets repair rtfm rubygems rvm selector
set snapshot tools upgrade wrapper
)
for file in "${files[@]}"
do
if [[ -s "${rvm_scripts_path}/${file}" && ! -x "${rvm_scripts_path}/${file}" ]]
then
chmod +x "${rvm_scripts_path}/${file}"
fi
done
}
install_man_pages()
{
printf "\n Copying manpages into place.\n"
files=($(
builtin cd "$install_source_path/man"
find . -maxdepth 2 -mindepth 1 -type f -print
))
for file in "${files[@]//.\/}"
do
if [[ ! -d $rvm_man_path/${file%\/*} ]]
then
mkdir -p $rvm_man_path/${file%\/*}
fi
cp -Rf "$install_source_path/man/$file" "$rvm_man_path/$file"
done
}
cleanup_tmp_files()
{
files=($(
find "$rvm_path/" -mindepth 1 -maxdepth 2 "${name_opt}" '*.swp' -type f
))
if (( ${#files[@]} > 0 ))
then
printf "\n Cleanup any .swp files."
for file in "${files[@]}"
do
if [[ -f "$file" ]]
then
rm -f "$file"
fi
done
fi
}
display_notes()
{
true ${upgrade_flag:=0}
if [[ $upgrade_flag -eq 0 ]]
then
[[ -x ./scripts/notes ]] || 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 || echo ${SUDO_USER:-${USERNAME}} )"
fi
if (( upgrade_flag == 1 ))
then
upgrade_notes
check_rubyopt_conditions
printf "\nUpgrade of RVM in $rvm_path/ is complete.\n\n"
else
if (( ${rvm_user_install_flag:=0} == 1 ))
then
installation_complete
fi
check_rubyopt_conditions
printf "\nInstallation of RVM to $rvm_path/ is complete.\n\n"
fi
}
display_requirements()
{
true ${upgrade_flag:=0}
if [[ $upgrade_flag -eq 0 ]]
then
[[ -x ./scripts/requirements ]] || chmod +x ./scripts/requirements # Sometimes things don't clone properly :/
./scripts/requirements
fi
}
#
# root install functions.
#
setup_rvm_path_permissions()
{
chown -R root:"$rvm_group_name" "$rvm_path"
chmod -R g+w "$rvm_path"
if [[ -d "$rvm_path" ]]
then
find "$rvm_path" -type d -print0 | xargs -n1 -0 chmod g+s
fi
return 0
}
setup_rvm_group()
{
if \grep "$rvm_group_name" /etc/group >/dev/null 2>&1
then
echo "RVM system user group '$rvm_group_name' exists, proceeding with installation."
else
echo "Creating RVM system user group '$rvm_group_name'"
case "$(uname)" in
"OpenBSD")
groupadd "$rvm_group_name"
;;
"FreeBSD")
pw groupadd "$rvm_group_name" -q
;;
"Linux")
if [[ -f "/etc/SuSE-release" ]]
then
groupadd "$rvm_group_name"
else
groupadd -f "$rvm_group_name"
fi
;;
"Darwin")
if ! dscl . -read "/Groups/$rvm_group_name" 1>/dev/null 2>&1
then
gid="501" #only gids > 500 show up in user preferences
#Find an open gid
while true
do
name=$(dscl . search /groups PrimaryGroupID $gid | cut -f1 -s)
if [[ -z "$name" ]]
then
break
fi
gid=$[$gid +1]
done
# Create the group, isn't OSX "fun"?! :)
# Yes folks, screw convention!!!
#
# We do NOT have to call dscl twice to create the group and then assign the requested GID.
# Works under 10.4.x, 10.5.x, and 10.6.x, and 10.7.x to combine the initial creation *and* GID assignment.
# Thanks for the assist in determining this, frogor of ##osx-server on freenode! Appreciate the assist!
dscl . -create "/Groups/$rvm_group_name" gid "$gid"
fi
;;
"SunOS")
groupadd "$rvm_group_name"
;;
esac
fi
return 0
}
system_check()
{
local os=$(uname)
case "$os" in
OpenBSD|Linux|FreeBSD|Darwin|SunOS)
return 0 # Accounted for, continue.
;;
*)
printf "Installing RVM as root is currently only supported on the following known OS's (uname):\n Linux, FreeBSD, OpenBSD, Darwin and SunOS\nWhereas your OS is reported as '$os'" >&2
return 1
;;
esac
}
setup_etc_profile()
{
if (( ${rvm_etc_profile_flag:-1} == 0 ))
then return 0 ; fi # opt-out
local executable add_to_profile_flag
executable=0
add_to_profile_flag=0
etc_profile_file="/etc/profile.d/rvm.sh"
if [[ -d /etc/profile.d ]]
then
executable=1
else
mkdir -p /etc/profile.d
add_to_profile_flag=1
executable=0
fi
if ! [[ -s "${etc_profile_file}" ]]
then
printf "#
# RVM profile
#
# /etc/profile.d/rvm.sh # sh extension required for loading.
#
if [ -n \"\${BASH_VERSION:-}\" -o -n \"\${ZSH_VERSION:-}\" ] ; then
# Load user rvmrc configurations, if exist
for file in /etc/rvmrc \"\$HOME/.rvmrc\" ; do
[[ -s \"\$file\" ]] && source \$file
done
# Load RVM if it is installed, try user then root install.
if [[ -s \"\$rvm_path/scripts/rvm\" ]] ; then
source \"\$rvm_path/scripts/rvm\"
elif [[ -s \"\$HOME/.rvm/scripts/rvm\" ]] ; then
true \${rvm_path:=\"\$HOME/.rvm\"}
source \"\$HOME/.rvm/scripts/rvm\"
elif [[ -s \"/usr/local/rvm/scripts/rvm\" ]] ; then
true \${rvm_path:=\"/usr/local/rvm\"}
source \"/usr/local/rvm/scripts/rvm\"
fi
#
# Opt-in for custom prompt through by setting:
#
# rvm_ps1=1
#
# in either /etc/rvmrc or \$HOME/.rvmrc
#
if [[ \${rvm_ps1:-0} -eq 1 ]] ; then
# Source RVM ps1 functions for a great prompt.
if [[ -s \"\$rvm_path/contrib/ps1_functions\" ]] ; then
source \"\$rvm_path/contrib/ps1_functions\"
elif [[ -s \"/usr/local/rvm/contrib/ps1_functions\" ]] ; then
source \"/usr/local/rvm/contrib/ps1_functions\"
fi
if command -v ps1_set >/dev/null 2>&1 ; then
ps1_set
fi
fi
# Add \$rvm_bin_path to \$PATH if necessary
if [[ \"\${rvm_bin_path}\" != \"\${rvm_path}/bin\" ]] ; then
regex=\"^([^:]*:)*\${rvm_bin_path}(:[^:]*)*\$\"
if [[ ! \"\${PATH}\" =~ \$regex ]] ; then
__rvm_add_to_path prepend \"\${rvm_bin_path}\"
fi
fi
fi
" >> "${etc_profile_file}"
if (( executable )) && [[ ! -x "${etc_profile_file}" ]]
then
chmod +x "${etc_profile_file}"
fi
if (( add_to_profile_flag )) &&
! grep "${etc_profile_file}" /etc/profile >/dev/null 2>&1
then
echo "source \"${etc_profile_file}\"" >> /etc/profile
fi
fi
return 0
}
setup_rvmrc()
{
if (( UID == 0 ))
then
rvmrc_file="/etc/rvmrc"
if ! grep 'umask g+w' $rvmrc_file >/dev/null 2>&1
then
echo 'umask g+w' >> $rvmrc_file
fi
if [[ -s $rvmrc_file ]]
then
chown $USER:${rvm_group_name:-$USER} $rvmrc_file
fi
else
rvmrc_file="$HOME/.rvmrc"
fi
return 0
}
setup_user_profile()
{
if (( UID > 0 ))
then
if [[ -n "${ZSH_VERSION:-}" ]]
then
profile_file="$HOME/.zshenv"
else
profile_file="$HOME/.bashrc"
fi
if [[ -d /etc/profile.d ]]
then
etc_profile_file="/etc/profile.d/rvm.sh"
else
etc_profile_file="/etc/profile"
fi
if [[ -f "${profile_file}" ]] &&
! grep '$HOME/.rvm/scripts/rvm' "$profile_file" >/dev/null 2>&1
then
if [[ ! -s "${etc_profile_file}" ]]
then
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*' >> "$profile_file"
fi
fi
fi