-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
rubygems
executable file
·239 lines (201 loc) · 6.12 KB
/
rubygems
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
#!/usr/bin/env bash
source "$rvm_scripts_path/base"
source "$rvm_scripts_path/functions/db"
result=0
__rvm_become
rubygems_remove()
{
typeset rubygems_path ruby entry
rvm_log "Removing old Rubygems files..."
if [[ "$rvm_ruby_interpreter" == "rbx" ]]
then
ruby="puts Config::CONFIG['prefix']"
elif [[ "$rvm_ruby_string" =~ ruby-1.9.3.* ]]
then
ruby="puts RbConfig::CONFIG.values_at('sitelibdir','vendorlibdir').detect { |path| File.directory?(File.join(path.to_s, 'rubygems')) }.to_s"
else
ruby="puts Config::CONFIG.values_at('sitelibdir','vendorlibdir').detect { |path| File.directory?(File.join(path.to_s, 'rubygems')) }.to_s"
fi
rubygems_path="$(ruby -rrbconfig -e "$ruby")"
# Remove common files installed by ruby gems.
entries=(
"${rubygems_path}/ubygems.rb"
"${rubygems_path}/gauntlet_rubygems.rb"
"${rubygems_path}/rbconfig/"
)
for entry in "${entries[@]}" "${rubygems_path}/rubygems"*
do
__rvm_rm_rf "$entry"
done
}
can_switch_rubygems()
{
case "$rvm_ruby_string" in
jruby*|maglev*)
return 1
;;
*)
return 0
;;
esac
}
rubygems_version_list()
{
curl -s https://api.github.com/repos/rubygems/rubygems/tags |
sed -n '/"name": / {s/^.*".*": "v\(.*\)".*$/\1/; p;}' |
sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n
}
rubygems_master_sha()
{
curl -s "https://api.github.com/repos/rubygems/rubygems/commits?page=last&per_page=1" | sed -n '/^ "sha":/ {s/^.*".*": "\(.*\)".*$/\1/;p;}'
}
rubygems_select_version_url()
{
case "$version" in
latest|current)
case "$rvm_ruby_string" in
ruby-1.8*|ree-1.8*)
typeset _rbv
_rbv=${rvm_ruby_version##*.}
if (( _rbv <= 5 ))
then
version=1.3.5
elif (( _rbv == 6 ))
then
version=1.3.7
fi
;;
esac
;;
esac
case "$version" in
latest|current)
version="$(__rvm_db "${rvm_ruby_string//-/_}_rubygems_version")"
version="${version:-"$(__rvm_db "${rvm_ruby_interpreter}_rubygems_version")"}"
version="${version:-"$(__rvm_db "rubygems_version")"}"
;;
esac
case "$version" in
latest-*)
version="${version#latest-}"
version="$(rubygems_version_list | GREP_OPTIONS="" \grep "^${version}\." | tail -n 1 )"
version="${version}"
;;
esac
case "${version}" in
head|master)
typeset sha
sha="$(rubygems_master_sha)"
rvm_rubygems_version="$version"
rvm_gem_package_name="rubygems-rubygems-${sha:0:7}"
rvm_gem_url="https://github.com/rubygems/rubygems/tarball/${sha}"
;;
*)
rvm_rubygems_version="$version"
rvm_gem_package_name="rubygems-${rvm_rubygems_version}"
rvm_rubygems_url=$(__rvm_db "rubygems_url")
rvm_gem_url="${rvm_rubygems_url}/${rvm_gem_package_name}.tgz"
;;
esac
}
rubygems_setup()
{
__rvm_warn_on_rubyopt
true ${rvm_ruby_selected_flag:=0}
unset RUBYOPT
if (( rvm_ruby_selected_flag == 0 ))
then
__rvm_select
fi
rubygems_select_version_url
# Sanity check... If setup.rb is missing from the rubygems source path,
# something went wrong. Cleanup, aisle 3!
if [[ ! -f "${rvm_src_path}/$rvm_gem_package_name/setup.rb" ]]
then
__rvm_rm_rf "${rvm_src_path}/$rvm_gem_package_name"
fi
if [[ ! -d "${rvm_src_path}/${rvm_gem_package_name}" ]]
then
rvm_log "Retrieving $rvm_gem_package_name"
"$rvm_scripts_path/fetch" "$rvm_gem_url" "${rvm_gem_package_name}.tgz"
result=$?
if (( result > 0 ))
then
rvm_error "There has been an error while trying to fetch the source. \nHalting the installation."
return $result
fi
if [[ ! -d "${rvm_src_path}/$rvm_gem_package_name" ]]
then
\mkdir -p "${rvm_src_path}/$rvm_gem_package_name"
fi
__rvm_run "rubygems.extract" \
"gunzip < ${rvm_archives_path}/$rvm_gem_package_name.tgz | $rvm_tar_command xf - -C ${rvm_src_path}" \
"Extracting $rvm_gem_package_name ..."
fi
rubygems_remove # Remove old gems.
builtin cd "${rvm_src_path}/$rvm_gem_package_name"
__rvm_run "rubygems.install" \
"GEM_PATH=\"$GEM_PATH:${GEM_PATH%%@*}@global\" GEM_HOME=\"$GEM_HOME\" \"${rvm_ruby_binary}\" \"${rvm_src_path}/$rvm_gem_package_name/setup.rb\"" \
"Installing $rvm_gem_package_name for ${rvm_ruby_string} ..."
result=$?
if (( result == 0 ))
then
typeset program_suffix
program_suffix="$(${rvm_ruby_binary} -rrbconfig -e "puts RbConfig::CONFIG['configure_args']")"
case "${program_suffix:-}" in
(*--program-suffix=*)
program_suffix="${program_suffix#*--program-suffix=}"
program_suffix="${program_suffix%%[\' ]*}"
__rvm_run "link.gem" "ln -s \"$rvm_ruby_home/bin/gem${program_suffix}\" \
\"$rvm_ruby_home/bin/gem\"" "$rvm_ruby_string - #linking gem${program_suffix} -> gem "
;;
esac
rvm_log "Installation of rubygems completed successfully."
else
rvm_warn "Installation of rubygems did not complete successfully."
fi
if [[ ! -z "$rvm_ruby_major_version" ]]
then
ruby_lib_gem_path="$rvm_ruby_home/lib/ruby/gems/${rvm_ruby_release_version}.${rvm_ruby_major_version}"
else
ruby_lib_gem_path="$rvm_ruby_home/lib/ruby/gems/$interpreter"
fi
# Add ruby's gem path to ruby's lib direcotry.
\mkdir -p "$(dirname $ruby_lib_gem_path)"
__rvm_rm_rf "$ruby_lib_gem_path"
if [[ -d "$rvm_ruby_gem_home" ]]
then
ln -fs "$rvm_ruby_gem_home" "$ruby_lib_gem_path"
fi
unset ruby_lib_gem_path
}
if ! builtin command -v ruby > /dev/null
then
rvm_error "'ruby' was not found, cannot install rubygems unless ruby is present (Do you have an RVM ruby installed & selected?)"
exit 1
fi
#
# rvm rubygems X
#
args=($*)
export version
version="${args[0]}"
args="$(echo ${args[@]:1})" # Strip trailing / leading / extra spacing.
if [[ -z "$version" ]]
then
rvm_error "Usage: rvm rubygems [x.y.z|latest-x.y|latest|remove]"
exit 1
fi
if can_switch_rubygems
then
case "$version" in
remove) rubygems_remove
;;
*) rubygems_setup
;;
esac
else
rvm_error "Rubygems version may only be set for an RVM MRI based Ruby, please select one and rerun."
result=1
fi
exit $result