diff --git a/labs/lib/osbash/virtualbox.functions b/labs/lib/osbash/virtualbox.functions index 4e72c011..a3fc5a81 100644 --- a/labs/lib/osbash/virtualbox.functions +++ b/labs/lib/osbash/virtualbox.functions @@ -457,6 +457,16 @@ function disk_delete_child_vms { # VM shared folders #------------------------------------------------------------------------------- +# Return the host path for a VM's shared directory; assumes there is only one. +function vm_get_share_path { + local VM_NAME=$1 + local LINE=$(WBATCH= $VBM showvminfo --machinereadable "$VM_NAME" | \ + grep '^SharedFolderPathMachineMapping1=') + local SHARE_PATH=${LINE##SharedFolderPathMachineMapping1=\"} + SHARE_PATH=${SHARE_PATH%\"} + echo "$SHARE_PATH" +} + function vm_add_share_automount { local VM_NAME=$1 local SHARE_DIR=$2 diff --git a/labs/osbash.sh b/labs/osbash.sh index 12410eb4..a28cd9a2 100755 --- a/labs/osbash.sh +++ b/labs/osbash.sh @@ -163,14 +163,28 @@ done #------------------------------------------------------------------------------- function export_appliance { if [ -n "${EXPORT_OVA:-}" ]; then - echo "Removing shared folders for export" - vm_rm_share "controller" "$SHARE_NAME" - vm_rm_share "network" "$SHARE_NAME" - vm_rm_share "compute" "$SHARE_NAME" + echo >&2 "Removing shared folders for export" + local -a share_paths + local node + for node in $nodes; do + local share_path=$(vm_get_share_path "$node") + share_paths+=("$share_path") + if [ -n "$share_path" ]; then + vm_rm_share "$node" "$SHARE_NAME" + fi + done rm -f "$EXPORT_OVA" mkdir -pv "$IMG_DIR" $VBM export controller network compute --output "$EXPORT_OVA" echo >&2 "Appliance exported" + echo >&2 "Reattaching shared folders" + local ii=0 + for node in $nodes; do + if [ -n "${share_paths[$ii]}" ]; then + vm_add_share "$node" "$SHARE_DIR" "$SHARE_NAME" + fi + ii=$(($ii + 1)) + done fi } export_appliance