2024-05-04 21:05:33 -07:00
#!/usr/bin/env bash
# @file VirtualBox Extension Pack
# @brief Ensures the VirtualBox extension pack is installed.
# @description
# This script ensures the VirtualBox extension pack that corresponds with VirtualBox's version is properly installed.
2024-05-27 20:45:14 -07:00
set -Eeuo pipefail
2024-05-27 20:50:11 -07:00
trap "gum log -sl error 'Script encountered an error!'" ERR
2024-05-27 04:15:03 -07:00
2024-05-04 21:05:33 -07:00
### Run logic if VirtualBox is installed
if command -v VirtualBox > /dev/null; then
### Install VirtualBox extension pack if it is not installed already
if [ ! -d /usr/lib/virtualbox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack ] && [ ! -d /Applications/VirtualBox.app/Contents/MacOS/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack ] ; then
2024-05-27 20:50:11 -07:00
gum log -sl info 'Acquiring VirtualBox version information'
2024-05-04 21:05:33 -07:00
VBOX_VERSION = " $( VirtualBox --help | head -n 1 | cut -f 6 -d' ' ) "
VBOX_VERSION = " ${ VBOX_VERSION //v } "
### Set up folders
# Check for macOS installation before creating ExtensionPacks folder on Linux machines
if [ ! -d /Applications/VirtualBox.app ] ; then
sudo mkdir -p /usr/lib/virtualbox/ExtensionPacks
fi
mkdir -p /tmp/vbox
cd /tmp/vbox
### Download extension pack
2024-05-27 20:50:11 -07:00
gum log -sl info 'Downloading VirtualBox extension pack'
curl -sSL https://download.virtualbox.org/virtualbox/$VBOX_VERSION /Oracle_VM_VirtualBox_Extension_Pack-$VBOX_VERSION .vbox-extpack -o /tmp/vbox/Oracle_VM_VirtualBox_Extension_Pack-$VBOX_VERSION .vbox-extpack || gum log -sl error 'Failed to download the VirtualBox extension pack so the extension pack installation will be skipped'
2024-05-04 21:05:33 -07:00
### Install extension pack
if [ -f /tmp/vbox/Oracle_VM_VirtualBox_Extension_Pack-$VBOX_VERSION .vbox-extpack ] ; then
2024-05-27 20:50:11 -07:00
gum log -sl info 'Installing VirtualBox extension pack'
2024-05-04 21:05:33 -07:00
echo 'y' | sudo VBoxManage extpack install --replace /tmp/vbox/Oracle_VM_VirtualBox_Extension_Pack-$VBOX_VERSION .vbox-extpack
2024-05-27 23:55:42 -07:00
gum log -sl info 'Successfully installed VirtualBox extension pack'
2024-05-04 21:05:33 -07:00
fi
else
2024-05-27 20:50:11 -07:00
gum log -sl info 'VirtualBox Extension pack is already installed'
2024-05-04 21:05:33 -07:00
fi
else
2024-05-27 20:50:11 -07:00
gum log -sl info 'VirtualBox is not installed so VirtualBox Extension pack will not be installed'
2024-05-04 21:05:33 -07:00
fi