Allow users to override output format in create-training-box.sh

Users may want to override the generated output format, in case they
want to run in a virtualization environment other than VMware or
VirtualBox.

Accept a positional argument enabling users to select their preferred
output format, defaulting to VMDK (the previously hard-coded format).

Also, make the creation of an OVA archive conditional on the user
selecting a disk format commonly used with VirtualBox (that is, VDI or
VMDK).

Change-Id: I8829c1a21aa79de877748d9bdc3b7eef7802a6d8
This commit is contained in:
Florian Haas 2018-08-09 14:22:49 +02:00
parent 5c7335d88f
commit b84194f735
1 changed files with 21 additions and 10 deletions

View File

@ -2,22 +2,33 @@
set -e
VMDK=upstream-training-disk001.vmdk
# Create a VMDK image by default. Override with
# "create-training-box.sh <FORMAT>", where FORMAT can be any format
# that qemu-img understands.
FORMAT=${1:-vmdk}
DISK=upstream-training-disk001.$FORMAT
export ELEMENTS_PATH=./elements/
mkdir -p tmp
DIB_OPTIONS="-o tmp/$DISK -t $FORMAT --image-size 40"
if [ "$FORMAT" = "vmdk" ]; then
DIB_OPTIONS="$DIB_OPTIONS --qemu-img-options subformat=streamOptimized"
fi
disk-image-create \
-o "tmp/$VMDK" \
-t vmdk \
--qemu-img-options subformat=streamOptimized \
--image-size 40 \
$DIB_OPTIONS \
upstream-training
DIST="dist/upstream-training-$(date +%Y%m%d-%H%M).ova"
# If we're configured to create a VMDK or VDI image, assume that we're
# building for VirtualBox and also create an OVA tarball
if [ "$FORMAT" = "vmdk" ] || [ "$FORMAT" = "vdi" ]; then
DIST="dist/upstream-training-$(date +%Y%m%d-%H%M).ova"
cp upstream-training.ovf tmp/
cp upstream-training.ovf tmp/
pushd tmp/
tar -cf "../$DIST" upstream-training.ovf "$VMDK"
popd
pushd tmp/
tar -cf "../$DIST" upstream-training.ovf "$DISK"
popd
fi