rconf 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -146,7 +146,13 @@ module RightConf
146
146
  must_configure = (Profile.force_check? || sha != sig) && !check
147
147
  end
148
148
  Platform.dispatch(*args) { :run } if must_configure
149
- Profile.set_configurator_signature(key, sig) unless aborting
149
+
150
+ # clear any leftover signature in case of aborting to prevent rconf
151
+ # doing nothing on restart.
152
+ #
153
+ # FIX: there seems to be an issue when a new ruby version is installed
154
+ # and rconf aborts and has to be restarted (on Ubuntu?)
155
+ Profile.set_configurator_signature(key, aborting ? nil : sig)
150
156
  true
151
157
  end
152
158
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2011-2012 RightScale, Inc, All Rights Reserved Worldwide.
1
+ # Copyright (C) 2011-2013 RightScale, Inc, All Rights Reserved Worldwide.
2
2
  #
3
3
  # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
4
4
  # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use,
@@ -9,19 +9,25 @@
9
9
  # License Agreement between RightScale.com, Inc. and
10
10
  # the licensee
11
11
 
12
+ require 'fileutils'
13
+ require 'tmpdir'
14
+
12
15
  module RightConf
13
16
 
14
17
  # Specify rbenv and ruby-build git revision for installation
15
18
  RBENV_GIT_REPO = 'git://github.com/sstephenson/rbenv.git'
16
- RBENV_GIT_REVISION = "9375e99f921f428849f19efe2a2e500b3295d1a7"
19
+ RBENV_GIT_REVISION = "605e691bff4863e5014ba5ad750ad65e3278aea3"
17
20
 
18
21
  RUBYBUILD_GIT_REPO = 'git://github.com/sstephenson/ruby-build.git'
19
- RUBY_BUILD_GIT_REVISION = "28b9bcb6df1bc18fb2b06e25ee65f397ac3d4632"
22
+ RUBY_BUILD_GIT_REVISION = "57cb1e98c6ec695c130e369629d02417ccc1a51a"
20
23
 
21
24
  # Local installation target folders
22
25
  RBENV_INSTALL_TARGET = "#{ENV['HOME']}/.rbenv"
23
26
  RUBYBUILD_TARGET = "#{RBENV_INSTALL_TARGET}/plugins/ruby-build"
27
+ RUBYBUILD_DEFINITIONS_PATH = ::File.join(RUBYBUILD_TARGET, 'share', 'ruby-build')
24
28
 
29
+ # rubygems
30
+ RUBYGEMS_URI_PREFIX = 'http://production.cf.rubygems.org/rubygems'
25
31
 
26
32
  class RubyConfigurator
27
33
 
@@ -32,7 +38,8 @@ module RightConf
32
38
  description "Installs ruby interpreter and rubygems.\n" +
33
39
  'Installs and uses rbenv on supported (i.e. non-Windows) platforms'
34
40
 
35
- setting 'version', 'Ruby version using rbenv notation (see "rbenv versions")', :required => true
41
+ setting 'version', 'Ruby version using rbenv notation (see "rbenv versions")', :required => true
42
+ setting 'rubygems', 'RubyGems version using semantic versioning'
36
43
 
37
44
  updater lambda { update_rbenv_installation }
38
45
 
@@ -70,7 +77,8 @@ module RightConf
70
77
  check_rbenv
71
78
  return true if aborting
72
79
  check_ruby
73
- Command.set_ruby(ruby_version)
80
+ Command.set_ruby(ruby_with_rubygems_version)
81
+ check_rubygems
74
82
  true
75
83
  end
76
84
  alias :run_darwin :run_linux
@@ -90,12 +98,25 @@ module RightConf
90
98
  @ruby_version ||= version.start_with?('ruby-') ? version[5..-1] : version
91
99
  end
92
100
 
