bin/rconf in rconf-0.6.15 vs bin/rconf in rconf-0.6.16
- old
+ new
@@ -10,10 +10,11 @@
# License Agreement between RightScale.com, Inc. and
# the licensee
$stdout.sync = true
+require 'json'
require File.join(File.dirname(__FILE__), '..', 'lib', 'rconf')
module RightConf
class Configurer
@@ -31,10 +32,11 @@
where [options] are:
EOS
opt :configurators, 'Show available configurators'
+ opt :update, 'Update rconf to latest version'
opt :config, 'Set path to configuration file', :type => :string
opt :output, 'Output file (output to STDOUT by default)', :type => :string
opt :force, 'Run rconf even if configuration file has not changed'
opt :verbose, 'Print debug output'
end
@@ -51,42 +53,97 @@
FileUtils.mkdir_p(File.dirname(opts[:output]))
rescue Exception => e
Trollop::die :output, "Failed to initialize output file: #{e.message}"
end
end
- new.configure(opts)
+ if opts[:configurators]
+ new.list_configurators
+ elsif opts[:update]
+ new.update
+ else
+ new.configure(opts)
+ end
end
+ # List all available configurators
+ #
+ # === Return
+ # true:: Always return true
+ def list_configurators
+ puts "The following configurators are registered:\n\n"
+ ConfiguratorRegistry.each do |key, configurator|
+ puts "== #{key} ==".bold
+ puts configurator.desc
+ puts 'Settings:'
+ max_size = configurator.all_settings.keys.map(&:to_s).map(&:size).max
+ configurator.all_settings.each do |name, desc|
+ num_spaces = max_size - name.to_s.size + 1
+ print " - #{name.to_s.blue}:#{' ' * num_spaces}#{desc}"
+ required_settings = configurator.required_settings || []
+ if required_settings.include?(name)
+ puts ' [required]'.green
+ else
+ puts
+ end
+ end
+ puts
+ end
+ end
+
+ # Update rconf to latest in all installed rubies
+ #
+ # === Return
+ # true:: Always return true
+ def update
+ ProgressReporter.report_to_stdout
+ report_check 'Retrieving latest rconf...'
+ json = Command.execute('curl', '-s', 'http://rubygems.org/api/v1/gems/rconf.json').output
+ info = JSON.load(json)
+ report_fatal 'Failed to retrieve rconf gem information, check network connectivity' unless info
+ version = info['version']
+ report_success
+ report('Latest rconf version is ' + version.blue)
+ rubies = Command.execute('rvm', 'list').output
+ rubies = rubies.split("\n")[3..-1]
+ update_rconf(rubies, version)
+ end
+
+ # Update rconf for given rubies if required
+ #
+ # === Parameters
+ # rubies(Array):: List of rubies as returned by 'rvm list'
+ # version(String):: Latest version
+ #
+ # === Return
+ # true:: Always return true
+ def update_rconf(rubies, version)
+ rubies.each do |ruby|
+ ruby =~ /(\s+| =>)([^ ]*)\s.*/
+ ruby = Regexp.last_match(2)
+ report_check("Checking rconf for #{ruby}")
+ rconf = Command.execute('rvm', "#{ruby}@global", 'exec', 'gem', 'list', 'rconf').output
+ if rconf =~ /rconf \(#{version}\)/
+ report_success
+ next
+ else
+ report_failure
+ report_check("Updating rconf for #{ruby}")
+ res = Command.execute('rvm', "#{ruby}@global", 'exec', 'gem', 'install', 'rconf')
+ report_result(res.success?)
+ end
+ end
+ end
+
+
# Actually configure environment
#
# === Parameters
# options[:config](String):: Configuration file
# options[:output](String):: Output file, optional
#
# === Return
# true:: Always return true
def configure(options)
- if options[:configurators]
- puts "The following configurators are registered:\n\n"
- ConfiguratorRegistry.each do |key, configurator|
- puts "== #{key} ==".bold
- puts configurator.desc
- puts 'Settings:'
- max_size = configurator.all_settings.keys.map(&:to_s).map(&:size).max
- configurator.all_settings.each do |name, desc|
- num_spaces = max_size - name.to_s.size + 1
- print " - #{name.to_s.blue}:#{' ' * num_spaces}#{desc}"
- required_settings = configurator.required_settings || []
- if required_settings.include?(name)
- puts ' [required]'.green
- else
- puts
- end
- end
- puts
- end
- exit 0
- end
Profile.reset if options[:force]
ProgressReporter.report_to_stdout
ProgressReporter.report_to_file(options[:output]) if options[:output]
Command.set_verbose if options[:verbose]
begin