boxgrinder-build

Path: bin/boxgrinder-build
Last Update: Thu Jun 14 12:34:20 +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.

Required files

optparse   rubygems   pathname   rbconfig   hashery/opencascade   boxgrinder-core   boxgrinder-core/models/config   boxgrinder-core/helpers/log-helper   boxgrinder-build/appliance   boxgrinder-build/util/permissions/fs-observer   boxgrinder-build/util/permissions/fs-monitor  

Methods

Constants

ARGV_DUP = ARGV.clone

Public Instance methods

[Source]

     # File bin/boxgrinder-build, line 165
165: def ensure_root
166:   unless Process.uid == 0
167:     puts("Currently running as non-root user, BoxGrinder will re-launch under `sudo -E` and change to your local user after the OS plugin.")
168:     # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/151376
169:     ruby = File.join(RbConfig::CONFIG["bindir"],
170:                      RbConfig::CONFIG["RUBY_INSTALL_NAME"] + RbConfig::CONFIG["EXEEXT"])
171:     exec("sudo -E #{ruby} -I#{$:.join(':')} #{Pathname.new(__FILE__).realpath} #{ARGV_DUP.join(" ")} --change-to-user")
172:   end
173: end

[Source]

     # File bin/boxgrinder-build, line 70
 70: def process_options(options)
 71:   OptionParser.new do |opts|
 72:     program = File.basename($0)
 73: 
 74:     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"
 75: 
 76: 
 77:     opts.separator ""
 78:     opts.separator "Options:"
 79: 
 80:     opts.on("-p", "--platform [TYPE]", "The name of platform you want to convert to.") { |v| options.platform = v.to_sym }
 81:     opts.on("-d", "--delivery [METHOD]", "The delivery method for selected appliance.") { |v| options.delivery = v.to_sym }
 82:     opts.on("-f", "--force", "Force image creation - removes all previous builds for selected appliance. Default: false.") { |v| options.force = v }
 83: 
 84:     opts.separator ""
 85:     opts.separator "Plugin configuration options:"
 86: 
 87:     opts.on("-l", "--plugins [PLUGINS]", Array, "Comma separated list of additional plugins. Default: empty.") do |v|
 88:       options[:additional_plugins] = v
 89:     end
 90: 
 91:     opts.separator ""
 92: 
 93:     opts.on("--os-config [CONFIG]", Array, "Operating system plugin configuration in format: key1:value1,key2:value2.") do |v|
 94:       validate_hash_option(options, :os_config, v) do |entry|
 95:         puts "Operating system plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'."
 96:       end
 97:     end
 98: 
 99:     opts.on("--platform-config [CONFIG]", Array, "Platform plugin configuration in format: key1:value1,key2:value2.") do |v|
100:       validate_hash_option(options, :platform_config, v) do |entry|
101:         puts "Platform plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'."
102:       end
103:     end
104: 
105:     opts.on("--delivery-config [CONFIG]", Array, "Delivery plugin configuration in format: key1:value1,key2:value2.") do |v|
106:       validate_hash_option(options, :delivery_config, v) do |entry|
107:         puts "Delivery plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'."
108:       end
109:     end
110: 
111:     opts.separator ""
112:     opts.separator "Logging options:"
113: 
114:     opts.on("--debug", "Prints debug information while building. Default: false.") { options[:log_level] = :debug }
115:     opts.on("--trace", "Prints trace information while building. Default: false.") { options[:log_level] = :trace }
116:     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 }
117: 
118:     opts.separator ""
119:     opts.separator 'Common options:'
120: 
121:     opts.on_tail('--help', 'Show this message.') do
122:       puts opts
123:       exit
124:     end
125: 
126:     opts.on_tail('--version', 'Print the version.') do
127:       puts "BoxGrinder Build #{File.read("#{File.dirname(__FILE__)}/../CHANGELOG").match(/^v(.*)/)[1]}"
128: 
129:       [:os, :platform, :delivery].each do |type|
130:         puts
131:         puts "Available #{type} plugins:"
132:         BoxGrinder::PluginManager.instance.plugins[type].each do |name, plugin_info|
133:           puts " - #{name} plugin for #{plugin_info[:full_name]}"
134:         end
135:       end
136: 
137:       exit
138:     end
139: 
140:     opts.on('--change-to-user', 'Change from root to local user after the OS plugin completes.') do
141:       options[:change_to_user] = true
142:     end
143:   end
144: end

[Source]

    # File bin/boxgrinder-build, line 45
45: def validate_hash_option(options, name, value)
46:   value.each do |entry|
47:     if entry =~ /^(\S+?):(\S+)$/
48: 
49:       k = $1.strip
50:       v = $2.strip
51: 
52:       if v =~ /^([-+]?(0|[1-9][0-9_]*))$/
53:         v = v.to_i
54:       elsif v =~ /^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)$/
55:         v = true
56:       elsif v =~ /^(n|N|no|No|NO|false|False|FALSE|off|Off|OFF)$/
57:         v = false
58:       elsif v =~ /^([-+]?([0-9][0-9_]*)?\.[0-9.]*([eE][-+][0-9]+)?)$/
59:         v = v.to_f
60:       end
61: 
62:       options[name][k] = v
63:     else
64:       yield entry if block_given?
65:       abort
66:     end
67:   end
68: end

[Validate]