101
+ # appends a rubygems version specifier only when necessary.
102
+ def ruby_with_rubygems_version
103
+ @ruby_with_rubygems_version ||= (rubygems ? "#{ruby_version}_rubygems-#{rubygems}" : ruby_version)
104
+ end
105
+
106
+ def ruby_bin_path_for(version)
107
+ ::File.join(RBENV_INSTALL_TARGET, 'versions', version, 'bin', 'ruby')
108
+ end
109
+
110
+ def gem_bin_path_for(version)
111
+ ::File.join(RBENV_INSTALL_TARGET, 'versions', version, 'bin', 'gem')
112
+ end
113
+
93
114
  # Check whether rbenv and ruby-build are installed and installs it/them if not
94
115
  #
95
116
  # === Return
96
117
  # true:: Always return true
97
118
  def check_rbenv
98
- rbenv_present = File.exist?(File.join(ENV['HOME'], '.rbenv', 'bin', 'rbenv'))
119
+ rbenv_present = File.exist?(File.join(RBENV_INSTALL_TARGET, 'bin', 'rbenv'))
99
120
 
100
121
  res = Command.execute('rbenv')
101
122
  rbenv_in_path = res.success?
@@ -127,10 +148,10 @@ module RightConf
127
148
  # === Return
128
149
  # true:: Always return true
129
150
  def self.add_custom_ree_definition
130
- curr_dir=File.dirname(__FILE__)
131
- patched_ree = "#{curr_dir}/../../patches/ree-1.8.7-2012.02-rs-custom"
132
- FileUtils.cp patched_ree, "#{RUBYBUILD_TARGET}/share/ruby-build/ree-1.8.7-2012.02"
133
-
151
+ puts "Adding custom ruby enterprise edition definition to ruby-build ..."
152
+ src_patched_ree = ::File.expand_path('../../../patches/ree-1.8.7-2012.02-rs-custom', __FILE__)
153
+ dst_patched_ree = ::File.join(RUBYBUILD_DEFINITIONS_PATH, 'ree-1.8.7-2012.02')
154
+ ::FileUtils.cp(src_patched_ree, dst_patched_ree)
134
155
  true
135
156
  end
136
157
 
@@ -143,14 +164,14 @@ module RightConf
143
164
  puts "Updating rbenv ..."
144
165
  if File.directory?("#{RBENV_INSTALL_TARGET}/.git")
145
166
  # Perform the pull only if rbenv has been installed by using a git pull (and not through a package manager)
146
- system("cd #{RBENV_INSTALL_TARGET}; git fetch -q; git checkout -q #{RBENV_GIT_REVISION}")
167
+ system("cd #{RBENV_INSTALL_TARGET}; git fetch -q; git checkout -f -q #{RBENV_GIT_REVISION}")
147
168
  end
148
169
 
149
170
  puts "Updating ruby-build ..."
150
171
  if File.directory?("#{RUBYBUILD_TARGET}/.git")
151
172
  # Perform the pull only if ruby-build has been installed by using a git pull (and not through a package manager)
152
173
  # Before checking out the new branch, reset the repository to avoid conflicts
153
- system("cd #{RUBYBUILD_TARGET}; git reset -q --hard; git fetch -q; git checkout -q #{RUBY_BUILD_GIT_REVISION}")
174
+ system("cd #{RUBYBUILD_TARGET}; git reset -q --hard; git fetch -q; git checkout -f -q #{RUBY_BUILD_GIT_REVISION}")
154
175
 
155
176
  # Add our ree definition again because the repository has been reset
156
177
  RubyConfigurator.add_custom_ree_definition
@@ -205,9 +226,57 @@ module RightConf
205
226
  # === Return
206
227
  # true:: Always return true
207
228
  def check_ruby
