-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
rubygems
executable file
·157 lines (103 loc) · 4.4 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
#!/usr/bin/env bash
source "$rvm_path/scripts/base"
result=0
__rvm_become
rubygems_setup()
{
__rvm_warn_on_rubyopt
unset RUBYOPT
if [[ ! -z "$(echo "$rvm_ruby_version" | awk '/^1\.9/')" ]] || [[ ! -z "$(echo $rvm_ruby_interpreter | awk '/^mput/')" ]] ; then
install=0
elif [[ "$rvm_ruby_string" = "ruby-head" ]] ; then
install=0
elif [[ -n "$(echo "$rvm_ruby_string" | awk '/^rbx|jruby|rubinius/')" ]]; then
install=0
else
install=1
fi
if [[ "$install" -eq 0 ]] ; then
"$rvm_path/scripts/log" "error" \
"Cannot switch to ${version} for this interpreter."
exit 1
else
"$rvm_path/scripts/log" "info" \
"Removing old Rubygems files..."
rubygems_dir="$(ruby -rrbconfig -e "puts Config::CONFIG.values_at('sitelibdir','vendorlibdir').detect {|path| File.directory?(File.join(path, 'rubygems')) }.to_s")"
if [[ -n "$rubygems_dir" && -d "$rubygems_dir" ]]; then
# Remove common files installed by ruby gems.
\rm -rf "${rubygems_dir}/ubygems.rb" "${rubygems_dir}/rubygems.rb" \
"${rubygems_dir}/rubygems" "${rubygems_dir}/gauntlet_rubygems.rb"
fi
"$rvm_path/scripts/log" "info" "Installing rubygems dedicated to $rvm_ruby_string..."
rvm_rubygems_version="$version"
rvm_gem_package_name="rubygems-$rvm_rubygems_version"
rvm_rubygems_url=$(__rvm_db "rubygems_${rvm_rubygems_version}_url")
rvm_gem_url="$rvm_rubygems_url/$rvm_gem_package_name.tgz"
# Sanity check... If setup.rb is missing from the rubygems source path,
# something went wrong. Cleanup, aisle 3!
if [[ ! -f "${rvm_src_path:-"$rvm_path/src"}/$rvm_gem_package_name/setup.rb" ]]; then
\rm -rf "${rvm_src_path:-"$rvm_path/src"}/$rvm_gem_package_name"
fi
if [[ ! -d "${rvm_src_path:-"$rvm_path/src"}/$rvm_gem_package_name" ]] ; then
"$rvm_path/scripts/log" "info" \
"Retrieving $rvm_gem_package_name"
"$rvm_path/scripts/fetch" "$rvm_gem_url" ; result=$?
if [[ "$result" -gt 0 ]] ; then
"$rvm_path/scripts/log" "error" \
"There has been an error while trying to fetch the source. Aborting the installation."
return $result
fi
if [[ ! -d "${rvm_src_path:-"$rvm_path/src"}/$rvm_gem_package_name" ]] ; then
\mkdir -p "${rvm_src_path:-"$rvm_path/src"}/$rvm_gem_package_name"
fi
__rvm_run "rubygems.extract" \
"gunzip < ${rvm_archives_path:-"$rvm_path/archives"}/$rvm_gem_package_name.tgz | tar xf - -C ${rvm_src_path:-"$rvm_path/src"}" \
"Extracting $rvm_gem_package_name ..."
fi
builtin cd "${rvm_src_path:-"$rvm_path/src"}/$rvm_gem_package_name"
__rvm_run "rubygems.install" \
"GEM_PATH=\"$rvm_ruby_gem_path:$rvm_ruby_global_gems_path\" GEM_HOME=\"$rvm_ruby_gem_home\" BUNDLE_PATH=\"$rvm_ruby_gem_home $rvm_ruby_home/bin/ruby\" \"${rvm_src_path:-"$rvm_path/src"}/$rvm_gem_package_name/setup.rb\"" \
"Installing rubygems for $rvm_ruby_home/bin/ruby"
result=$?
if [[ "$result" == 0 ]] ; then
"$rvm_path/scripts/log" "info" \
"Installation of rubygems completed successfully."
else
"$rvm_path/scripts/log" "warning" \
"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
fi
# Add ruby's gem path to ruby's lib direcotry.
\mkdir -p "$(dirname $ruby_lib_gem_path)"
if [[ -d "$ruby_lib_gem_path" ]] ; then \rm -rf "$ruby_lib_gem_path" ; fi
ln -nfs "$rvm_ruby_gem_home" "$ruby_lib_gem_path"
unset ruby_lib_gem_path
}
if ! command -v ruby > /dev/null ; then
"$rvm_path/scripts/log" "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 use X
#
args=($*)
version="${args[0]}"
args="$(echo ${args[@]:1}) " # Strip trailing / leading / extra spacing.
if [[ -z "$version" ]] ; then
"$rvm_path/scripts/log" "error" \
"A version must be specified, for example 'rvm rubygems 1.3.7'"
exit 1
fi
# Update the rubygems to the current.
if [[ "$version" = "current" ]]; then
version="$(__rvm_db "${rvm_ruby_interpreter}_rubygems_version")"
version="${rvm_rubygems_version:-"$(__rvm_db "rubygems_version")"}"
fi
rubygems_setup
exit $result