#!/bin/bash # Initial/Upgrade VirtualBox # if [ "$UID" -ne 0 ] then echo "This script should be run as root." exit 1 fi # # Source config file if [ ! -f ~/.vbconfig ]; then echo "Config File ~/.vbconfig not found!" echo "Either you have not done a sudo from the VB user or not run set-folders" echo "Run: set-folders to create .vbconfig" exit 1 fi . ~/.vbconfig # echo "Edit file to update for correct/recent:" echo " (1) Version and Distribution" echo " (2) Extension pack URL" echo " (3) Guest Additions URL - to be installed on Guest" echo " (4) User id for Virtual Machines" echo "Shell Variables are: VB_VERSION, (DEB_DIST), EXT_PACK_URL, GUEST_ADD_URL, VB_USER_ID" echo read -p "Press [Enter] key to start or Ctrl-C to break and update script ..." # # VB Version to be installed (using aptitude) VB_VERSION="virtualbox-4.3" # # Check if VirtualBox is already installed VB_INSCHK=`aptitude search $VB_VERSION | grep -c "i...${VB_VERSION}"` if [ $VB_INSCHK -gt 0 ]; then echo "VirtualBox install detected. VirtualBox will be upgraded." echo "Please shutdown all VMs before proceeding." read -p "Press [Enter] key to continue or Ctrl-C to break to shutdown VMs first ..." fi # # Debian-based Linux distributions # Trusty example below - CHANGE if required DEB_DIST="deb http://download.virtualbox.org/virtualbox/debian trusty contrib" # # Version 4.3.20 example below - CHANGE # The new version # will depend on version for base install (above) EXT_PACK_URL="http://download.virtualbox.org/virtualbox/4.3.20/Oracle_VM_VirtualBox_Extension_Pack-4.3.20.vbox-extpack" EXT_PACK_FILE=$(basename $EXT_PACK_URL) # # GuestAdditions # Update URL for latest version # URL to follow version # of base and extension pack - CHANGE GUEST_ADD_URL="http://download.virtualbox.org/virtualbox/4.3.20/VBoxGuestAdditions_4.3.20.iso" GUEST_ADD_FILE=$(basename $GUEST_ADD_URL) # # Define the Designated VB User read -e -p "Enter VM User : " -i "$SUDO_USER" VB_USER_ID # echo "Check settings ... " echo "VirtualBox Version : $VB_VERSION" echo "Debian Distribution: $DEB_DIST" echo "Extension pack URL : $EXT_PACK_URL" echo "Guest Addition URL : $GUEST_ADD_URL" echo "VirtualBox User Id : $VB_USER_ID " read -p "Press [Enter] key to continue or Ctrl-C to break and update variables ..." # echo echo "Including Debian-based Linux distributions in apt sources" read -p "Press [Enter] key to continue or Ctrl-C to break ..." # Include Debian-based Linux distributions CHK_DEBAPT=`grep -c "$DEB_DIST" /etc/apt/sources.list` if [ "$CHK_DEBAPT" -eq 0 ] then echo $DEB_DIST >> /etc/apt/sources.list else echo "Debian-based Linux distributions already included. Proceeding ..." fi # echo echo "Including Oracle public key for apt-secure" read -p "Press [Enter] key to continue or Ctrl-C to break ..." # Oracle public key for apt-secure # Ok to run again even if already completed wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc \ -O- | sudo apt-key add - # echo echo "Updating apt, OS and installing dkms" read -p "Press [Enter] key to continue or Ctrl-C to break ..." aptitude update #aptitude upgrade #aptitude dist-upgrade # May be required sometimes aptitude -y install dkms # echo echo "Downloading extension pack" read -p "Press [Enter] key to continue or Ctrl-C to break ..." # Download extension pack to the DVD folder if [ -f $VB_DVD_LOC/$EXT_PACK_FILE ]; then echo "Download already exists. Skipping ..." else cd $VB_DVD_LOC wget "$EXT_PACK_URL" fi # echo echo "Downloading Guest Additions" read -p "Press [Enter] key to continue or Ctrl-C to break ..." # Download Guest Additions to the DVD folder if [ -f $VB_DVD_LOC/$GUEST_ADD_FILE ]; then echo "Download already exists. Skipping ..." else cd $VB_DVD_LOC wget "$GUEST_ADD_URL" fi # echo echo "Installing VirtualBox using aptitude" echo "Follow the aptitude prompts to complete install" read -p "Press [Enter] key to continue or Ctrl-C to break ..." # aptitude install $VB_VERSION # echo echo "Completed install of VirtualBox" echo echo "Installing (or replace) Extension Pack" read -p "Press [Enter] key to continue or Ctrl-C to break ..." VBoxManage extpack install --replace $EXT_PACK_FILE # # Assign VB user to vboxusers group echo Assign VB user $VB_USER_ID to vboxusers group usermod -a -G vboxusers $VB_USER_ID # echo "VirtualBox install completed! If this is the initial install Run 'set-machine-folder' script as ${VB_USER_ID} " # exit