208
- unless Command.execute('rbenv', 'local', ruby_version).success?
209
- report_check("Installing ruby #{ruby_version} (this will take a while, please be patient)")
210
- Platform.dispatch(ruby_version) { :install_ruby }
229
+ if Command.execute('rbenv', 'local', ruby_with_rubygems_version).success?
230
+ # always (re)install latest rconf gem because switched-to ruby may exist
231
+ # but not have rconf.
232
+ install_rconf(ruby_with_rubygems_version)
233
+ else
234
+ report_check("Installing ruby #{ruby_with_rubygems_version} (this will take a while, please be patient)")
235
+
236
+ # create a ruby+rubygems definition file in order to isolate any
237
+ # differences in rubygems versions between projects. ideally only a
238
+ # single rubygems version will be specified for use with a given ruby
239
+ # platform version.
240
+ #
241
+ # note that copying/renaming an existing installed ruby directory does
242
+ # not work as expected because the installed files contain shebangs that
243
+ # refer back to the original installed directory.
244
+ if ruby_version != ruby_with_rubygems_version
245
+ # ruby+rubygems definition may already exist because it was previously
246
+ # created here, checked into source control, etc.
247
+ dst_def_path = ::File.join(RUBYBUILD_DEFINITIONS_PATH, ruby_with_rubygems_version)
248
+ unless ::File.file?(dst_def_path)
249
+ src_def_path = ::File.join(RUBYBUILD_DEFINITIONS_PATH, ruby_version)
250
+ if ::File.file?(src_def_path)
251
+ # existing ruby platform definition may include a specifier for
252
+ # the requested rubygems version or some other version but not all
253
+ # definitions will have this specifier. in any case, we need to
254
+ # run and then restart rconf and maintain state so we need to
255
+ # create a custom ruby platform definition.
256
+ #
257
+ # remove any existing rubygems specifier.
258
+ src_def_text = ::File.read(src_def_path)
259
+ any_rubygems_regex = /^install_package\s+"rubygems\-.*$/
260
+ dst_def_text = src_def_text.gsub(any_rubygems_regex, '').gsub("\n\n", "\n").strip
261
+
262
+ # append full rubygems specifier to definition to make
263
+ # rbenv install do the work of installing correct rubygems version.
264
+ rubygems_basename = "rubygems-#{rubygems}"
265
+ rubygems_specifier_prefix = "install_package #{rubygems_basename.inspect}"
266
+ rubygems_filename = "#{rubygems_basename}.tgz"
267
+ rubygems_tarball_url = ::File.join(RUBYGEMS_URI_PREFIX, rubygems_filename)
268
+ rubygems_specifier_full = "#{rubygems_specifier_prefix} #{rubygems_tarball_url.inspect} ruby"
269
+ dst_def_text += "\n#{rubygems_specifier_full}"
270
+
271
+ # write custom ruby platform definition.
272
+ ::File.open(dst_def_path, 'w') { |f| f.write(dst_def_text) }
273
+ else
274
+ post_note "Requested ruby version definition not found: #{ruby_version}"
275
+ aborting(true)
276
+ end
277
+ end
278
+ end
279
+ Platform.dispatch(ruby_with_rubygems_version) { :install_ruby }
211
280
  end
212
281
 
213
282
  which = Command.execute('which', 'ruby').output.strip
@@ -216,6 +285,13 @@ module RightConf
216
285
  aborting(true)
217
286
  end
218
287
 
288
+ # if currenly executing ruby is not our selected ruby then we must abort
289
+ # and run rconf again or else bundler will install gems to wrong directory.
290
+ which = Command.execute('rbenv', 'which', 'ruby').output.strip
291
+ if which != ruby_bin_path_for(ruby_with_rubygems_version)
292
+ post_note "rconf selected ruby #{ruby_with_rubygems_version} and needs to be restarted so the right ruby tools get activated\nPlease run 'rconf' again."
293
+ aborting(true)
294
+ end
219
295
  true
220
296
  end
221
297
 
@@ -232,11 +308,27 @@ module RightConf
232
308
  # Can't abort on failure rbenv install seems to exist with a non zero error code even when successful :(
233
309
  Command.execute('rbenv', 'install', ruby)
234
310
  report_success
311
+ abort_message = <<EOF
312
+ Failed to select installed ruby or else installation failed.
313
+ Try running 'rconf -u' to update rbenv to latest known ruby definitions (for REE, etc.)
314
+ Run 'rbenv install --list' to see current list of available rubies.
315
+ EOF
316
+ Command.execute('rbenv', 'local', ruby, :abort_on_failure => abort_message.chomp)
317
+ install_rconf(ruby)
235
318
  post_note "rconf installed ruby #{ruby} and needs to be restarted so the right ruby tools get activated\nPlease run 'rconf' again."
