rvm 0.1.43 → 0.1.44

Sign up to get free protection for your applications and to get access to all the features.
@@ -95,6 +95,11 @@ else
95
95
  exit 1
96
96
  fi
97
97
 
98
+ # Update the rubygems to the current.
99
+ if [[ "$version" = "current" ]]; then
100
+ version="$(__rvm_db "${rvm_ruby_interpreter}_rubygems_version")"
101
+ version="${rvm_rubygems_version:-"$(__rvm_db "rubygems_version")"}"
102
+ fi
98
103
  rubygems_setup
99
104
 
100
105
  exit $result
@@ -4,22 +4,35 @@
4
4
  # http://rvm.beginrescueend.com
5
5
  # http://gitub.com/wayneeseguin/rvm
6
6
 
7
+ rvm_reload_flag="${rvm_reload_flag:-0}"
8
+ rvm_loaded_flag="${rvm_loaded_flag:-0}"
7
9
  if [[ "$rvm_loaded_flag" != "1" ]] || [[ "$rvm_reload_flag" = "1" ]] ; then
8
10
  unset rvm_reload_flag
9
11
 
10
- for rvmrc in /etc/rvmrc $HOME/.rvmrc ; do
11
- if [[ -f "$rvmrc" ]] ; then
12
- if grep -q '^\s*rvm .*$' $rvmrc ; then
13
- printf "\nError: $rvmrc is for rvm settings only.\nrvm CLI may NOT be called from within $rvmrc. \nSkipping the loading of $rvmrc"
14
- return 1
15
- else
16
- source "$rvmrc"
12
+ if [[ -z "$rvm_ignore_rvmrc" ]]; then
13
+ for rvmrc in /etc/rvmrc $HOME/.rvmrc ; do
14
+ if [[ -f "$rvmrc" ]] ; then
15
+ if grep -q '^\s*rvm .*$' $rvmrc ; then
16
+ printf "\nError: $rvmrc is for rvm settings only.\nrvm CLI may NOT be called from within $rvmrc. \nSkipping the loading of $rvmrc"
17
+ return 1
18
+ else
19
+ source "$rvmrc"
20
+ fi
17
21
  fi
