/
utility
697 lines (609 loc) · 26.4 KB
/
utility
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
#!/usr/bin/env bash
__rvm_db() {
key=$1 ; variable=$2
if [[ -f "$rvm_config_path/user" ]] ; then
value="$($rvm_scripts_path/db "$rvm_config_path/user" "$key")"
fi
if [[ -z "$value" ]] ; then
value="$($rvm_scripts_path/db "$rvm_config_path/db" "$key")"
fi
if [[ ! -z "$value" ]] ; then
if [[ -z $variable ]] ; then
echo $value
else
eval "$variable=$value"
fi
fi
}
__rvm_info() {
if [[ ! -z "$(which ruby 2>/dev/null)" ]] ; then full_version=$(ruby -v) ; fi
cat <<Info
system:
uname: "$(uname -a)"
ruby:
interpreter: "$(echo $full_version | awk '{print $1}')"
version: "$(echo $full_version | awk '{print $2}')"
date: "$(echo $full_version | sed 's/^.*(\([0-9]\{4\}\(-[0-9][0-9]\)\{2\}\).*$/\1/')"
platform: "$(echo $full_version | sed 's/^.*\[//' | sed 's/\].*$//')"
patchlevel: "$(echo $full_version | sed 's/^.*(//' | sed 's/).*$//')"
full_version: "$full_version"
homes:
gem: "${GEM_HOME:-'not set'}"
ruby: "${MY_RUBY_HOME:-'not set'}"
binaries:
ruby: "$(which ruby 2>/dev/null)"
irb: "$(which irb 2>/dev/null)"
gem: "$(which gem 2>/dev/null)"
rake: "$(which rake 2>/dev/null)"
environment:
GEM_HOME: "$GEM_HOME"
MY_RUBY_HOME: "$MY_RUBY_HOME"
IRBRC: "$IRBRC"
Info
unset full_version
}
__rvm_debug() {
$rvm_scripts_path/log "debug" "PATH:\n$(echo $PATH | awk -F":" '{print $1":"$2":"$3":"$4":"$5}')"
$rvm_scripts_path/log "debug" "uname -a: $(uname -a)"
if [[ "Darwin" = "$(uname)" ]] ; then
$rvm_scripts_path/log "debug" "uname -r: $(uname -r)"
$rvm_scripts_path/log "debug" "uname -m: $(uname -m)"
$rvm_scripts_path/log "debug" "sw_vers: $(sw_vers | tr "\n" ',')"
$rvm_scripts_path/log "debug" "ARCHFLAGS: $ARCHFLAGS"
$rvm_scripts_path/log "debug" "LDFLAGS: $LDFLAGS"
$rvm_scripts_path/log "debug" "CFLAGS: $CFLAGS"
$rvm_scripts_path/log "debug" "/Developer/SDKs/*:$(basename -a /Developer/SDKs/* | tr "\n" ',')"
fi
for file_name in $(echo $rc_files) ; do
if [[ -s "$file_name" ]] ; then
$rvm_scripts_path/log "debug" "$file_name:\n$(grep 'rvm' $file_name)"
fi
done
if [[ "root" = "$(whoami)" ]] ; then
debug_files="$rvm_path/default $rvm_path/system $rvm_path/config/db /etc/rvmrc /etc/gemrc"
else
debug_files="$rvm_path/default $rvm_path/system $rvm_path/config/db $HOME/.rvmrc $HOME/.gemrc"
fi
for file_name in $(echo $debug_files); do
if [[ -f "$file_name" ]] && [[ -s "$file_name" ]] ; then
$rvm_scripts_path/log "debug" "$file_name (filtered):\n$(cat $file_name | awk '!/assword|_key/')\n"
fi
done
$rvm_scripts_path/log "debug" "gem sources:\n$(gem sources | awk '/gems/')"
}
if [[ ! -z "$ZSH_VERSION" ]] ; then __shell_array_start=1 ; else __shell_array_start=0 ; fi
__rvm_push() {
array=$1 ; shift ; item=$2
# TODO: allow loop over more arguments.
eval "index=\$((\${#${array}[*]} + $__shell_array_start))"
eval "${array}[${index}]=${item}"
unset array item
}
__rvm_clean_path() {
PATH=$(echo $PATH | tr -s ':' '\n' | awk '!($0 in a){a[$0];print}' | tr -s '\n' ':' | sed 's#:$##')
export PATH
}
__rvm_remove_rvm_from_path() {
PATH=$(echo $PATH | tr -s ':' '\n' | grep -v "\.rvm" | tr -s '\n' ':' | sed 's#:$##')
export PATH
}
__rvm_gi() { gem install -q --no-rdoc --no-ri $* ; }
__rvm_run() {
log_file_name="$1" ; command="$2" ; message="$3"
rvm_ruby_log_path="${rvm_ruby_log_path:-$rvm_path/log}"
mkdir -p $(dirname "$rvm_ruby_log_path/$log_file_name.log")
if [[ ! -z "$message" ]] ; then $rvm_scripts_path/log "info" "$message" ; fi
(( $rvm_debug_flag )) && $rvm_scripts_path/log "debug" "Executing: $command"
touch "$rvm_ruby_log_path/$log_file_name.log" "$rvm_ruby_log_path/$log_file_name.error.log" # for zsh :(
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $command" | tee "$rvm_ruby_log_path/$log_file_name.log" > "$rvm_ruby_log_path/$log_file_name.error.log"
if [[ -z "$rvm_niceness" ]] || [[ "0" = "$rvm_niceness" ]] ; then
eval "$command" >> "$rvm_ruby_log_path/$log_file_name.log" 2>> "$rvm_ruby_log_path/$log_file_name.error.log"
else
eval "nice -n $rvm_niceness $command" >> $rvm_ruby_log_path/$log_file_name.log 2>> $rvm_ruby_log_path/$log_file_name.error.log
fi
if [[ $? -gt 0 ]] ; then $rvm_scripts_path/log "error" "Error running '$command', please check $rvm_ruby_log_path/$log_file_name.error.log" ; __rvm_pushpop ; return 1 ; fi
unset log_file command
}
__rvm_cleanup_variables() {
__rvm_unset_ruby_variables
unset rvm_ruby_selected_flag rvm_action rvm_irbrc_file rvm_command rvm_error_message rvm_gem_set_name rvm_url rvm_force_flag rvm_all_flag rvm_reconfigure_flag rvm_make_flags rvm_bin_flag rvm_load_flag rvm_dump_flag rvm_self_flag rvm_gem_flag rvm_rubygems_flag rvm_debug_flag rvm_delete_flag rvm_summary_flag rvm_test_flag _rvm_spec_flag rvm_json_flag rvm_yaml_flag rvm_shebang_flag rvm_env_flag rvm_tail_flag rvm_use_flag rvm_dir_flag rvm_list_flag rvm_empty_flag rvm_file_name rvm_benchmark_flag rvm_clear_flag rvm_name_flag rvm_verbose_flag rvm_user_flag rvm_system_flag rvm_ruby_configure_flags
}
__rvm_unset_ruby_variables() {
unset rvm_ruby_interpreter rvm_ruby_version rvm_ruby_repo_url rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_make rvm_ruby_make_install rvm_ruby_revision rvm_ruby_tag rvm_major_version rvm_minor_version rvm_ruby_gem_home rvm_ruby_binary rvm_ruby_home rvm_ruby_log_path rvm_ruby_src_path rvm_ruby_irbrc rvm_ruby_selected_flag rvm_ruby_string rvm_ruby_string rvm_ruby_src_path rvm_ruby_repo_url rvm_major_version rvm_minor_version rvm_ruby_gem_home rvm_head_flag rvm_ruby_configure rvm_ruby_mode
}
__rvm_load_rvmrc() {
if [[ -f /etc/rvmrc ]] ; then source /etc/rvmrc ; fi
if [[ -f $HOME/.rvmrc ]] ; then source $HOME/.rvmrc ; fi
}
__rvm_bin_scripts() {
for rvm_ruby_binary in $(\ls $rvm_path/*/bin/ruby 2> /dev/null) ; do
if [[ -x "$rvm_ruby_binary" ]] ; then
rvm_ruby_string=$(dirname "$rvm_ruby_binary" | xargs dirname | xargs basename)
__rvm_select
__rvm_bin_script
fi
done
}
__rvm_bin_script() {
if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select $* ; fi
ruby_wrapper=$(cat <<RubyWrapper
#!/bin/bash
GEM_HOME=$rvm_ruby_gem_home ; export GEM_HOME
GEM_PATH=$rvm_ruby_gem_home ; export GEM_PATH
MY_RUBY_HOME=$rvm_ruby_home ; export MY_RUBY_HOME
PATH=$rvm_ruby_home/bin:$rvm_ruby_gem_home/bin:\$PATH ; export PATH
exec "$rvm_ruby_binary" "\$@"
RubyWrapper
)
rm -f $rvm_path/bin/$rvm_ruby_package_name
echo "$ruby_wrapper" > $rvm_path/bin/$rvm_ruby_package_name
unset ruby_wrapper
chmod +x $rvm_path/bin/$rvm_ruby_package_name
}
__rvm_load_defaults() {
if [[ ! -s "$rvm_path/system" ]] ; then
for variable in RUBY_VERSION GEM_HOME GEM_PATH MY_RUBY_HOME ; do
eval value=\$${variable}
if [[ -z "$value" ]] ; then
echo "unset ${variable}" >> $rvm_path/system
else
eval "export $variable"
eval value=\$${variable}
echo "${variable}='$value' ; export ${variable}" >> $rvm_path/system
fi
done
fi
__rvm_db "system_ruby" "rvm_system_ruby"
if [[ ! -z "$rvm_system_ruby" ]] ; then
rvm_system_ruby=$(which ruby 2>/dev/null)
if [[ $? -ne 0 ]] ; then
$rvm_scripts_path/log "info" "System ruby not found, no system default will be stored."
else
$rvm_scripts_path/db "$rvm_config_path/user" "system_ruby" "$rvm_system_ruby"
# Now store system system & user gem paths
if [[ ! -z "$(which gem 2>/dev/null)" ]] ; then
__rvm_db "system_user_gem_path" "rvm_system_user_gem_path"
if [[ -z "$rvm_system_user_gem_path" ]] ; then
rvm_system_user_gem_path=$( rvm system ; gem env gemdir user; )
$rvm_scripts_path/db "$rvm_config_path/user" "system_user_gem_path" "$rvm_system_user_gem_path"
fi
__rvm_db "system_gem_path" "rvm_system_gem_path"
if [[ -z "$rvm_system_gem_path" ]] ; then
rvm_system_gem_path=$( rvm system ; gem env gemdir; )
$rvm_scripts_path/db "$rvm_config_path/user" "system_gem_path" "$rvm_system_gem_path"
fi
fi
fi
fi
}
__rvm_reset() {
PATH=$(echo $PATH | tr ':' '\n' | awk '$0 !~ /rvm/' | paste -sd : -)
PATH=$rvm_bin_path:$PATH ; export PATH
for variable in RUBY_VERSION GEM_HOME MY_RUBY_HOME ; do unset $variable ; done
for file in system default ; do
if [[ -f "$rvm_path/$file" ]] ; then rm -f $rvm_path/$file ; fi
done
rvm_ruby_interpreter="system"
__rvm_select
for system_config in system_ruby system_gem_path system_user_gem_path ; do
$rvm_scripts_path/db "$rvm_config_path/user" "$system_config" "delete"
done ; unset system_config variable
rm -f $rvm_path/bin/ruby $rvm_path/bin/gem $rvm_path/bin/rake $rvm_path/bin/irb $rvm_path/bin/default*
}
__rvm_implode() {
while : ; do
$rvm_scripts_path/log "warn" "Are you SURE you wish for rvm to implode? This will remove $rvm_path ? (type 'yes' or 'no')"
read response
if [[ "yes" = "$response" ]] ; then
if [[ "/" = "$rvm_path" ]] ; then
$rvm_scripts_path/log "error" "remove '/' ?!... NO!"
else
if [[ -d "$rvm_path" ]] ; then
$rvm_scripts_path/log "info" "Hai! Removing $rvm_path"
rm -rf $rvm_path/
$rvm_scripts_path/log "info" "$rvm_path has been removed."
else
$rvm_scripts_path/log "info" "It appears that $rvm_path is already non existant."
fi
fi
break
elif [[ "no" = "$response" ]] ; then
$rvm_scripts_path/log "info" "Cancelling implosion, no harm done :)"
break
fi
done
}
__rvm_source_dir() {
if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select $* ; fi
if [[ -z "$rvm_ruby_src_path" ]] ; then
$rvm_scripts_path/log "fail" "No source directory exists for the default implementation."
else
echo "$rvm_ruby_src_path"
fi
}
__rvm_list() {
if [[ ! -z "$rvm_all_flag" ]] ; then
while read -r tag
do
prefix="$(echo ${tag/\//} | sed 's#^v1_##' | awk -F'_' '{print "(ruby-)1."$1"."$2}' | sed 's#p$##')"
echo "${prefix}-t${tag/\//}"
unset prefix tag
done < <(svn list http://svn.ruby-lang.org/repos/ruby/tags/ | awk '/^v1_[8|9]/')
echo -e "(ruby-)1.8.6(-p383)\n(ruby-)1.8.6-head\n(ruby-)1.8.7(-p174)\n(ruby-)1.8.7-head\n(ruby-)1.9.1(-p243)\n(ruby-)1.9.1-head\n(ruby-)1.9.2-preview1"
echo -e "jruby-1.2.0\njruby-1.3.0\njruby-1.3.1\njruby(-1.4.0) # the default\njruby-head"
echo -e "rbx(-head) # rubinius head, the default rbx \nrbx(-head) --jit (rubinius head with LLVM enabled)"
echo -e "ree-1.8.6\nree(-1.8.7) # the default\nree-1.8.6-head\nree-1.8.7-head"
echo -e "mput(-head) # shyouhei head, the default mput"
if [[ "Darwin" = "$(uname)" ]] ; then
echo -e "macruby(-nightly) # the default macruby\nmacruby-head # Build from the macruby git repository"
fi
else
ruby=$(which ruby 2>/dev/null) ; current_ruby=""
if [[ ! -z "$ruby" ]] && [[ ! -z "$(echo $ruby | awk '/rvm/')" ]] ; then
current_ruby="$(echo $ruby | xargs dirname | xargs dirname | xargs basename 2> /dev/null)"
fi
for version in $(\ls -l $rvm_path/ 2> /dev/null | awk '/ ruby-[1-2].*/ { print $NF }') ; do
string=$($rvm_path/$version/bin/ruby -v)
if [[ "$version" = "$current_ruby" ]] ; then
echo -e "=> $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
selected="1"
else
echo -e " $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
fi
done ; unset version
for version in $(\ls $rvm_path/ 2> /dev/null | awk '/ree-.*/ { print $NF }') ; do
string="$($rvm_path/$version/bin/ruby -v | tr "\n" ' ' )"
if [[ "$version" = "$current_ruby" ]] ; then
echo -e "=> $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
selected="1"
else
echo -e " $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
fi
done ; unset version
for version in $(\ls $rvm_path/ 2> /dev/null | awk '/mput-.*/ { print $NF }') ; do
string="$($rvm_path/$version/bin/ruby -v | tr "\n" ' ' )"
if [[ "$version" = "$current_ruby" ]] ; then
echo -e "=> $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
selected="1"
else
echo -e " $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
fi
done ; unset version
for version in $(\ls $rvm_path/ 2> /dev/null | awk '/jruby-.*/ { print $NF }') ; do
string=$($rvm_path/$version/bin/ruby -v)
if [[ "$version" = "$current_ruby" ]] ; then
echo -e "=> $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
selected="1"
else
echo -e " $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
fi
done ; unset version
# for version in $(\ls $rvm_path/ 2> /dev/null | awk '/rbx-.*/ { print $NF }') ; do
for version in "rbx-head" ; do
if [[ -f "$rvm_path/$version/bin/ruby" ]] ; then
string="$($rvm_path/$version/bin/ruby -v | tr "\n" ' ' )"
if [[ "$version" = "$current_ruby" ]] ; then
echo -e "=> $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
selected="1"
else
echo -e " $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
fi
fi
done ; unset version
if [[ "Darwin" = "$(uname)" ]] ; then
for version in $(\ls $rvm_path/ 2> /dev/null | awk '/macruby-.*/ { print $NF }') ; do
string="$($rvm_path/$version/bin/ruby -v | tr "\n" ' ' )"
if [[ "$version" = "$current_ruby" ]] ; then
echo -e "=> $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
selected="1"
else
echo -e " $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
fi
done ; unset version
fi
if [[ -f "$rvm_path/default" ]] && [[ -s $rvm_path/default ]] ; then
version=$(grep '^MY_RUBY_HOME' $rvm_path/default | awk -F"'" '{print $2}' | xargs basename)
if [[ ! -z "$version" ]] ; then
string=$($rvm_path/$version/bin/ruby -v)
if [[ "$version" = "$current_ruby" ]] ; then
echo -e "=> $(tput setaf 3)(default)$(tput sgr0) $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
selected="1"
else
echo -e " $(tput setaf 3)(default)$(tput sgr0) $(tput setaf 2)$version$(tput sgr0) ( ruby -v # => $string) )"
fi
fi ; unset version
fi
system_ruby="$(rvm system ; which ruby 2>/dev/null)"
if [[ ! -z "$system_ruby" ]] ; then
system_version=$($system_ruby -v)
if [[ ! -z "$(which ruby 2>/dev/null)" ]] && [[ "$($(which ruby 2>/dev/null) -v)" = "$system_version" ]] ; then
echo -e "=> $(tput setaf 2)system$(tput sgr0) ( ruby -v # => $system_version )\n"
else
echo -e " $(tput setaf 2)system$(tput sgr0) ( ruby -v # => $system_version )\n"
fi
else
$rvm_scripts_path/log "info" "No system ruby found."
fi
unset current_ruby version selected system_ruby system_version string
fi
}
__rvm_initialize() {
rvm_ruby_load_path="."
rvm_ruby_require=""
__rvm_clean_path
rvm_result=$(echo $PATH | grep 'rvm\/bin:')
if [[ -z "$rvm_result" ]] ; then
PATH=$rvm_bin_path:$PATH ; export PATH
fi
mkdir -p $rvm_src_path $rvm_bin_path $rvm_archives_path $rvm_gem_path $rvm_tmp_path
}
__rvm_update() {
if [[ "head" = "$rvm_ruby_revision" ]] || [[ ! -z "$rvm_self_flag" ]] || [[ "update" = "$rvm_action" ]] || [[ ! -z "$rvm_update_flag" ]] ; then
__rvm_version
__rvm_update_rvm
fi
if [[ ! -z "$rvm_bin_flag" ]] ; then __rvm_bin_scripts ; fi
if [[ ! -z "$rvm_rubygems_flag" ]] ; then __rvm_rubygems_setup ; fi
unset rvm_update_flag rvm_action rvm_self_flag rvm_ruby_revision rvm_bin_flag rvm_rubygems_flag
}
__rvm_update_rvm() {
mkdir -p "$rvm_src_path"
__rvm_pushpop "$rvm_src_path"
system_ruby="$(rvm system ; which ruby 2>/dev/null)"
if [[ "head" = "$rvm_ruby_revision" ]] || [[ -z "$system_ruby" ]] ; then
if [[ -d "$rvm_src_path/rvm/.git" ]] ; then
builtin cd $rvm_src_path/rvm/ && git pull origin master && ./scripts/install
else
builtin cd $rvm_src_path && git clone git://github.com/wayneeseguin/rvm.git && builtin cd rvm/ && ./install
fi
else
# TODO: rvm_install_path:
gem install rvm --no-rdoc --no-ri -q rvm && cd "$(rvm system ; gem env | grep "\- $HOME" | awk '{print $NF}')/gems/rvm-$(gem list rvm | sed 's/.*(//' | awk -F',' '{print $1 ; exit}')" && ./install
fi
__rvm_pushpop
__rvm_hook "after_update"
}
__rvm_reboot() {
$rvm_scripts_path/log "warn" "Do you wish to reset rvm? ('yes', or 'no')"
read response
if [[ "yes" = "$response" ]] ; then
builtin cd $rvm_path
__rvm_reset
mv $rvm_path/archives ~/.archives
if [[ "/" = "$rvm_path" ]] ; then
$rvm_scripts_path/log "error" "remove '/' ?!... NO!"
else
if [[ -d "$rvm_path" ]] ; then rm -rf "$rvm_path/" ; fi
fi
gem install rvm --no-rdoc --no-ri -q
__rvm_update_rvm
source $rvm_path/scripts/rvm
else
$rvm_scripts_path/log "info" "Carry on then..."
fi ; unset response
}
__rvm_ruby_do() {
__rvm_select
__rvm_use
binary="$(echo $rvm_action | sed 's#do$##')"
if [[ -x "$rvm_ruby_home/bin/$binary" ]] ; then
binary="$rvm_ruby_home/bin/$binary"
elif [[ -x "$rvm_ruby_gem_home/bin/$binary" ]] ; then
binary="$rvm_ruby_gem_home/bin/$binary"
elif [[ "system" = "$rvm_ruby_string" ]] && [[ -x "$(which $binary)" ]] ; then
binary="$(which $binary 2>/dev/null)"
#elif [[ "spec" = "$binary" ]] ; then
#binary="$(which $binary 2>/dev/null)"
else
$rvm_scripts_path/log "warn" "'$binary not found for $rvm_ruby_string' either does not exist or is not executable? :("
__rvm_unset_ruby_variables
return 1
fi
if [[ ! -z "$rvm_ruby_mode" ]] ; then
rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_mode"
rvm_ruby_mode="--$(echo $rvm_ruby_mode | sed 's/^m//')"
fi
load_path="$rvm_ruby_home/bin:$rvm_ruby_load_path"
# TODO: the else case below should be run if $rvm_ruby_args =~ /\.rb$/
if [[ "ruby" = "$binary" ]] && [[ "$rvm_benchmark_flag" -ne 1 ]] ; then
if $rvm_scripts_path/match "$rvm_ruby_args" "\.rb$" ; then
if [[ -z "$prefix" ]] ; then prefix="-S" ; fi
if ! $rvm_scripts_path/match "$rvm_ruby_args" "$prefix" ; then
rvm_ruby_args="$prefix $rvm_ruby_args"
fi
fi
rvm_command="$binary $rvm_ruby_mode $rvm_ruby_require -I$load_path $rvm_ruby_args"
elif [[ "gem" = "$binary" ]] && match "$rvm_ruby_args" '^install' ; then
rvm_command="$binary $rvm_ruby_mode $rvm_ruby_args --no-rdoc --no-ri"
else
rvm_command="$binary $rvm_ruby_mode $rvm_ruby_args"
fi
mkdir -p ./log/$rvm_ruby_string/
if [[ ! -z "$rvm_json_flag" ]] || [[ ! -z "$rvm_yaml_flag" ]] || [[ ! -z "$rvm_summary_flag" ]] ; then
touch ./log/$rvm_ruby_string/$rvm_action.log ./log/$rvm_ruby_string/$rvm_action.error.log
eval "$rvm_command" >> ./log/$rvm_ruby_string/$rvm_action.log 2>> ./log/$rvm_ruby_string/$rvm_action.error.log
else
echo -e "\n\n\033[0;32m$rvm_ruby_string: $($rvm_ruby_home/bin/ruby -v $rvm_ruby_mode | tr "\n" ' ')\033[0m\n"
eval "$rvm_command"
fi
result=$?
if [[ $result -eq 0 ]]; then
eval "successes=(${successes[*]} $rvm_ruby_string)"
else
eval "errors=(${errors[*]} $rvm_ruby_string)"
fi
eval "rubies=(${rubies[*]} $rvm_ruby_string)"
eval "statuses=(${statuses[*]} $result)"
__rvm_unset_ruby_variables
}
__rvm_do() {
__rvm_state
rubies=() ; successes=() ; errors=() ; statuses=()
# TODO: Extract the common functionality out of the if below
if [[ ! -z "$rvm_ruby_string" ]] ; then
unset rvm_ruby_interpreter rvm_ruby_version
__rvm_ruby_do
elif [[ ! -z "$rvm_ruby_version" ]] ;then
for rvm_ruby_string in $(echo $rvm_ruby_version | tr ',' ' ') ; do
__rvm_ruby_do
done
elif [[ ! -z "$rvm_ruby_interpreter" ]] ; then
unset rvm_ruby_string rvm_ruby_version
__rvm_ruby_do
else # all
rubies=($(\ls $rvm_path/*/bin/ruby))
for full_binary in ${rubies[@]} ; do
if [[ -x "$full_binary" ]] ; then
rvm_ruby_string="$(dirname $full_binary | xargs dirname | xargs basename)"
__rvm_ruby_do
fi
done ; unset full_binary rubies
fi
if [[ ! -z "$rvm_summary_flag" ]] ; then __rvm_summary ; fi
if [[ ! -z "$rvm_yaml_flag" ]] ; then __rvm_yaml ; fi
if [[ ! -z "$rvm_json_flag" ]] ; then __rvm_json ; fi
__rvm_state
__rvm_hook "after_do"
return ${#errors[*]}
}
__rvm_summary() {
export successes errors statuses
summary="\nSummary:\n\n"
if [[ ${#successes[*]} -gt 0 ]] ; then
summary="$summary \033[0;32m${#successes[*]} successful: $(echo "${successes[*]}" | sed 's# #, #g')\033[0m\n"
fi
if [[ ${#errors[*]} -gt 0 ]] ; then
summary="$summary \033[0;31m${#errors[*]} errors: $(echo "${errors[*]}" | sed 's# #, #g')\033[0m\n"
fi
total=${#rubies[*]}
if [[ ! -z "$ZSH_VERSION" ]] ; then array_start=1 ; else array_start=0 ; fi
echo -e "$summary" | tee -a log/summary.log
return ${#errors[*]}
}
__rvm_yaml() {
export successes errors statuses
yaml="totals:\n rubies: ${#rubies[*]}\n successes: ${#successes[*]}\n errors: ${#errors[*]}\nsuccesses:"
for var in ${successes[*]} ; do yaml="$yaml\n - $var" ; done
yaml="$yaml\nerrors:"
for var in ${errors[*]} ; do yaml="$yaml\n - $var" ; done
yaml="$yaml\nrubies:"
total=${#rubies[*]}
if [[ ! -z "$ZSH_VERSION" ]] ; then array_start=1 ; else array_start=0 ; fi
for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do
(( $rvm_debug_flag )) && $rvm_scripts_path/log "debug" "${rubies[$index]}: ${statuses[$index]}"
yaml="$yaml\n \"${rubies[$index]}\": ${statuses[$index]}"
done ; unset index array_start
mkdir -p log
echo -e "$yaml" | tee -a log/summary.yaml
return ${#errors[*]}
}
__rvm_json() {
json="{"
json="$json\n \"totals\": { \"rubies\": ${#rubies[*]}, \"successes\": ${#successes[*]}, \"errors\": ${#errors[*]}},"
json="$json\n \"successful\": [ "$(echo ${successes[*]} | sed 's# #", "#g')" ],"
json="$json\n \"errors\": [ "$(echo ${errors[*]} | sed 's# #", "#g')" ],"
json="$json\n \"rubies\": {"
total=${#rubies[*]}
if [[ ! -z "$ZSH_VERSION" ]] ; then array_start=1 ; else array_start=0 ; fi
for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do
(( $rvm_debug_flag )) && $rvm_scripts_path/log "debug" "${rubies[$index]}: ${statuses[$index]}"
json="$json\n {\"${rubies[$index]}\": ${statuses[$index]}}"
if (( $index + 1 < $total + $array_start )) ; then json="$json, " ; fi
done ; unset index array_start
json="$json\n }\n}"
mkdir -p log
echo -e "$json" | tee -a log/summary.json
return ${#errors[*]}
}
__rvm_benchmark() {
code="require \"benchmark\" \n Benchmark.bmbm do |benchmark| \n benchmark.report(\"${rvm_ruby_file}\") do \n"
echo -e "$code" > "$rvm_tmp_path/$$.rb"
unset code
cat $rvm_ruby_file >> "$rvm_tmp_path/$$.rb"
echo -e "\n end \nend\n" >> "$rvm_tmp_path/$$.rb"
rvm_ruby_args="$rvm_tmp_path/$$.rb"
rvm_benchmark_flag=1
rvm_action="ruby"
if [[ ! -z "$rvm_debug_flag" ]] ; then echo -e "$rvm_tmp_path/$$.rb:\n$(cat $rvm_tmp_path/$$.rb)" ; fi
__rvm_do
}
__rvm_irbrc() {
# Create the irbrc for the currently selected ruby installation.
if [[ -d "$rvm_ruby_home" ]] && [[ ! -s "$rvm_ruby_irbrc" ]] ; then
cp $rvm_path/scripts/irbrc $rvm_ruby_irbrc
fi
}
__rvm_pushpop() {
if [[ -z "$1" ]] ; then
popd > /dev/null 2>&1
else
pushd "$1" > /dev/null 2>&1
fi
}
__rvm_state() {
if [[ -z "$rvm_state" ]] ; then
if [[ -z "$(which ruby 2>/dev/null | awk /$(basename $rvm_path)/)" ]] ; then
rvm_state=system
else
rvm_state="$(dirname "$(which ruby 2>/dev/null)" | xargs dirname | xargs basename)"
fi
else
rvm_ruby_string="$rvm_state"
__rvm_select
__rvm_use
unset rvm_state
fi
}
__rvm_inspect() {
for binary in $rvm_ruby_args ; do
actual_file="$(which $binary 2>/dev/null)"
$rvm_scripts_path/log "info" "$actual_file:"
if [[ ! -z "$rvm_shebang_flag" ]] ; then cat $actual_file | head -n 1 ; fi
if [[ ! -z "$rvm_env_flag" ]] ; then cat $actual_file | awk '/ENV/' ; fi
if [[ ! -z "$rvm_path_flag" ]] ; then cat $actual_file | awk '/PATH/' ; fi
if [[ ! -z "$rvm_head_flag" ]] ; then cat $actual_file | head -n 5 ; fi
if [[ ! -z "$rvm_tail_flag" ]] ; then cat $actual_file | tail -n 5 ; fi
if [[ ! -z "$rvm_all_flag" ]] ; then cat $actual_file ; fi
done
}
__rvm_make_flags() {
PATH=${rvm_path}/usr/bin:$PATH ; export PATH
# This is only an issue with Darwin :/
if [[ "Darwin" = "$(uname)" ]] ; then
# ls /usr/lib/gcc/i686-apple-darwin10
# Set the build & host type
if [[ "Power Macintosh" = "$(sysctl hw.machine | awk -F: '{print $2}' | sed 's/^ //')" ]] ; then
: # Do nothing ?
elif [[ $(sysctl hw.cpu64bit_capable | awk '{print $2}') = 1 ]] ; then # we could also use: sysctl hw.optional.x86_64
# 64 bit capable
if [[ "-arch x86_64" = "$rvm_archflags" ]] ; then
rvm_ruby_configure_flags="${rvm_ruby_configure_flags} --build=i686-apple-darwin$(uname -r) --host=i686-apple-darwin$(uname -r)"
elif [[ "-arch i386" = "$rvm_archflags" ]] ; then
rvm_ruby_configure_flags="${rvm_ruby_configure_flags} --build=i386-apple-darwin$(uname -r) --host=i386-apple-darwin$(uname -r)"
else
rvm_archflags="-arch x86_64"
rvm_ruby_configure_flags="${rvm_ruby_configure_flags} --build=i686-apple-darwin$(uname -r) --host=i686-apple-darwin$(uname -r)"
fi
else
# 32 bit capable only
if [[ -z "$rvm_archflags" ]] ; then rvm_archflags="-arch i386" ; fi
rvm_ruby_configure_flags="${rvm_ruby_configure_flags} --build=i386-apple-darwin$(uname -r) --host=i386-apple-darwin$(uname -r)"
fi
if [[ ! -z "$rvm_archflags" ]] ; then
ARCHFLAGS="$rvm_archflags" ; export ARCHFLAGS
# Use the latest sdk available.
if [[ -z "$rvm_sdk" ]] ; then rvm_sdk="$(basename -a /Developer/SDKs/* | awk '/^M/' | sort | tail -n 1)" ; fi
CFLAGS="${CFLAGS:-"-isysroot /Developer/SDKs/$rvm_sdk $rvm_archflags"}" ; export CFLAGS
LDFLAGS="${LDFLAGS:-"-Wl,-syslibroot /Developer/SDKs/$rvm_sdk $rvm_archflags"}" ; export LDFLAGS
# CXXFLAGS="-mmacosx-version-min="$(sw_vers -productVersion | awk -F'.' '{print $1"."$2}')" -isysroot /Developer/SDKs/$rvm_sdk " ; export CXXFLAGS
fi
fi
}
__rvm_hook() {
if [[ ! -z "$1" ]] ; then
if [[ -s "$rvm_hooks_path/$1" ]] ; then
if [[ "$rvm_verbose_flag" -eq 1 ]] || [[ "$rvm_debug_flag" -eq 1 ]] ; then $rvm_scripts_path/log "info" "running hook $1" ; fi
source "$rvm_hooks_path/$1"
fi
fi
}