236
319
  aborting(true)
237
320
  true
238
321
  end
239
322
 
323
+ # gem install the latest greatest rconf before leaving to avoid confusion
324
+ # when user tries and fails to restart rconf as indicated. assumes some
325
+ # version of rubygems is provided by every ruby install.
326
+ def install_rconf(ruby_selector)
327
+ report_check("Installing latest rconf gem into selected ruby '#{ruby_selector}'")
328
+ Command.execute(gem_bin_path_for(ruby_selector), 'install', 'rconf', '--no-rdoc', '--no-ri', :abort_on_failure => "Failed to install rconf gem in selected ruby")
329
+ report_success
330
+ end
331
+
240
332
  # Install given ruby version using rbenv
241
333
  # On Lion, need to setup CC env var before running rbenv install
242
334
  #
@@ -326,6 +418,49 @@ module RightConf
326
418
  true
327
419
  end
328
420
 
421
+ # check if rubygems is installed and has the expected version or else kick
422
+ # off installation when required.
423
+ def check_rubygems
424
+ return true unless rubygems
425
+ report_check("Checking for rubygems #{rubygems}")
426
+ gem_bin_path = gem_bin_path_for(ruby_with_rubygems_version)
427
+ result = Command.execute(gem_bin_path, '-v', :abort_on_failure => nil)
428
+ current_rubygems = result.success? ? result.output.strip : ''
429
+ if current_rubygems == rubygems
430
+ report_success
431
+ else
432
+ install_rubygems(rubygems)
433
+ result = Command.execute(gem_bin_path, '-v', :abort_on_failure => nil)
434
+ current_rubygems = result.success? ? result.output.strip : ''
435
+ if current_rubygems == rubygems
436
+ report_success
437
+ else
438
+ post_note "Failed to update RubyGems to v#{rubygems}:\n#{result.output.strip}"
439
+ report_failure
440
+ end
441
+ end
442
+ true
443
+ end
444
+
445
+ # installs, upgrades, downgrades, or reinstalls rubygems to specified
446
+ # version by downloading source tarball and executing 'setup.rb'.
447
+ def install_rubygems(version)
448
+ report_check("Installing rubygems #{version}")
449
+ basename = "rubygems-#{version}"
450
+ filename = "#{basename}.tgz"
451
+ tarball_url = ::File.join(RUBYGEMS_URI_PREFIX, filename)
452
+ ::Dir.mktmpdir do |tmpdir|
453
+ ::Dir.chdir(tmpdir) do
454
+ Command.execute('curl', '-O', '-f', tarball_url, :abort_on_failure => "Failed to curl #{tarball_url}")
455
+ Command.execute('tar', '-xzvf', filename, :abort_on_failure => "Failed to explode #{filename}")
456
+
457
+ # rubygems 'setup.rb' needs it's root dir to be the working dir.
458
+ ::Dir.chdir(basename) do
459
+ Command.execute(ruby_bin_path_for(ruby_with_rubygems_version), 'setup.rb', :abort_on_failure => "Failed to setup rubygems")
460
+ end
461
+ end
462
+ end
463
+ end
329
464
 
330
465
  # Produce abort on failure option
331
466
  #
@@ -85,23 +85,25 @@ module RightConf
85
85
  end
86
86
  begin
87
87
  source.split("\n").each do |o|
88
- operands = o.gsub(/\s+/, '').split('=')
89
- if operands.size != 2
90
- raise "Invalid syntax '#{o}', must be of the form 'key.setting=value'"
88
+ unless o.start_with?('#') # ignore commented-out lines
89
+ operands = o.gsub(/\s+/, '').split('=')
90
+ if operands.size != 2
91
+ raise "Invalid syntax '#{o}', must be of the form 'key.setting=value'"
92
+ end
93
+
94
+ if operands[1].start_with?('"') || operands[1].start_with?("'")
95
+ # Quoted string
96
+ value = operands[1]
97
+ elsif operands[1] =~ NIL_LITERAL
98
+ # Literal nil
99
+ value = 'nil'
100
+ else
101
+ # Anything else: assume unquoted string
102
+ value = "'#{operands[1]}'"
103
+ end
104
+
105
+ overrides.instance_eval("@#{operands[0]}=#{value}")
91
106
  end
