@@ -76,48 +76,35 @@ to check for a running agent.
7676To use a HTTP proxy, specify --proxy followed by the proxy server
7777defined by http://hostname:port
7878
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.
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.
8481
8582EOF
8683 end
8784
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
85+ # check ruby version, only version 2.0.x works
9386 def check_ruby_version_and_symlink
9487 @log . info ( "Starting Ruby version check." )
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
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 )
10295
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 )
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' )
109106 end
110107 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.' )
121108 end
122109
123110 def parse_args ( )
@@ -159,21 +146,23 @@ EOF
159146 @type = ARGV . shift . downcase ;
160147 end
161148
162- def force_ruby2x ( ruby_interpreter_path )
163- # change interpreter when symlink /usr/bin/ruby2.x exists, but running with non-supported ruby version
149+ def force_ruby20 ( )
150+ # change interpreter when symlink /usr/bin/ruby2.0 exists, but running with lower ruby version
164151 actual_ruby_version = RUBY_VERSION . split ( '.' ) . map { |s |s . to_i }
165152 left_bound = '2.0.0' . split ( '.' ) . map { |s |s . to_i }
166- right_bound = '2.3.1 ' . split ( '.' ) . map { |s |s . to_i }
153+ right_bound = '2.1.0 ' . split ( '.' ) . map { |s |s . to_i }
167154 if ( actual_ruby_version <=> left_bound ) < 0
168155 if ( !@reexeced )
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 )
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 )
171158 else
172- unsupported_ruby_version_error
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' )
173161 exit ( 1 )
174162 end
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." )
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' )
177166 end
178167 end
179168
184173
185174 parse_args ( )
186175
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 )
176+ ########## Force running as Ruby 2.0 or fail here ##########
177+ check_ruby_version_and_symlink ( )
178+ force_ruby20 ( )
190179
191180 def run_command ( *args )
192181 exit_ok = system ( *args )
0 commit comments