Skip to content

Commit c554a11

Browse files
committed
Adding back the ruby dependency in the installer
This reverts commit 74e87fd.
1 parent 74e87fd commit c554a11

File tree

1 file changed

+44
-33
lines changed

1 file changed

+44
-33
lines changed

bin/install

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,35 +76,48 @@ to check for a running agent.
7676
To use a HTTP proxy, specify --proxy followed by the proxy server
7777
defined by http://hostname:port
7878
79-
This install script needs Ruby version 2.0.x installed as a prerequisite.
80-
If you do not have Ruby version 2.0.x installed, please install it first.
79+
This install script needs Ruby version 2.x installed as a prerequisite.
80+
Currently recommanded Ruby versions are 2.0.0, 2.1.8, 2.2.4 and 2.3.0.
81+
If multiple Ruby versions are installed, the default ruby version will be used.
82+
If the default ruby version does not satisfy reqirement, the newest version will be used.
83+
If you do not have a supported Ruby version installed, please install one of them first.
8184
8285
EOF
8386
end
8487

85-
# check ruby version, only version 2.0.x works
88+
def supported_ruby_versions
89+
['2.3', '2.2', '2.1', '2.0']
90+
end
91+
92+
# check ruby version, only version 2.x works
8693
def check_ruby_version_and_symlink
8794
@log.info("Starting Ruby version check.")
88-
actual_ruby_version = RUBY_VERSION.split('.').map{|s|s.to_i}
89-
left_bound = '2.0.0'.split('.').map{|s|s.to_i}
90-
right_bound = '2.1.0'.split('.').map{|s|s.to_i}
91-
if !(File.exist?('/usr/bin/ruby2.0'))
92-
if (File.symlink?('/usr/bin/ruby2.0'))
93-
@log.error("The symlink /usr/bin/ruby2.0 already exists, but it's linked to a non-existent directory or executable file.")
94-
exit(1)
95+
actual_ruby_version = RUBY_VERSION.split('.').map{|s|s.to_i}[0,2]
96+
97+
supported_ruby_versions.each do |version|
98+
if ((actual_ruby_version <=> version.split('.').map{|s|s.to_i}) == 0)
99+
return File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["RUBY_INSTALL_NAME"] + RbConfig::CONFIG["EXEEXT"])
100+
end
101+
end
95102

96-
# The spaceship operator is a rarely used Ruby feature - particularly how it interacts with arrays.
97-
# Not all languages that have it handle that case the same way.
98-
elsif ((actual_ruby_version <=> left_bound) < 0 || (actual_ruby_version <=> right_bound) >= 0)
99-
@log.error("Current running Ruby version for "+ENV['USER']+" is "+RUBY_VERSION+", but Ruby version 2.0.x needs to be installed.")
100-
@log.error('If you have Ruby version 2.0.x installed for other users, please create a symlink to /usr/bin/ruby2.0.')
101-
@log.error("Otherwise please install Ruby 2.0.x for "+ENV['USER']+" user.")
102-
exit(1)
103-
else
104-
ruby_interpreter_path = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["RUBY_INSTALL_NAME"] + RbConfig::CONFIG["EXEEXT"])
105-
File.symlink(ruby_interpreter_path, '/usr/bin/ruby2.0')
103+
supported_ruby_versions.each do |version|
104+
if(File.exist?("/usr/bin/ruby#{version}"))
105+
return "/usr/bin/ruby#{version}"
106+
elsif (File.symlink?("/usr/bin/ruby#{version}"))
107+
@log.error("The symlink /usr/bin/ruby#{version} exists, but it's linked to a non-existent directory or non-executable file.")
108+
exit(1)
106109
end
107110
end
111+
112+
unsupported_ruby_version_error
113+
exit(1)
114+
end
115+
116+
def unsupported_ruby_version_error
117+
@log.error("Current running Ruby version for "+ENV['USER']+" is "+RUBY_VERSION+", but Ruby version 2.x needs to be installed.")
118+
@log.error('If you already have the proper Ruby version installed, please either create a symlink to /usr/bin/ruby2.x,')
119+
@log.error( "or run this install script with right interpreter. Otherwise please install Ruby 2.x for "+ENV['USER']+" user.")
120+
@log.error('You can get more information by running the script with --help option.')
108121
end
109122

110123
def parse_args()
@@ -146,23 +159,21 @@ EOF
146159
@type = ARGV.shift.downcase;
147160
end
148161

149-
def force_ruby20()
150-
# change interpreter when symlink /usr/bin/ruby2.0 exists, but running with lower ruby version
162+
def force_ruby2x(ruby_interpreter_path)
163+
# change interpreter when symlink /usr/bin/ruby2.x exists, but running with non-supported ruby version
151164
actual_ruby_version = RUBY_VERSION.split('.').map{|s|s.to_i}
152165
left_bound = '2.0.0'.split('.').map{|s|s.to_i}
153-
right_bound = '2.1.0'.split('.').map{|s|s.to_i}
166+
right_bound = '2.3.1'.split('.').map{|s|s.to_i}
154167
if (actual_ruby_version <=> left_bound) < 0
155168
if(!@reexeced)
156-
@log.info("The current Ruby version is not 2.0.x! Restarting the installer with /usr/bin/ruby2.0")
157-
exec('/usr/bin/ruby2.0', __FILE__, '--re-execed' , *@args)
169+
@log.info("The current Ruby version is not 2.x! Restarting the installer with #{ruby_interpreter_path}")
170+
exec("#{ruby_interpreter_path}", __FILE__, '--re-execed' , *@args)
158171
else
159-
@log.error('The Ruby version in /usr/bin/ruby2.0 is '+RUBY_VERSION+', but this must be Ruby version 2.0.x. Installation cannot continue.')
160-
@log.error('If you have Ruby version 2.0.x installed, please correct the symlink. Otherwise, please install Ruby 2.0')
172+
unsupported_ruby_version_error
161173
exit(1)
162174
end
163-
elsif (actual_ruby_version <=> right_bound) >= 0
164-
@log.warn('The Ruby version in /usr/bin/ruby2.0 is '+RUBY_VERSION+', but this must be Ruby version 2.0.x. Attempting to install anyway.')
165-
@log.warn('If you have Ruby version 2.0.x installed, please correct the symlink. Otherwise, please install Ruby 2.0')
175+
elsif ((actual_ruby_version <=> right_bound) > 0)
176+
@log.warn("The Ruby version in #{ruby_interpreter_path} is "+RUBY_VERSION+", . Attempting to install anyway.")
166177
end
167178
end
168179

@@ -173,9 +184,9 @@ EOF
173184

174185
parse_args()
175186

176-
########## Force running as Ruby 2.0 or fail here ##########
177-
check_ruby_version_and_symlink()
178-
force_ruby20()
187+
########## Force running as Ruby 2.x or fail here ##########
188+
ruby_interpreter_path = check_ruby_version_and_symlink
189+
force_ruby2x(ruby_interpreter_path)
179190

180191
def run_command(*args)
181192
exit_ok = system(*args)

0 commit comments

Comments
 (0)