92
-
93
- if operands[1].start_with?('"') || operands[1].start_with?("'")
94
- # Quoted string
95
- value = operands[1]
96
- elsif operands[1] =~ NIL_LITERAL
97
- # Literal nil
98
- value = 'nil'
99
- else
100
- # Anything else: assume unquoted string
101
- value = "'#{operands[1]}'"
102
- end
103
-
104
- overrides.instance_eval("@#{operands[0]}=#{value}")
105
107
  end
106
108
  rescue Exception => e
107
109
  @overrides = nil
@@ -13,7 +13,7 @@ module RightConf
13
13
 
14
14
  MAJOR = 1
15
15
  MINOR = 0
16
- BUILD = 12
16
+ BUILD = 13
17
17
 
18
18
  VERSION = [MAJOR, MINOR, BUILD].map(&:to_s).join('.')
19
19
 
@@ -1,9 +1,8 @@
1
- # Configuration settings for RightSite
1
+ # Configuration settings for rconf
2
2
  ruby do
3
- version 'ruby-1.9.3-p392'
3
+ version 'ruby-1.9.3-p448'
4
+ rubygems '1.8.26'
4
5
  end
5
6
  bundler do
6
7
  version '1.3.5'
7
8
  end
8
-
9
-
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rconf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Raphael Simon
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-12-09 00:00:00.000000000 Z
12
+ date: 2014-01-02 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rspec
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: flexmock
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -121,26 +126,33 @@ files:
121
126
  - spec/support/package_installer_spec.rb
122
127
  homepage: http://rubygems.org/gems/rconf
123
128
  licenses: []
124
- metadata: {}
125
129
  post_install_message:
126
130
  rdoc_options: []
127
131
  require_paths:
128
132
  - lib
129
133
  required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
130
135
  requirements:
131
136
  - - ! '>='
132
137
  - !ruby/object:Gem::Version
133
138
  version: '0'
139
+ segments:
140
+ - 0
141
+ hash: -2553812799441389264
134
142
  required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
135
144
  requirements:
136
145
  - - ! '>='
137
146
  - !ruby/object:Gem::Version
138
147
  version: '0'
148
+ segments:
149
+ - 0
150
+ hash: -2553812799441389264
139
151
  requirements: []
140
152
  rubyforge_project: rconf
141
- rubygems_version: 2.1.8
153
+ rubygems_version: 1.8.26
142
154
  signing_key:
143
- specification_version: 4
155
+ specification_version: 3
144
156
  summary: Cross platform environment configuration
145
157
  test_files:
146
158
  - spec/command_spec.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTg4MDQ2NGY4ZTI1NDMzZTFiNzc5NzYwZTBmMTlkZDQ5NjhhMjM5Nw==
5
- data.tar.gz: !binary |-
6
- OTliZTY2MjBjMDZhOGFjZTM3ZTQ5ZmJkOWIzYTdjNGRkZDc1MzU4NA==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- ZDNkZTUwYzAwMzMyZTk1OTBhMmI1YmVlZDYzMTI2Yzc4OTE5ODM1MDU5YTZi
10
- MTcwN2Q5NWVkZmE5NzBiMzYyZGM3NjMyMWMzZTc1ZTE2YjFkODIxODA3OGU5
11
- NDVhMmY5M2NlNGJlNTM2MjgwZTdlNDkyMWQ2MTZhNWFkNzMwOTY=
12
- data.tar.gz: !binary |-
13
- MmYwY2I0ZTRlMjRhYTBjYTM2YjdmZjU4Yjk5YzNhNTkxMTdhMGU2YjkzNDdk
14
- OWUwYThiYTcyZjExODE1MzUyMmM2OWE3ZjYwMjY3NzdiMGIzZmNjOTI2Mjgy
15
- MTljMThhZGU2MjJkNzk0MzY3YTBlNzQ0MjRjMWUyNGU4OWZiZjk=