Path: | bin/boxgrinder-build |
Last Update: | Mon Mar 19 13:16:47 +0000 2012 |
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 164 164: def ensure_root 165: unless Process.uid == 0 166: puts("Currently running as non-root user, BoxGrinder will re-launch under `sudo -E` and change to your local user after the OS plugin.") 167: # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/151376 168: ruby = File.join(RbConfig::CONFIG["bindir"], 169: RbConfig::CONFIG["RUBY_INSTALL_NAME"] + RbConfig::CONFIG["EXEEXT"]) 170: exec("sudo -E #{ruby} -I#{$:.join(':')} #{Pathname.new(__FILE__).realpath} #{ARGV_DUP.join(" ")} --change-to-user") 171: end 172: end
# File bin/boxgrinder-build, line 69 69: def process_options(options) 70: OptionParser.new do |opts| 71: program = File.basename($0) 72: 73: 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" 74: 75: 76: opts.separator "" 77: opts.separator "Options:" 78: 79: opts.on("-p", "--platform [TYPE]", "The name of platform you want to convert to.") { |v| options.platform = v.to_sym } 80: opts.on("-d", "--delivery [METHOD]", "The delivery method for selected appliance.") { |v| options.delivery = v.to_sym } 81: opts.on("-f", "--force", "Force image creation - removes all previous builds for selected appliance. Default: false.") { |v| options.force = v } 82: 83: opts.separator "" 84: opts.separator "Plugin configuration options:" 85: 86: opts.on("-l", "--plugins [PLUGINS]", Array, "Comma separated list of additional plugins. Default: empty.") do |v| 87: options[:additional_plugins] = v 88: end 89: 90: opts.separator "" 91: 92: opts.on("--os-config [CONFIG]", Array, "Operating system plugin configuration in format: key1:value1,key2:value2.") do |v| 93: validate_hash_option(options, :os_config, v) do |entry| 94: puts "Operating system plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'." 95: end 96: end 97: 98: opts.on("--platform-config [CONFIG]", Array, "Platform plugin configuration in format: key1:value1,key2:value2.") do |v| 99: validate_hash_option(options, :platform_config, v) do |entry| 100: puts "Platform plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'." 101: end 102: end 103: 104: opts.on("--delivery-config [CONFIG]", Array, "Delivery plugin configuration in format: key1:value1,key2:value2.") do |v| 105: validate_hash_option(options, :delivery_config, v) do |entry| 106: puts "Delivery plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'." 107: end 108: end 109: 110: opts.separator "" 111: opts.separator "Logging options:" 112: 113: opts.on("--debug", "Prints debug information while building. Default: false.") { options[:log_level] = :debug } 114: opts.on("--trace", "Prints trace information while building. Default: false.") { options[:log_level] = :trace } 115: 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 } 116: 117: opts.separator "" 118: opts.separator 'Common options:' 119: 120: opts.on_tail('--help', 'Show this message.') do 121: puts opts 122: exit 123: end 124: 125: opts.on_tail('--version', 'Print the version.') do 126: puts "BoxGrinder Build #{File.read("#{File.dirname(__FILE__)}/../CHANGELOG").match(/^v(.*)/)[1]}" 127: 128: [:os, :platform, :delivery].each do |type| 129: puts 130: puts "Available #{type} plugins:" 131: BoxGrinder::PluginManager.instance.plugins[type].each do |name, plugin_info| 132: puts " - #{name} plugin for #{plugin_info[:full_name]}" 133: end 134: end 135: 136: exit 137: end 138: 139: opts.on('--change-to-user', 'Change from root to local user after the OS plugin completes.') do 140: options[:change_to_user] = true 141: end 142: end 143: end
# File bin/boxgrinder-build, line 44 44: def validate_hash_option(options, name, value) 45: value.each do |entry| 46: if entry =~ /^(\S+?):(\S+)$/ 47: 48: k = $1.strip 49: v = $2.strip 50: 51: if v =~ /^([-+]?(0|[1-9][0-9_]*))$/ 52: v = v.to_i 53: elsif v =~ /^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)$/ 54: v = true 55: elsif v =~ /^(n|N|no|No|NO|false|False|FALSE|off|Off|OFF)$/ 56: v = false 57: elsif v =~ /^([-+]?([0-9][0-9_]*)?\.[0-9.]*([eE][-+][0-9]+)?)$/ 58: v = v.to_f 59: end 60: 61: options[name][k] = v 62: else 63: yield entry if block_given? 64: abort 65: end 66: end 67: end