#!/bin/bash # Mostly this just copies the below XML, but inserting random MAC address # and UUID strings, and other options as appropriate. SCRIPT_ROOT=$(readlink -f $(dirname "$0")/..) . "${SCRIPT_ROOT}/common.sh" || exit 1 DEFINE_string vm_name "CoreOS" "Name for this VM" DEFINE_string disk_vmdk "" "Disk image to reference, only basename is used." DEFINE_integer memory_size 1024 "Memory size in MB" DEFINE_string output_ovf "" "Path to write ofv file to, required." DEFINE_string output_vagrant "" "Path to write Vagrantfile to, optional." # Parse command line FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Die on any errors. switch_to_strict_mode if [[ ! -e "${FLAGS_disk_vmdk}" ]]; then echo "No such disk image '${FLAGS_disk_vmdk}'" >&2 exit 1 fi DISK_NAME=$(basename "${FLAGS_disk_vmdk}") DISK_UUID=$(uuidgen) DISK_SIZE_BYTES=$(qemu-img info -f vmdk "${FLAGS_disk_vmdk}" \ | gawk 'match($0, /^virtual size:.*\(([0-9]+) bytes\)/, a) {print a[1]}') if [[ -z "${DISK_SIZE_BYTES}" ]]; then echo "Unable to determine virtual size of ${FLAGS_disk_vmdk}" >&2 exit 1 fi # Generate random MAC addresses just as VirtualBox does, the format is # their assigned prefix for the first 3 bytes followed by 3 random bytes. VBOX_MAC_PREFIX=080027 macgen() { hexdump -n3 -e "\"${VBOX_MAC_PREFIX}%06X\n\"" /dev/urandom } # Used in both the ovf and Vagrantfile PRIMARY_MAC=$(macgen) # Date format as used in ovf datez() { date -u "+%Y-%m-%dT%H:%M:%SZ" } if [[ -n "${FLAGS_output_vagrant}" ]]; then cat >"${FLAGS_output_vagrant}" <"${FLAGS_output_ovf}" < List of the virtual disks used in the package Logical networks used in the package Logical network used by this appliance. A virtual machine The kind of installed guest operating system Linux26_64 Linux26_64 Virtual hardware requirements for a virtual machine Virtual Hardware Family 0 ${FLAGS_vm_name} virtualbox-2.2 1 virtual CPU Number of virtual CPUs 1 virtual CPU 1 3 1 MegaBytes ${FLAGS_memory_size} MB of memory Memory Size ${FLAGS_memory_size} MB of memory 2 4 ${FLAGS_memory_size} 0 ideController0 IDE Controller ideController0 3 PIIX4 5 1 ideController1 IDE Controller ideController1 4 PIIX4 5 true Ethernet adapter on 'NAT' NAT Ethernet adapter on 'NAT' 5 E1000 10 0 disk1 Disk Image disk1 /disk/vmdisk1 6 3 17 Complete VirtualBox machine configuration in VirtualBox format EOF fi