Path: | bin/boxgrinder-build |
Last Update: | Mon Dec 19 21:34:07 +0000 2011 |
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: www.fsf.org.
ARGV_DUP | = | ARGV.clone |
# File bin/boxgrinder-build, line 155 155: def ensure_root 156: unless Process.uid == 0 157: puts("Currently running as non-root user, BoxGrinder will attempt to re-launch under 'sudo -E'") 158: # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/151376 159: ruby = File.join(Config::CONFIG["bindir"], 160: Config::CONFIG["RUBY_INSTALL_NAME"] + Config::CONFIG["EXEEXT"]) 161: exec("sudo -E #{ruby} -I#{$:.join(':')} #{Pathname.new(__FILE__).realpath} #{ARGV_DUP.join(" ")}") 162: end 163: end
# File bin/boxgrinder-build, line 65 65: def process_options(options) 66: OptionParser.new do |opts| 67: program = File.basename($0) 68: 69: opts.banner = "Usage: \#{program} [appliance definition file] [options]\n\nA tool for building VM images from simple definition files.\n \nHomepage:\n http://boxgrinder.org/\n\nDocumentation:\n http://boxgrinder.org/tutorials/\n\nExamples:\n $ \#{program} jeos.appl # Build KVM image for jeos.appl\n $ \#{program} jeos.appl -f # Build KVM image for jeos.appl with removing previous build for this image\n $ \#{program} jeos.appl --os-config format:qcow2 # Build KVM image for jeos.appl with a qcow2 disk\n $ \#{program} jeos.appl -p vmware --platform-config type:personal,thin_disk:true # Build VMware image for VMware Server, Player, Fusion using thin (growing) disk\n $ \#{program} jeos.appl -p ec2 -d ami # Build and register AMI for jeos.appl\n $ \#{program} jeos.appl -p vmware -d local # Build VMware image for jeos.appl and deliver it to local directory\n" 70: 71: 72: opts.separator "" 73: opts.separator "Options:" 74: 75: opts.on("-p", "--platform [TYPE]", "The name of platform you want to convert to.") { |v| options.platform = v.to_sym } 76: opts.on("-d", "--delivery [METHOD]", "The delivery method for selected appliance.") { |v| options.delivery = v.to_sym } 77: opts.on("-f", "--force", "Force image creation - removes all previous builds for selected appliance. Default: false.") { |v| options.force = v } 78: 79: opts.separator "" 80: opts.separator "Plugin configuration options:" 81: 82: opts.on("-l", "--plugins [PLUGINS]", Array, "Comma separated list of additional plugins. Default: empty.") do |v| 83: options[:additional_plugins] = v 84: end 85: 86: opts.separator "" 87: 88: opts.on("--os-config [CONFIG]", Array, "Operating system plugin configuration in format: key1:value1,key2:value2.") do |v| 89: validate_hash_option(options, :os_config, v) do |entry| 90: puts "Operating system plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'." 91: end 92: end 93: 94: opts.on("--platform-config [CONFIG]", Array, "Platform plugin configuration in format: key1:value1,key2:value2.") do |v| 95: validate_hash_option(options, :platform_config, v) do |entry| 96: puts "Platform plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'." 97: end 98: end 99: 100: opts.on("--delivery-config [CONFIG]", Array, "Delivery plugin configuration in format: key1:value1,key2:value2.") do |v| 101: validate_hash_option(options, :delivery_config, v) do |entry| 102: puts "Delivery plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'." 103: end 104: end 105: 106: opts.separator "" 107: opts.separator "Logging options:" 108: 109: opts.on("--debug", "Prints debug information while building. Default: false.") { options[:log_level] = :debug } 110: opts.on("--trace", "Prints trace information while building. Default: false.") { options[:log_level] = :trace } 111: opts.on("-b", "--backtrace", "Prints full backtrace if errors occur whilst building. Default: true if console log is set to debug or trace, otherwise false.") { |v| options[:backtrace] = v } 112: 113: opts.separator "" 114: opts.separator 'Common options:' 115: 116: opts.on_tail('--help', 'Show this message.') do 117: puts opts 118: exit 119: end 120: opts.on_tail('--version', 'Print the version.') do 121: puts "BoxGrinder Build #{File.read("#{File.dirname(__FILE__)}/../CHANGELOG").match(/^v(.*)/)[1]}" 122: 123: [:os, :platform, :delivery].each do |type| 124: puts 125: puts "Available #{type} plugins:" 126: BoxGrinder::PluginManager.instance.plugins[type].each do |name, plugin_info| 127: puts " - #{name} plugin for #{plugin_info[:full_name]}" 128: end 129: end 130: 131: exit 132: end 133: end 134: end
# File bin/boxgrinder-build, line 40 40: def validate_hash_option(options, name, value) 41: value.each do |entry| 42: if entry =~ /^(\S+?):(\S+)$/ 43: 44: k = $1.strip 45: v = $2.strip 46: 47: if v =~ /^([-+]?(0|[1-9][0-9_]*))$/ 48: v = v.to_i 49: elsif v =~ /^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)$/ 50: v = true 51: elsif v =~ /^(n|N|no|No|NO|false|False|FALSE|off|Off|OFF)$/ 52: v = false 53: elsif v =~ /^([-+]?([0-9][0-9_]*)?\.[0-9.]*([eE][-+][0-9]+)?)$/ 54: v = v.to_f 55: end 56: 57: options[name][k] = v 58: else 59: yield entry if block_given? 60: abort 61: end 62: end 63: end