CentOS 6
If you’re like me, you like testing software in a virtual machine, before committing it to your live system. That’s what I do with Oracle’s VirtualBox. Something you might have noticed is that the VirtualBox yum repository doesn’t work all that well with CentOS, (as it’s not really for CentOS in the first place). At least, that was the case for me. The manual way of keeping your VirtualBox and the extension pack installation is more annoying than it is anything else.
After searching for an automated way to perform updates, that didn’t demand my complete attention, and seeing that a lot of other users were looking for something that would do similar, I wrote this little script which, only requires you browse the download site with your browser and identify the major, minor and release numbers of the version you’re looking to get. That’s easy enough to do by just hovering your mouse over the link of the VirtualBox version you want. Run this script in a terminal window, plug-in the major, minor and release numbers when prompted, then go back to work while the script downloads and installs an updated VirtualBox for you. The script is heavily commented so it’s clear what I’m doing and why. Be sure to watch those end-of-lines. They might be wrapped in your browser. Check them carefully.
Anyhow, not meaning to be pragmatic, this little script works for me. Saves time. If it’s useful to you too, Dear Reader, then you’ve discovered why I posted it.
Just copy & paste the following into an ed or nano session (yeah, you can use vi, but only if you have six arms with three hands on each one), save the buffer as "InstallVirtualBox.sh", or whatever name you prefer, apply execute permissions and that’s it.
.
#!/bin/sh
#---------------------------------------------------------|
# |
# Install new VirtualBox version. |
# |
# This script will download and install both VirtualBox |
# and the corresponding extension pack into /opt |
# |
# This script assumes that the directory "/opt" exists, |
# and that the user has sufficient "sudo" privileges. |
# |
#---------------------------------------------------------|
# Initialize variables
MAJOR=
MINOR=
RELEASE=
VERSION=
VBOXDOWNLOAD=
#
# Gather version information
#
echo VirtualBox and Extension Pack Installer
echo Enter VirtualBox Major '(as in 5):'
read MAJOR
echo Enter Minor number '(as in 0.2):'
read MINOR
echo Enter Release number '(as 102096):'
read RELEASE
#
# Assign version for downloads
#
VERSION=$MAJOR.$MINOR-$RELEASE
VBOXDOWNLOAD="VirtualBox-$VERSION-Linux_x86.run"
#
# Wait for user to give the okay signal.
echo Press ENTER to download $VBOXDOWNLOAD
read
#
# Check to see if the requested file exists. If it does,
# skip the download/compile/install operation.
#
if ! test -f $VBOXDOWNLOAD
then
echo Downloading $VBOXDOWNLOAD
wget http://download.virtualbox.org/virtualbox/"$MAJOR.$MINOR"/"$VBOXDOWNLOAD"
chmod +x $VBOXDOWNLOAD
sudo ./$VBOXDOWNLOAD
echo Press ENTER to download Oracle_VM_VirtualBox_Extension_Pack-$VERSION.vbox-extpack
read
else
echo File Exists ... Skipping
fi
#
# Inform the user of the next operation and wait for the okay signal.
#
echo Press ENTER to download and install the Extension Pack
read
#
# Check to see if the requested file exists. If it does,
# skip the download/compile/install operation.
#
if ! test -f Oracle_VM_VirtualBox_Extension_Pack-$VERSION.vbox-extpack
then
wget http://download.virtualbox.org/virtualbox/"$MAJOR"."$MINOR"/Oracle_VM_VirtualBox_Extension_Pack-"$VERSION".vbox-extpack
sudo VBoxManage extpack install --replace ./Oracle_VM_VirtualBox_Extension_Pack-$VERSION.vbox-extpack
else
echo File Exists ... Skipping
fi
# VirtualBox and it's Extension Pack have been downloaded and installed.
# Let the user know all went well.
#
echo Operations successful. VirtualBox is ready to run