#!/usr/bin/env ruby # Copyright 2010 Red Hat, Inc. # # This is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 3 of # the License, or (at your option) any later version. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this software; if not, write to the Free # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA # 02110-1301 USA, or see the FSF site: http://www.fsf.org. require 'optparse' require 'rubygems' require 'hashery/opencascade' require 'boxgrinder-core/models/config' require 'boxgrinder-core/helpers/log-helper' require 'boxgrinder-build/appliance' if Process.uid != 0 puts "This program must be executed with root privileges. Try 'sudo #{File.basename($0)}'." abort end options = OpenCascade.new( :platform => :none, :delivery => :none, :os_config => {}, :platform_config => {}, :delivery_config => {}, :additional_plugins => [] ) def validate_hash_option(options, name, value) value.each do |entry| if entry =~ /^(\S+):(\S+)$/ k = $1.strip v = $2.strip if v =~ /^([-+]?(0|[1-9][0-9_]*))$/ v = v.to_i elsif v =~ /^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)$/ v = true elsif v =~ /^(n|N|no|No|NO|false|False|FALSE|off|Off|OFF)$/ v = false elsif v =~ /^([-+]?([0-9][0-9_]*)?\.[0-9.]*([eE][-+][0-9]+)?)$/ v = v.to_f end options[name][k] = v else yield entry if block_given? abort end end end def process_options(options) OptionParser.new do |opts| program = File.basename($0) opts.banner = < 1 puts opts puts puts 'No or more than one appliance definition file specified.' abort end appliance_definition_file = ARGV.first unless File.exists?(appliance_definition_file) puts "Appliance definition file '#{appliance_definition_file}' could not be found." abort end config = BoxGrinder::Config.new(options) log = BoxGrinder::LogHelper.new(:level => config.log_level) begin BoxGrinder::Appliance.new(appliance_definition_file, config, :log => log).create rescue Exception => e msg = "#{e.class}: #{e.message}#$/#{e.backtrace.join($/)}" if options.backtrace log.fatal msg else # demote backtrace to debug so that it is in file log only log.fatal "#{e.class}: #{e.message}. See the log file for detailed information." log.debug msg end end rescue => e puts opts puts puts e.message abort end