2023-01-31 21:18:59 -08:00
{{- if ne .host.distro.family "windows" -}}
#!/usr/bin/env bash
2023-04-11 20:26:25 -07:00
# @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.
2023-01-31 21:18:59 -08:00
{{ includeTemplate "universal/profile" }}
{{ includeTemplate "universal/logg" }}
2023-01-31 23:04:55 -08:00
### Run logic if VirtualBox is installed
2023-01-31 21:18:59 -08:00
if command -v VirtualBox > /dev/null; then
2023-02-01 14:30:02 -08:00
### Install VirtualBox extension pack if it is not installed already
2023-05-29 19:28:25 -07:00
if [ ! -d /usr/lib/virtualbox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack ] && [ ! -d /Applications/VirtualBox.app/Contents/MacOS/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack ]; then
2023-01-31 23:04:55 -08:00
logg info 'Acquiring VirtualBox version information'
VBOX_VERSION="$(VirtualBox --help | head -n 1 | cut -f 6 -d' ')"
VBOX_VERSION=" ${ VBOX_VERSION / / v } "
### Set up folders
2023-05-29 19:28:25 -07:00
# 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
2023-01-31 23:04:55 -08:00
mkdir -p /tmp/vbox
2023-01-31 21:18:59 -08:00
cd /tmp/vbox
2023-01-31 23:04:55 -08:00
### Download extension pack
logg info 'Downloading VirtualBox extension pack'
curl -sSL https://download.virtualbox.org/virtualbox/ $ VBOX_VERSION /Oracle_VM_VirtualBox_Extension_Pack- $ VBOX_VERSION . vbox -extpack \
2023-06-14 18:10:55 -07:00
-o /tmp/vbox/Oracle_VM_VirtualBox_Extension_Pack- $ VBOX_VERSION . vbox -extpack || logg error 'Failed to download the VirtualBox extension pack so the extension pack installation will be skipped'
2023-01-31 23:04:55 -08:00
### Install extension pack
2023-06-14 18:10:55 -07:00
if [ -f /tmp/vbox/Oracle_VM_VirtualBox_Extension_Pack- $ VBOX_VERSION . vbox -extpack ]; then
logg info 'Installing VirtualBox extension pack'
echo 'y' | sudo VBoxManage extpack install --replace /tmp/vbox/Oracle_VM_VirtualBox_Extension_Pack- $ VBOX_VERSION . vbox -extpack
logg success 'Successfully installed VirtualBox extension pack'
fi
2023-02-01 14:30:02 -08:00
else
logg info 'VirtualBox Extension pack is already installed'
fi
2023-01-31 21:18:59 -08:00
else
2023-06-14 00:22:59 -07:00
logg info 'VirtualBox is not installed so VirtualBox Extension pack will not be installed'
2023-01-31 21:18:59 -08:00
fi
{{ end -}}