From b84194f735f782971efbd93e573006925d4f884f Mon Sep 17 00:00:00 2001 From: Florian Haas Date: Thu, 9 Aug 2018 14:22:49 +0200 Subject: [PATCH] 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 --- create-training-box.sh | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/create-training-box.sh b/create-training-box.sh index 76901ec..a3494a6 100755 --- a/create-training-box.sh +++ b/create-training-box.sh @@ -2,22 +2,33 @@ set -e -VMDK=upstream-training-disk001.vmdk +# Create a VMDK image by default. Override with +# "create-training-box.sh ", 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