22
+ done
23
+ fi
24
+
25
+ # Set the default sandboxed value.
26
+ if [[ -z "$rvm_sandboxed" ]]; then
27
+ if [[ "root" = "$(whoami)" ]] || [[ -n "$rvm_prefix" && "$rvm_prefix" != "$HOME"/* ]]; then
28
+ rvm_sandboxed=0
29
+ else
30
+ rvm_sandboxed=1
18
31
  fi
19
- done
32
+ fi
20
33
 
21
34
  if [[ -z "$rvm_prefix" ]] ; then
22
- if [[ "root" = "$(whoami)" ]] ; then
35
+ if [[ "$rvm_sandboxed" = "0" ]] ; then
23
36
  rvm_prefix="/usr/local"
24
37
  else
25
38
  rvm_prefix="$HOME/."
@@ -28,7 +41,7 @@ if [[ "$rvm_loaded_flag" != "1" ]] || [[ "$rvm_reload_flag" = "1" ]] ; then
28
41
 
29
42
  if [[ -z "$rvm_path" ]] ; then
30
43
  unset rvm_path
31
- if [[ "root" = "$(whoami)" ]] ; then
44
+ if [[ "$rvm_sandboxed" = "0" ]] ; then
32
45
  rvm_path="$rvm_prefix/rvm"
33
46
  else
34
47
  if [[ -d "$HOME/.rvm" ]] && [[ -s "$HOME/.rvm/scripts/rvm" ]]; then
@@ -47,7 +60,7 @@ if [[ "$rvm_loaded_flag" != "1" ]] || [[ "$rvm_reload_flag" = "1" ]] ; then
47
60
  elif [[ -d "$rvm_path/scripts" ]] && [[ -s "$rvm_path/scripts/rvm" ]]; then
48
61
  rvm_scripts_path="$rvm_path/scripts"
49
62
  else
50
- if [[ "root" = "$(whoami)" ]] ; then
63
+ if [[ "$rvm_sandboxed" = "0" ]] ; then
51
64
  rvm_scripts_path="/usr/local/rvm"
52
65
  else
53
66
  rvm_scripts_path="$HOME/.rvm"
@@ -67,7 +80,7 @@ if [[ "$rvm_loaded_flag" != "1" ]] || [[ "$rvm_reload_flag" = "1" ]] ; then
67
80
 
68
81
  rvm_loaded_flag=1
69
82
 
70
- rvm_version="$(cat "${rvm_path}/lib/VERSION.yml" | tail -n 3 | sed 's/^.*: //g' | tr "\n" '.' | sed 's/\.$//')" ; export rvm_version
83
+ rvm_version="$(cat "${rvm_path}/lib/VERSION.yml" | tail -n 3 | sed 's/^.*: //g' | \tr "\n" '.' | sed 's/\.$//')" ; export rvm_version
71
84
 
72
85
  alias rvm-restart="source '${rvm_path}/scripts/rvm'"
73
86
 
@@ -1,10 +1,18 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
+ if [[ -z "$rvm_sandboxed" ]]; then
4
+ if [[ "root" = "$(whoami)" ]] || [[ -n "$rvm_prefix" && "$rvm_prefix" != "$HOME"/* ]]; then
5
+ export rvm_sandboxed=0
6
+ else
7
+ export rvm_sandboxed=1
8
+ fi
9
+ fi
10
+
3
11
  unset rvm_auto_flag
4
12
 
5
- install_source_path=$(dirname $0)
13
+ install_source_path="$(dirname "$0" | sed 's#\/scripts$##')"
6
14
  if [[ -d "$install_source_path/scripts" ]] && [[ -s "$install_source_path/scripts/utility" ]] ; then
7
- builtin cd $install_source_path
15
+ builtin cd "$install_source_path"
8
16
  fi
9
17
 
10
18
  source scripts/version
@@ -53,7 +61,7 @@ done
53
61
 
54
62
  if [[ -z "$rvm_prefix" ]] ; then
55
63
  __rvm_load_rvmrc
56
- if [[ "root" = "$(whoami)" ]] ; then
64
+ if [[ "$rvm_sandboxed" = "0" ]] ; then
57
65
  rvm_prefix="${rvm_prefix:-"/usr/local/"}"
58
66
  else
59
67
  rvm_prefix="${rvm_prefix:-"$HOME/."}"
@@ -64,7 +72,7 @@ if [[ -z "$rvm_path" ]] ; then rvm_path="${rvm_prefix}rvm" ; fi
64
72
 
65
73
  source scripts/initialize
66
74
 
67
- if grep -q 'scripts/rvm' $HOME/.bash* || grep -q 'scripts/rvm' $HOME/.zsh*; then
75
+ if grep -q 'scripts/rvm' $HOME/.bash* 2>/dev/null || grep -q 'scripts/rvm' $HOME/.zsh* 2>/dev/null; then
68
76
  if [[ -d "$rvm_path" ]] && [[ -s "${rvm_path}/scripts/rvm" ]] ; then
69
77
  export upgrade_flag=1
70
78
  else
@@ -114,7 +122,7 @@ fi
114
122
 
115
123
  spinner
116
124
 
117
- mkdir -p $rvm_archives_path $rvm_src_path $rvm_log_path $rvm_bin_path $rvm_gems_path $rvm_rubies_path $rvm_config_path $rvm_hooks_path $rvm_tmp_path
125
+ mkdir -p "$rvm_archives_path" "$rvm_src_path" "$rvm_log_path" "$rvm_bin_path" "$rvm_gems_path" "$rvm_rubies_path" "$rvm_config_path" "$rvm_hooks_path" "$rvm_tmp_path"
118
126
 
119
127
  for file in README LICENCE ; do
120
128
  spinner
@@ -148,7 +156,7 @@ done
148
156
  # Bin Scripts
149
157
  #
150
158
  # Cleanse and purge...
151
- for file in rvm-prompt rvm rvmsudo rvm-shell ; do
159
+ for file in rvm-prompt rvm rvmsudo rvm-shell rvm-auto-ruby ; do
152
160
  spinner && perl -e 'sleep 0.2'
153
161
  rm -f "$rvm_bin_path/$file"
154
162
  cp -f "$source_path/binscripts/$file" $rvm_bin_path/
@@ -183,29 +191,30 @@ fi
183
191
  # Initial Interpreter Gemsets.
184
192
  #
185
193
  spinner
186
- mkdir -p "$rvm_gemsets_path"
187
- for gemset_file in $(cd gemsets ; find . -iname '*.gems' | sed 's/^\.\///') ; do
188
- source_path="$(pwd)/gemsets"
189
- destination="$rvm_gemsets_path/$gemset_file"
190
- destination_path="$(dirname "$destination")"
191
- if [[ ! -s "$destination" ]] ; then
192
- mkdir -p "$destination_path"
193
- cp "$source_path/$gemset_file" "$destination"
194
- fi
195
- done ; unset destination destination_path source_path gemset_file
194
+ if [[ -d gemsets/ ]] ; then
195
+ mkdir -p "$rvm_gemsets_path"
196
+ for gemset_file in $(cd gemsets ; find . -iname '*.gems' | sed 's/^\.\///') ; do
197
+ destination="$rvm_gemsets_path/$gemset_file"
198
+ destination_path="$(dirname "$destination")"
199
+ if [[ ! -s "$destination" ]] ; then
200
+ mkdir -p "$destination_path"
201
+ cp "gemsets/$gemset_file" "$destination"
202
+ fi
203
+ done ; unset destination destination_path gemset_file
204
+ fi
196
205
 
197
206
  spinner
198
- mkdir -p "$rvm_patchsets_path"
199
- for patchsets_file in $(cd gemsets ; find . -iname '*' | sed 's/^\.\///') ; do
200
- source_path="$(pwd)/gemsets"
201
- destination="$rvm_patchsets_path/$patchset_file"
202
- destination_path="$(dirname "$destination")"
203
- if [[ ! -s "$destination" ]] ; then
204
- mkdir -p "$destination_path"
205
- cp "$source_path/$patchset_file" "$destination"
206
- fi
207
- done ; unset destination destination_path source_path patchset_file
208
-
207
+ if [[ -d patchsets/ ]] ; then
208
+ mkdir -p "$rvm_patchsets_path"
209
+ for patchset_file in $(cd patchsets ; find . -iname '*' | sed 's/^\.\///') ; do
210
+ destination="$rvm_patchsets_path/$patchset_file"
211
+ destination_path="$(dirname "$destination")"
212
+ if [[ ! -s "$destination" ]] ; then
213
+ mkdir -p "$destination_path"
214
+ cp "patchsets/$patchset_file" "$destination"
215
+ fi
216
+ done ; unset destination destination_path patchset_file
217
+ fi
209
218
 
210
219
  #
211
220
  # Migrate ~/.rvm/ruby-X,jruby-X,... to ~/.rvm/rubies/ for 0.1.0.
@@ -276,7 +285,7 @@ fi
276
285
 
277
286
  printf "\n Correct permissions for base binaries in $rvm_bin_path..."
278
287
  mkdir -p $rvm_bin_path
279
- for file in rvm rvmsudo rvm-shell ; do
288
+ for file in rvm rvmsudo rvm-shell rvm-auto-ruby; do
280
289
  [[ -s "$rvm_bin_path/$file" ]] && chmod +x "$rvm_bin_path/$file"
281
290
  done; unset file
282
291
  printf "\n Copying manpages into place."
@@ -285,9 +294,7 @@ for man_file in $(\ls "$install_source_path/man"); do
285
294
  cp -R "$install_source_path/man/$man_file" "$rvm_man_path/"
286
295
  done
287
296
 
288
- if [[ "$upgrade_flag" -eq 0 ]] ; then
289
- ./scripts/notes
290
- fi
297
+ [[ "$upgrade_flag" = 0 ]] && ./scripts/notes
291
298
 
292
299
  name="$(awk -F= '/^[[:space:]]*name/{print $2}' ~/.gitconfig 2>/dev/null)"
293
300
  printf "\n\n${name:-"$(whoami)"},\n"
@@ -4,9 +4,10 @@
4
4
  __rvm_select() {
5
5
  if [[ -z "$rvm_ruby_string" ]] ; then
6
6
  rvm_ruby_string="${rvm_ruby_interpreter}"
7
- if [[ ! -z "$rvm_ruby_version" ]] ; then rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_version" ; fi
8
- if [[ ! -z "$rvm_ruby_patch_level" ]] ; then rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_patch_level" ; fi
9
- if [[ ! -z "$rvm_ruby_revision" ]] ; then rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_revision" ; fi
7
+ if [[ -n "$rvm_ruby_version" ]] ; then rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_version" ; fi
8
+ if [[ -n "$rvm_ruby_patch_level" ]] ; then rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_patch_level" ; fi
9
+ if [[ -n "$rvm_ruby_revision" ]] ; then rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_revision" ; fi
10
+ if [[ -n "$rvm_ruby_name" ]]; then rvm_ruby_name="$rvm_ruby_string-n$rvm_ruby_name"; fi
10
11
  fi
11
12
 
12
13
  __rvm_ruby_string
@@ -22,10 +23,8 @@ __rvm_select() {
22
23
  rvm_ruby_revision="head"
23
24
  __rvm_db "macruby_repo_url" "rvm_ruby_repo_url"
24
25
  rvm_url="$rvm_ruby_repo_url"
25
- rvm_ruby_string="${rvm_ruby_interpreter}-head"
26
26
  elif [[ "nightly" = "$rvm_ruby_version" ]] ; then
27
27
  __rvm_db "macruby_nightly_url" "rvm_url"
28
- rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}"
29
28
  rvm_ruby_package_name="${rvm_ruby_interpreter}_nightly-${rvm_ruby_version}"
30
29
  rvm_ruby_package_file="$rvm_ruby_package_name"
31
30
  else
@@ -56,7 +55,6 @@ __rvm_select() {
56
55
  rvm_url="$rvm_url/$rvm_ruby_package_file"
57
56
  else
58
57
  unset rvm_ruby_patch_level rvm_ruby_version
59
- rvm_ruby_string="$rvm_ruby_interpreter-head"
60
58
  fi
61
59
  ;;
62
60
 
@@ -64,7 +62,6 @@ __rvm_select() {
64
62
  unset rvm_ruby_patch_level
65
63
  if [[ ! -z "$rvm_head_flag" ]] ; then
66
64
  rvm_ruby_version="head"
67
- rvm_ruby_string="jruby-head"
68
65
  rvm_ruby_repo_url="${rvm_ruby_repo_url:-$(__rvm_db "jruby_repo_url")}"
69
66
  rvm_url="${rvm_ruby_repo_url:-$(__rvm_db "jruby_repo_url")}"
70
67
  else
@@ -73,7 +70,6 @@ __rvm_select() {
73
70
  jruby_url="$(__rvm_db "jruby_url")"
74
71
  rvm_ruby_package_file="${rvm_ruby_interpreter}-bin-${rvm_ruby_version}"
75
72
  rvm_ruby_package_name="${rvm_ruby_interpreter}-${rvm_ruby_version}"
76
- rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}"
77
73
  rvm_url="${jruby_url}/${rvm_ruby_version}/${rvm_ruby_package_file}.tar.gz"
78
74
  unset jruby_url
79
75
  fi
@@ -86,7 +82,6 @@ __rvm_select() {
86
82
  maglev_url="$(__rvm_db "maglev_url")"
87
83
  if [[ ! -z "$rvm_head_flag" ]] ; then
88
84
  rvm_ruby_version="head"
89
- rvm_ruby_string="maglev-head"
90
85
  rvm_ruby_repo_url="${rvm_ruby_repo_url:-$(__rvm_db "maglev_repo_url")}"
91
86
  rvm_url="${rvm_ruby_repo_url:-$(__rvm_db "maglev_repo_url")}"
92
87
  else
@@ -96,7 +91,6 @@ __rvm_select() {
96
91
  rvm_gemstone_package_file="GemStone-${rvm_ruby_version}.${system}-${arch}"
97
92
  rvm_ruby_version="${rvm_ruby_version:-"$(__rvm_db "maglev_version")"}"
98
93
  rvm_ruby_package_name="${rvm_ruby_interpreter}-${rvm_ruby_version}"
99
- rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}"
100
94
  rvm_url="${rvm_ruby_url:-"$maglev_url/${rvm_ruby_package_file}.${rvm_archive_extension}"}"
101
95
  rvm_gemstone_url="${rvm_gemstone_url:-"$maglev_url/${rvm_gemstone_package_file}.${rvm_archive_extension}"}"
102
96
  export MAGLEV_HOME="$rvm_rubies_path/$rvm_ruby_string"
@@ -107,14 +101,12 @@ __rvm_select() {
107
101
  unset rvm_ruby_patch_level
108
102
  if [[ "$rvm_head_flag" -eq 1 ]] ; then
109
103
  rvm_ruby_version="head"
110
- rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}"
111
104
  rvm_ruby_package_name="${rvm_ruby_string}"
112
105
  rvm_ruby_repo_url="${rvm_ruby_repo_url:-$(__rvm_db "ironruby_repo_url")}"
113
106
  rvm_url="${rvm_ruby_repo_url:-$(__rvm_db "ironruby_repo_url")}"
114
107
  else
115
108
  rvm_archive_extension="zip"
116
109
  rvm_ruby_version=${rvm_ruby_version:-"$(__rvm_db "ironruby_version")"}
117
- rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}"
118
110
  rvm_ruby_package_name="${rvm_ruby_interpreter}-${rvm_ruby_version}"
119
111
  rvm_ruby_package_file="${rvm_ruby_interpreter}-${rvm_ruby_version}.${rvm_archive_extension}"
120
112
  rvm_url="$(__rvm_db "ironruby_${rvm_ruby_version}_url")${rvm_ruby_package_file}"
@@ -127,9 +119,6 @@ __rvm_select() {
127
119
  rvm_ruby_version=${rvm_ruby_version:-"$(__rvm_db "ree_version")"}
128
120
  if [[ ! -z "$rvm_ruby_patch_level" ]] ; then
129
121
  rvm_ruby_patch_level="$(echo $rvm_ruby_patch_level | sed 's#^p##')"
130
- rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}-${rvm_ruby_patch_level}"
131
- elif [[ "$rvm_head_flag" = 1 ]] ; then
132
- rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}-head"
133
122
  fi
134
123
 
135
124
  if [[ "$rvm_ruby_version" != "head" ]] ; then
@@ -150,7 +139,7 @@ __rvm_select() {
150
139
  mput|shyouhei)
151
140
  rvm_ruby_interpreter="mput"
152
141
  rvm_ruby_version="head"
153
- rvm_ruby_string="mput-head"
142
+ rvm_ruby_string=$(echo $rvm_ruby_string | sed -e 's/shyouhei/mput/g')
154
143
  unset rvm_ruby_patch_level
155
144
  rvm_ruby_repo_url=${rvm_mput_repo_url:-"$(__rvm_db "shyouhei_repo_url")"}
156
145
  rvm_url=$rvm_ruby_repo_url
@@ -199,7 +188,7 @@ __rvm_select() {
199
188
  rvm_minor_version=$(echo $rvm_ruby_version | awk -F'.' '{ print $3 }')
200
189
  fi
201
190
 
202
- rvm_ruby_package_name="${rvm_ruby_package_name:-$rvm_ruby_string}"
191
+ rvm_ruby_package_name="${rvm_ruby_package_name:-$(echo $rvm_ruby_string | sed -e 's/-n.*$//')}"
203
192
  rvm_ruby_home="$rvm_rubies_path/$rvm_ruby_string"
204
193
  rvm_ruby_log_path="$rvm_log_path/$rvm_ruby_string"
205
194
  rvm_ruby_repo_path="$rvm_repo_path/$rvm_ruby_string"
@@ -221,13 +210,12 @@ __rvm_select() {
221
210
 
222
211
  rvm_ruby_selected_flag=1
223
212
 
224
- mkdir -p $rvm_ruby_log_path
213
+ mkdir -p "$rvm_ruby_log_path"
225
214
 
226
215
  export rvm_ruby_interpreter rvm_ruby_version rvm_ruby_repo_url rvm_ruby_package_name rvm_url rvm_ruby_patch_level rvm_ruby_configure rvm_ruby_configure_flags rvm_ruby_make rvm_ruby_make_install rvm_ruby_revision rvm_ruby_tag rvm_release_version rvm_major_version rvm_minor_version rvm_gemset_name rvm_gems_path rvm_ruby_gem_home rvm_path rvm_src_path rvm_bin_path rvm_ruby_binary rvm_ruby_home rvm_log_path rvm_ruby_log_path rvm_src_path rvm_ruby_src_path rvm_ruby_irbrc rvm_ruby_selected_flag rvm_ruby_string
227
216
  else
228
217
  rvm_ruby_interpreter="${rvm_ruby_interpreter:-system}"
229
218
  fi
230
-
231
219
  }
232
220
 
233
221
  __rvm_use() {
@@ -237,21 +225,23 @@ __rvm_use() {
237
225
  if [[ "system" = "$rvm_ruby_interpreter" ]] ; then
238
226
 
239
227
  unset GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME RUBY_VERSION IRBRC
240
- new_path="$(echo $PATH | tr ':' '\n' | awk '$0 !~ /rvm/' | paste -sd : -)"
228
+ new_path="$(echo $PATH | \tr ':' '\n' | awk '$0 !~ /rvm/' | paste -sd : -)"
241
229
  new_path="$rvm_bin_path:$new_path"
242
230
  if [[ -s $rvm_config_path/system ]] ; then
243
231
  grep "MY_RUBY_HOME='$rvm_rubies_path" "$rvm_config_path/system" > /dev/null
244
232
  if [[ $? -eq 0 ]] ; then
245
- rm -f $rvm_config_path/system # 'system' should *not* point to an rvm ruby.
233
+ [[ -f "$rvm_config_path/system" ]] && rm -f $rvm_config_path/system # 'system' should *not* point to an rvm ruby.
246
234
  else
247
- source $rvm_config_path/system
235
+ source "$rvm_config_path/system"
248
236
  fi
249
237
  fi
250
238
 
251
- if [[ "root" = "$(whoami)" ]] ; then
239
+ # Check binaries, remove under the condition they're symlinks.
240
+ if [[ "$rvm_sandboxed" = "0" ]] ; then
252
241
  for binary in ruby gem irb ri rdoc rake erb testrb ; do
253
- rm -f "$rvm_bin_path/$binary"
254
- done
242
+ full_binary_path="$rvm_bin_path/$binary"
243
+ [[ -L "$full_binary_path" ]] && rm -f "$full_binary_path"
244
+ done; unset binary full_binary_path
255
245
  fi
256
246
 
257
247
  if [[ ! -z "$rvm_verbose_flag" ]] ; then
@@ -286,10 +276,10 @@ __rvm_use() {
286
276
  __rvm_ensure_has_enviroment_files
287
277
 
288
278
  if [[ ! -z "$rvm_verbose_flag" ]] ; then
289
- $rvm_scripts_path/log "info" "Using $(basename $GEM_HOME | tr '-' ' ' | sed 's/'${rvm_gemset_separator}'/ with gemset /')"
279
+ $rvm_scripts_path/log "info" "Using $(basename $GEM_HOME | \tr '-' ' ' | sed 's/'${rvm_gemset_separator}'/ with gemset /')"
290
280
  fi
291
281
 
292
- new_path="$(echo $PATH | tr ':' '\n' | awk '$0 !~ /rvm/' | paste -sd : -)"
282
+ new_path="$(echo $PATH | \tr ':' '\n' | awk '$0 !~ /rvm/' | paste -sd : -)"
293
283
  new_path="$GEM_HOME/bin:$rvm_ruby_global_gems_path/bin:$MY_RUBY_HOME/bin:$rvm_bin_path:$new_path"
294
284
  fi
295
285
 
@@ -302,16 +292,16 @@ __rvm_use() {
302
292
  environment_id="$(__rvm_environment_identifier)"
303
293
 
304
294
  if [[ ! -z "$rvm_default_flag" ]] && [[ "default" != "$rvm_ruby_interpreter" ]] ; then
305
- if [[ "root" = "$(whoami)" ]] ; then
295
+ if [[ "$rvm_sandboxed" = "0" ]] ; then
306
296
  # Sets up the default wrappers.
307
297
  $rvm_scripts_path/wrapper "$rvm_ruby_string"
308
298
  fi
309
299
  if [[ "system" = "$rvm_ruby_interpreter" ]] ; then
310
300
  $rvm_scripts_path/alias delete default &> /dev/null
311
- rm -f $rvm_config_path/default
312
301
  rm -f $rvm_bin_path/default*
313
- rm -f $rvm_environments_path/default
314
- rm -f $rvm_wrappers_path/default
302
+ [[ -f $rvm_config_path/default ]] && rm -f $rvm_config_path/default
303
+ [[ -f $rvm_environments_path/default ]] && rm -f $rvm_environments_path/default
304
+ [[ -f $rvm_wrappers_path/default ]] && rm -f $rvm_wrappers_path/default
315
305
  else
316
306
  RUBY_VERSION="$($rvm_ruby_home/bin/ruby -v | sed 's#^\(.*\) (.*$#\1#')"
317
307
  export GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME RUBY_VERSION
@@ -362,13 +352,17 @@ __rvm_ruby_string() {
362
352
  fi
363
353
  fi
364
354
 
355
+ # Preparation for alias tags
356
+ rvm_ruby_alias=$(echo "$rvm_ruby_string" | awk -F+ '{print $2}')
357
+ rvm_ruby_string=$(echo "$rvm_ruby_string" | awk -F+ '{print $1}')
358
+
365
359
  set_name=$(echo "$rvm_ruby_string" | awk -F${rvm_gemset_separator} '{print $2}')
366
360
  if [[ ! -z "$set_name" ]] ; then rvm_gemset_name="$set_name" ; fi
367
361
  ruby_string=$(echo "$rvm_ruby_string" | awk -F${rvm_gemset_separator} '{print $1}')
368
362
 
369
363
  __rvm_unset_ruby_variables
370
364
 
371
- for string in $(echo $ruby_string | tr '-' ' ') ; do
365
+ for string in $(echo $ruby_string | \tr '-' ' ') ; do
372
366
  if [[ "head" = "$string" ]] ; then
373
367
  rvm_ruby_revision="head"
374
368
  unset rvm_ruby_patch_level rvm_ruby_revision rvm_ruby_tag
@@ -390,7 +384,7 @@ __rvm_ruby_string() {
390
384
  unset rvm_ruby_revision rvm_ruby_tag
391
385
  elif $rvm_scripts_path/match "$string" "^p[0-9]" ; then
392
386
  rvm_ruby_patch_level="$string"
393
- elif $rvm_scripts_path/match "$string" "^[0-9][0-9]" ; then
387
+ elif [[ -n "$rvm_ruby_version" ]] && $rvm_scripts_path/match "$string" "^[0-9][0-9]" ; then
394
388
  if [[ "ree" = "$rvm_ruby_interpreter" ]] ; then
395
389
  rvm_ruby_patch_level="$string"
396
390
  unset rvm_ruby_revision
@@ -418,6 +412,8 @@ __rvm_ruby_string() {
418
412
  rvm_ruby_user_tag="$string"
419
413
  elif $rvm_scripts_path/match "$string" "^b[0-9][0-9]" ; then
420
414
  rvm_ruby_bits="$string"
415
+ elif $rvm_scripts_path/match "$string" "^n" ; then
416
+ rvm_ruby_name="${string/n/}"
421
417
  elif $rvm_scripts_path/match "ruby rbx jruby macruby ree rubinius maglev mput shyouhei ironruby " "$string " ; then
422
418
  # NOTE: The space at the end of each of the above strings is *very* important.
423
419
  rvm_ruby_interpreter="$string"
@@ -480,5 +476,136 @@ __rvm_ruby_string() {
480
476
  fi
481
477
  fi
482
478
  fi
479
+
480
+ if [[ -n "${rvm_ruby_name}" ]] ; then
481
+ rvm_ruby_string="${rvm_ruby_string}-n${rvm_ruby_name}"
482
+ fi
483
+ }
484
+
485
+ # Select a gemset based on CLI set options and environment.
486
+ # This only sets 'rvm_ruby_gem_home'
487
+ __rvm_gemset_select() {
488
+ command -v gem > /dev/null
489
+ if [[ $? -gt 0 ]] ; then return 0 ; fi # Stop if no 'gem' command is available.
490
+
491
+ rvm_ruby_global_gems_path="$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}global"
492
+
493
+ #if [[ -z "$(echo $rvm_ruby_gem_home | grep "$rvm_path")" ]] ; then
494
+ # $rvm_scripts_path/log "warn" "Gemsets cannot be used with system ruby installs (yet)."
495
+ #fi
496
+
497
+ if [[ -z "$rvm_gemset_name" ]] ; then
498
+ # No longer defaulting to 'sticky' gem sets.
499
+ # Set 'rvm_sticky_flag=1' in ~/.rvmrc to enable.
500
+ if [[ -n "$rvm_sticky_flag" ]] ; then
501
+ if [[ -n "$GEM_HOME" ]] ; then
502
+ rvm_gemset_name=$(echo $GEM_HOME | xargs basename | awk -F${rvm_gemset_separator} '{print $2}')
503
+ fi
504
+ if [[ -n "$rvm_ruby_gem_home" ]] ; then
505
+ rvm_gemset_name=$(echo $rvm_ruby_gem_home | xargs basename | awk -F${rvm_gemset_separator} '{print $2}')
506
+ fi
507
+ fi
508
+
509
+ if [[ -n "$rvm_gemset_name" ]] && ! $rvm_scripts_path/match "$rvm_gemset_name" "^[0-9]\.[0-9]" ; then
510
+ rvm_ruby_gem_home="$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}${rvm_gemset_name}"
511
+ else
512
+ if [[ -n "$rvm_ruby_string" ]] && [[ "$rvm_ruby_interpreter" != "system" ]] ; then
513
+ rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string"
514
+ elif [[ -z "$GEM_HOME" ]] && [[ -n "$(command -v gem)" ]] ; then
515
+ rvm_ruby_gem_home=$(gem env gemdir)
516
+ elif [[ -n "$GEM_HOME" ]] ; then
517
+ rvm_ruby_gem_home="$GEM_HOME"
518
+ else
519
+ unset rvm_ruby_gem_home
520
+ fi
521
+ fi
522
+ if [[ -z "$rvm_gemset_name" ]] ; then unset rvm_gemset_name ; fi
523
+ else
524
+ gemset=$(echo "$rvm_ruby_gem_home" | awk -F'@' '{print $NF}')
525
+ if [[ -z "$rvm_ruby_string" ]] && [[ -n "${GEM_HOME/@*/}" ]] ; then
526
+ rvm_ruby_string=$(basename ${GEM_HOME/@*/})
527
+ fi
528
+
529
+ if [[ -n "$rvm_ruby_string" ]] ; then
530
+ if [[ -z "$rvm_ruby_gem_home" ]] || [[ -n "$gemset" ]] ; then
531
+ rvm_ruby_gem_home="$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}${rvm_gemset_name}"
532
+ elif [[ -n "$gemset" ]] && [[ "$rvm_gemset_name" != "$gemset" ]] ; then
533
+ rvm_ruby_gem_home="$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}${rvm_gemset_name}"
534
+ fi ; unset gemset
535
+ else
536
+ $rvm_scripts_path/log "error" "Gemsets can not be used with non rvm controlled rubies (currently)."
537
+ return 1
538
+ fi
539
+ fi
540
+
541
+ # If the gemset does not exist, then notify the user as such and abort the action.
542
+ if [[ -n "$rvm_gemset_name" ]] && [[ ! -d "$rvm_ruby_gem_home" ]] ; then
543
+ if [[ "$rvm_gemset_create_on_use_flag" -ne 1 ]] && [[ "$rvm_create_flag" -ne 1 ]] && [[ "$rvm_delete_flag" -ne 1 ]] ; then
544
+ $rvm_scripts_path/log "error" "Gemset '$rvm_gemset_name' does not exist, rvm gemset create '$rvm_gemset_name' first."
545
+ return 1
546
+ fi
547
+ elif [[ "$rvm_delete_flag" -eq 1 ]] ; then
548
+ return 1
549
+ fi
550
+
551
+ if [[ -z "$rvm_ruby_gem_home" ]] && [[ -n $rvm_ruby_string ]] ; then
552
+ rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string"
553
+ rvm_ruby_global_gems_path="$rvm_gems_path/$rvm_ruby_string${rvm_gemset_separator}global"
554
+ fi
555
+
556
+ rvm_ruby_gem_path="$rvm_ruby_gem_home:$rvm_ruby_global_gems_path"
557
+
558
+ # Ensure that the ruby gem home exists.
559
+ mkdir -p "$rvm_ruby_gem_home"
560
+ if [[ -n "$rvm_ruby_gem_home" ]] && echo "$rvm_ruby_gem_home" | grep -q 'rvm'; then
561
+ if __rvm_using_gemset_globalcache && [[ ! -L "$rvm_ruby_gem_home/cache" ]]; then
562
+ mv "$rvm_ruby_gem_home/cache/"*.gem "$rvm_gems_cache_path/" 2>/dev/null
563
+ rm -rf "$rvm_ruby_gem_home/cache"
564
+ ln -nfs "$rvm_gems_cache_path" "$rvm_ruby_gem_home/cache"
565
+ fi
566
+ fi
567
+
568
+ export rvm_ruby_gem_path rvm_ruby_gem_home
569
+ }
570
+
571
+ # Use a gemset specified by 'rvm_ruby_gem_home'
572
+ __rvm_gemset_use() {
573
+ #if [[ -z "$(echo $rvm_ruby_gem_home | grep "rvm")" ]] ; then
574
+ # $rvm_scripts_path/log "warn" "Gemsets cannot be used with system ruby installs (yet)."
575
+ #fi
576
+ if [[ -n "$rvm_ruby_gem_home" ]] ; then
577
+ if [[ ! -d "$rvm_ruby_gem_home" ]] ; then
578
+ if [[ "$rvm_gemset_create_on_use_flag" -eq 1 ]] || [[ "$rvm_create_flag" -eq 1 ]]; then
579
+ $rvm_scripts_path/gemsets create $rvm_gemset_name
580
+ else
581
+ $rvm_scripts_path/log "error" "Gemset '$rvm_gemset_name' does not exist, rvm gemset create '$rvm_gemset_name' first."
582
+ return 1
583
+ fi
584
+ fi
585
+
586
+ if [[ "$rvm_interactive" -eq 1 ]] || [[ "$rvm_verbose_flag" -eq 1 ]] ; then
587
+ $rvm_scripts_path/log "info" "Now using gemset '${rvm_gemset_name:-default}'"
588
+ fi
589
+
590
+ rvm_ruby_gem_home="$(echo $GEM_HOME | sed 's/'${rvm_gemset_separator}'.*$//')${rvm_gemset_separator}${rvm_gemset_name}"
591
+ GEM_HOME="$rvm_ruby_gem_home"
592
+ BUNDLE_PATH="$rvm_ruby_gem_home"
593
+ GEM_PATH="$rvm_ruby_gem_home/bin:$(echo $GEM_HOME | sed 's/'${rvm_gemset_separator}'.*$//')${rvm_gemset_separator}global/bin"
594
+ export rvm_ruby_gem_home GEM_HOME BUNDLE_PATH GEM_PATH
595
+
596
+ __rvm_use # Now ensure the selection takes effect for the environment.
597
+ fi
598
+ return 0
599
+ }
600
+
601
+ __rvm_gemset_clear() {
602
+ unset rvm_gemset_name ; shift
603
+ rvm_ruby_gem_home="$(echo $GEM_HOME | sed "s#${rvm_gemset_separator:-'@'}.*\$##g")"
604
+ rvm_ruby_global_gems_path="$(echo $GEM_HOME | sed 's/'${rvm_gemset_separator}'.*$//')${rvm_gemset_separator}global"
605
+ GEM_HOME=$rvm_ruby_gem_home
606
+ BUNDLE_PATH="$rvm_ruby_gem_home"
607
+ GEM_PATH="$rvm_ruby_gem_home/bin:$rvm_ruby_global_gems_path/bin"
608
+ export rvm_ruby_gem_home rvm_ruby_global_gems_path GEM_HOME BUNDLE_PATH GEM_PATH
609
+ __rvm_use # Now ensure the selection takes effect for the environment.
483
610
  }
484
611