PDA

View Full Version : Oracle VirtualBox installation script



glennzo
24th January 2015, 11:36 AM
There are many threads here detailing the troubles that Fedora users have installing VirtualBox. It shouldn't be that difficult, and it really isn't.

My personal preference is to use the RPM from Oracle. It has worked extremely well for me for several years now.

In an effort to help Fedora users install Oracle VirtualBox and the Oracle VirtualBox Extension Pack under Fedora 20 and 21, i686 and x86_64, I've written a bash script.

I've spent about a week on this, testing and tweaking until the output and the results were just so. I've test run this script probably 100 times under Fedora 20 and 21 virtual machines and am completely confident in the results.

Truth be told, the script will work for releases older than 20 too with a small change in the code.

Give it a try if you wish. If you do, please let me know how it worked for you.

Comments and suggestions always welcome. Just be nice :)


#!/bin/bash
# 21_oracle_virtualbox.sh
# Install and configure the Oracle version of VirtualBox for Fedora 20 and later.
# Install the Oracle VirtualBox Extension Pack.

# Glenn A. Johnson
# Started January 18, 2015
# Updated January 24, 2015

<< COMMENT
DNF for Fedora 21 and up, yum for earlier releases
What if Fedora version of VirtualBox is already installed, failed or not? VirtualBox-4.3.20-3.fc20.x86_64 - kmod-VirtualBox-3.17.7-200.fc20.x86_64-4.3.20-1.fc20.4.x86_64
COMMENT

# Variables
# Additional packages usually needed for a successful install of VirtualBox
packfiles="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 dkms wget SDL"

# At some point, when Oracle releases an updated RPM, these variables will need to be changed.
vbox_source_file="VirtualBox-4.3-4.3.20_96996_fedora18-1."`uname -m`".rpm"
vbox_ext_source="Oracle_VM_VirtualBox_Extension_Pack-4.3.20-96996.vbox-extpack"

# Need root permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
echo -e $(tput bold)$(tput setaf 7)"You're going to need root permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\""$(tput sgr0)
exit 0
fi

# Release 20 and later only
function get_release()
{
printf $(tput setaf 2)"Checking Fedora release version... "$(tput sgr0)
rel_num=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $rel_num < "20" ]] ; then
printf $(tput setaf 1)"\nThis script is for Fedora release 20 and later only.\nThis appears to be Fedora $rel_num.\n"$(tput sgr0)
exit 0
else printf $(tput bold)$(tput setaf 2)" ✓"$(tput sgr0)
fi
echo
}

# Clear screen and print a banner
function banner()
{
clear
printf $(tput bold)$(tput setaf 2)"VirtualBox installation script for Fedora 20 and up\n"$(tput sgr0)
printf $(tput bold)$(tput setaf 2)"Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$(tput sgr0)
}

# Remove Oracle source files if they exist
function remove_source()
{
for i in $vbox_source_file $vbox_ext_source ; do
rm -f $i
done
}

# Remove Fedora VirtualBox. This will remove kmod-VirtualBox also.
function remove_fed_vbox()
{
vbox_installed=$(rpm -qa | grep VirtualBox)
if [[ $vbox_installed ]] ; then
printf $(tput bold)$(tput setaf 2)"Removing Fedora version of VirtualBox. Please wait..."$(tput sgr0)
yum -y -q erase VirtualBox
printf $(tput setaf 2)"\nDone.\n"$(tput sgr0)
fi
}

# Install the downloaded source RPM from Oracle
function install_source()
{
if [[ -f $vbox_source_file ]] ; then
printf $(tput setaf 2)"Installing Oracle VirtualBox\n"$(tput sgr0)
rpm -Uvh $vbox_source_file
else
echo $(tput bold)$(tput setaf 1)"Source file missing."$(tput sgr0)
exit 0
fi
}

# Get any necessary packages needed to complete the VirtualBox installation without errors
function get_packages()
{
echo -e -n $(tput setaf 2)"Checking for necessary packages..."$(tput sgr0)
echo
newpkgs=""
for i in $packfiles ; do
echo -e -n $(tput setaf 2)"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
echo $(tput bold)$(tput setaf 2)"✓"$(tput sgr0)
else
echo $(tput bold)$(tput setaf 1)"✗"$(tput sgr0)
newpkgs="${newpkgs} $i"
fi
done
if [ -n "${newpkgs}" ]; then
echo -e -n $(tput setaf 2)"==> Installing ${newpkgs}... "$(tput sgr0)
yum -y -q install ${newpkgs}
echo -e $(tput setaf 2)"\nDone installing packages.\n"$(tput sgr0)
else
echo $(tput setaf 2)"==> $(tput bold)Nothing new to install."$(tput sgr0)
fi
}

# Get the VirtualBox source RPM from Oracle
function get_source()
{
echo -e -n $(tput setaf 2)"Getting VirtualBox source from the Oracle download site..."$(tput sgr0)
case `uname -m` in
i386) vbox_source="http://download.virtualbox.org/virtualbox/4.3.20/VirtualBox-4.3-4.3.20_96996_fedora18-1.i686.rpm" ;;
i686) vbox_source="http://download.virtualbox.org/virtualbox/4.3.20/VirtualBox-4.3-4.3.20_96996_fedora18-1.i686.rpm" ;;
x86_64) vbox_source="http://download.virtualbox.org/virtualbox/4.3.20/VirtualBox-4.3-4.3.20_96996_fedora18-1.x86_64.rpm" ;;
esac
remove_source
wget -q $vbox_source
echo -e $(tput bold)$(tput setaf 2)" ✓"$(tput sgr0)
echo -e -n $(tput setaf 2)"Getting the VirtualBox Extension Pack source file..."$(tput sgr0)

wget -q http://download.virtualbox.org/virtualbox/4.3.20/$vbox_ext_source
echo -e $(tput bold)$(tput setaf 2)" ✓"$(tput sgr0)
echo
}

function install_extpack()
{
if [[ -f $vbox_ext_source ]] ; then
echo $(tput setaf 2)"Installing Oracle VirtualBox extension pack"$(tput sgr0)
VBoxManage extpack install --replace $vbox_ext_source
else
echo $(tput setaf 2)"Trying to install the Oracle VirtualBox extension pack but can't find the source file!"$(tput sgr0)
fi
}

function script_complete()
{
remove_source
printf $(tput bold)$(tput setaf 2)"Script run complete.\n"$(tput sgr0)
}

function script_cancel()
{
tput cuu1
tput el
printf $(tput setaf 2)"Script cancelled.\n"$(tput sgr0)
}

function query_user()
{
clear
banner
printf $(tput setaf 2)"\nFor this script to succeed you need to be running the newest available and installed kernel.\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system.\n"$(tput sgr0)
printf $(tput bold)$(tput setaf 2)"Shall we continue? <y/n> "$(tput sgr0)
read yn
case $yn in
y) get_release
remove_source
#remove_fed_vbox
get_packages
get_source
install_source
install_extpack
script_complete
;;

n) echo $(tput setaf 2)"Update your system and reboot into the newest kernel. Then revisit this script."$(tput sgr0)
exit 0
;;
*) script_cancel
exit 0
;;
esac
}
query_user

sea
24th January 2015, 04:07 PM
Heya Glennzo

Cant try your script atm, for obvious reasons, but will do tomorrow or monday :)

For easier maintainance of the script, i'd recomend to set some values as variables:

VB_REL_VER="4.3-4.3.20_96996"
VB_REL_DIST="fedora18-1."

So your code (this example) would look like:

# At some point, when Oracle releases an updated RPM, these variables will need to be changed.
vbox_source_file="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
vbox_ext_source="Oracle_VM_VirtualBox_Extension_Pack-${VB_REL_VER}.vbox-extpack"
NOTE: Those { brackets are required, specialy for the first one, otherwise it would take the 'connecting' underscore as part of the Name, this way it knows the variablename had ended.

You have reused the hardcoded version number of VB and release distro version of fedora quite a few times.
If you set them as a variable, you just need to change this, and not all XY occourences in the script.
Once done, its simpler to do than using sed for each version change.

Hope this helps

glennzo
24th January 2015, 04:44 PM
Thanks for the tips Sea. They make a lot of sense. I'll incorporate them into the script.

Dangermouse
24th January 2015, 06:40 PM
Hi Glenn,

had a quick look, does it work for a PAE kernel as well (not that its used much now)

marko
24th January 2015, 08:45 PM
I use code like this to get fancy so I don't have to edit the script as the user updates by putting a new source file in with the script, I assume the usage mode is that the new file(s) are put in the directory with the script and only the new files. They should remove the previous one. The count test detects that the filename isn't single valued and echoes an error.
I use a glob to get the current exact filename by using find with the glob pattern. The goal is that the 'glob' is a
pattern that's going to be sticked to, you try to make it selective enough so it's very unlikely a file will be in the directory that
would match by accident.


#!/bin/bash
.... other code...

# change this for format changes if needed
VBOX_SRC_GLOB="VirtualBox-*."`uname -m`".rpm"


vbox_source_file=`/usr/bin/find . -mindepth 1 -maxdepth 1 -type f -name "$VBOX_SRC_GLOB"`
source_words=( $vbox_source_file )
source_count=${#source_words[@]}

if [ "$source_count" -ne 1 ]; then
echo "ERROR multiple source files in install directory"
echo "remove previous file(s) and re-run"
exit 1
fiAnother comment, be careful with the 'tput' fanciness, I have a customer I have to deal with, their programmers went crazy with tput in one of their
scripts. It messes up the terminal when I try to use their script. I suspect it's a bad reaction with the TERM setting we use and they didn't save off the terminal settings at the beginning of the script to set it back to the way it was at the end.

The terminal is corrupted after the script exits and it's not back to normal until I manually do a "clear". What I did to work around that (I don't want to edit their script the many dozens of tput's every time I update their file), is to set my terminal to ansi-mono which blocks all tput color settings, then I run their script:

export TERM='ansi-mono'
run script...

glennzo
24th January 2015, 09:22 PM
@Dangermouse. Not sure about the PAE thing. Don't have a virtual machine running that kernel, at least not at the moment. Good point though.

@ marko. I'm all about how the script looks. The least important factor.

Let's try this with no color changes at all and I'll incorporate some of the other suggestions here too. Later though, not enough time right now.

zuser
24th January 2015, 10:26 PM
As a coincidence, I only decided to install VirtualBox this morning. I have no prior experience with virtual machines. Installed from the Fedora repos and it took several tries to get it running, but it seemed ok with one virtual machine installed.

After finding this post, copied the script above and glad to say it ran perfectly replacing repo version with latest from oracle. My system is F21_64 bit with KDE.

Thanks for that.

glennzo
24th January 2015, 10:28 PM
Updated code, better variables (not perfect), no color. Still needs work but it still works.


#!/bin/bash
# 2_oracle_virtualbox.sh

# Glenn A. Johnson
# Started January 24, 2015
# Updated January 24, 2015

# Variables
# Additional packages usually needed for a successful install of VirtualBox
PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 dkms wget SDL"

# At some point, when Oracle releases an updated RPM, these variables will need to be changed.
VBOX_SOURCE_FILE="VirtualBox-4.3-4.3.20_96996_fedora18-1.`uname -m`.rpm"
VBOX_EXT_SOURCE="Oracle_VM_VirtualBox_Extension_Pack-4.3.20-96996.vbox-extpack"

# Need root permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
echo -e "You're going to need root permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\""
exit 0
fi

# Release 20 and later only
function get_release()
{
clear
printf "Checking Fedora release version... "
REL_NUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $REL_NUM < "20" ]] ; then
printf "\nThis script is for Fedora release 20 and later only.\nThis appears to be Fedora $REL_NUM.\n"
exit 0
else printf " ✓"
fi
echo
}

# Clear screen and print a banner
function banner()
{
clear
printf "VirtualBox installation script for Fedora 20 and up\n"
printf "Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"
}

# Remove Oracle source files if they exist
function remove_source()
{
for i in $VBOX_SOURCE_FILE $VBOX_EXT_SOURCE ; do
rm -f $i
done
}

# Remove Fedora VirtualBox. This will remove kmod-VirtualBox also.
function remove_fed_vbox()
{
vbox_installed=$(rpm -qa | grep VirtualBox)
if [[ $vbox_installed ]] ; then
printf "Removing Fedora version of VirtualBox. Please wait..."
yum -y -q erase VirtualBox
printf "\nDone.\n"
fi
}

# Get any necessary packages needed to complete the VirtualBox installation without errors
function get_packages()
{
echo -e -n "Checking for necessary packages..."
echo
newpkgs=""
for i in $PACKFILES ; do
echo -e -n "==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
echo "✓"
else
echo "✗"
newpkgs="${newpkgs} $i"
fi
done
if [ -n "${newpkgs}" ]; then
echo -e -n "==> Installing ${newpkgs}... "
yum -y -q install ${newpkgs}
echo -e "\nDone installing packages.\n"
else
echo "==> Nothing new to install."
fi
}

# Get the VirtualBox source RPM from Oracle
function get_source()
{
echo -e -n "Getting VirtualBox source from the Oracle download site..."
remove_source
wget -q http://download.virtualbox.org/virtualbox/4.3.20/$VBOX_SOURCE_FILE
echo -e " ✓"
echo -e -n "Getting the VirtualBox Extension Pack source file..."
wget -q http://download.virtualbox.org/virtualbox/4.3.20/$VBOX_EXT_SOURCE
echo -e " ✓"
echo
}

# Install the downloaded source RPM from Oracle
function install_source()
{
if [[ -f $VBOX_SOURCE_FILE ]] ; then
printf "Installing Oracle VirtualBox\n"
rpm -Uvh $VBOX_SOURCE_FILE
else
echo "Source file missing."
exit 0
fi
}

function install_extpack()
{
if [[ -f $VBOX_EXT_SOURCE ]] ; then
echo "Installing Oracle VirtualBox extension pack"
VBoxManage extpack install --replace $VBOX_EXT_SOURCE
else
echo "Trying to install the Oracle VirtualBox extension pack but can't find the source file!"
fi
}

function script_complete()
{
remove_source
printf "Script run complete.\n"
}

function script_cancel()
{
tput cuu1
tput el
printf "Script cancelled.\n"
}

function query_user()
{
clear
banner
printf "\nFor this script to succeed you need to be running the newest available and installed kernel.\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system.\n"
printf "Shall we continue? <y/n> "
read yn
case $yn in
y) get_release
remove_source
#remove_fed_vbox
get_packages
get_source
install_source
install_extpack
script_complete
;;

n) script_cancel
exit 0
;;
*) script_cancel
exit 0
;;
esac
}
query_user

glennzo
25th January 2015, 10:46 AM
As a coincidence, I only decided to install VirtualBox this morning. I have no prior experience with virtual machines. Installed from the Fedora repos and it took several tries to get it running, but it seemed ok with one virtual machine installed.

After finding this post, copied the script above and glad to say it ran perfectly replacing repo version with latest from oracle. My system is F21_64 bit with KDE.

Thanks for that.

That's good news! I happy to hear that the script was a useful tool for someone.

Skull One
25th January 2015, 12:38 PM
Since you can assign the 'tput' output to variables, you can easily remove the colors as an option. Here an example (example.sh):


#!/bin/bash

# Color definitions; the variables are null it the option NOCOLOR is set
if [ -z "$NOCOLOR" ]; then
OK=$(tput bold;tput setaf 2)
ERR=$(tput bold;tput setaf 1)
RST=$(tput sgr0)
else
OK=
ERR=
RST=
fi
# end of color definitions

echo -en "[ ${ERR}Error${RST} ]"
echo -e "[ ${OK}OK${RST} ]"


Usage with colors:
example.sh
and without:
NOCOLOR=1 example.sh

glennzo
25th January 2015, 12:51 PM
Since you can assign the 'tput' output to variables, you can easily remove the colors as an option. Here an example (example.sh):


#!/bin/bash

# Color definitions; the variables are null it the option NOCOLOR is set
if [ -z "$NOCOLOR" ]; then
OK=$(tput bold;tput setaf 2)
ERR=$(tput bold;tput setaf 1)
RST=$(tput sgr0)
else
OK=
ERR=
RST=
fi
# end of color definitions

echo -en "[ ${ERR}Error${RST} ]"
echo -e "[ ${OK}OK${RST} ]"


Usage with colors:
example.sh
and without:
NOCOLOR=1 example.sh

Interesting. I like that and might just try adding it to my script. Thanks Skull One.

rich1974
25th January 2015, 01:12 PM
thanx man.....great job!
i just installed virtual box. previously i have had virtual box from fedora and i had to remove it since my first attempt to install, over fedora version, has failed.
thanx again!

glennzo
25th January 2015, 01:13 PM
thanx man.....great job!
i just installed virtual box. previously i have had virtual box from fedora and i had to remove it since my first attempt to install, over fedora version, has failed.
thanx again!

Sweet! 2 for 2! Glad the script worked as expected.

glennzo
25th January 2015, 02:59 PM
Just as info, seems that there is a problem with forum attachments so I can't upload a tar file, hence the full script.

MadmanRB
25th January 2015, 03:08 PM
Just seems odd that virtualbox is this hard to install, sure we have gnome boxes but boxes isnt that good IMHO

glennzo
25th January 2015, 03:10 PM
Just seems odd that virtualbox is this hard to install, sure we have gnome boxes but boxes isnt that good IMHO

I not so sure that it's hard to install, I think some users just don't fully understand what needs to be done for a successful install.

MadmanRB
25th January 2015, 03:15 PM
Eh even I had issues and I am not entirely new to Fedora, the only other distro that I had this much trouble with virtualbox is Arch.

rich1974
25th January 2015, 03:17 PM
is not that hard, the problem is that the virtualbox from fedora repository got broken when they update the kernel to 3.17.8-300.fc21.i686. using the previous kernel, it works okay!

the problem with this script is that it would have to be updated once the oracle release a new build of virtualbox.
also, this thread would be good to be pinned.

MadmanRB
25th January 2015, 03:23 PM
It also happened on my 64bit build too, still an odd issue.

glennzo
25th January 2015, 10:45 PM
Script updated. Now Fedora 18 and 19 friendly. Of course, that wasn't too difficult :)


#!/bin/bash
# 21_oracle_virtualbox.sh

# Install and configure the Oracle version of VirtualBox for Fedora 19 and later.
# Install the Oracle VirtualBox Extension Pack.

# Glenn A. Johnson
# Started January 18, 2015
# Updated January 25, 2015

# A tip of the fedora to Fedora Forum members Sea, Skull One, marko, Dangermouse

<< COMMENT
The idea behind this script is to install Oracle VirtualBox and the Oracle VirtualBox Extension Pack for Fedora systems.
The script will detect and remove any installed version of Fedora VirtualBox.
It will clean up when finished by removing downloaded source files.
It will use DNF for Fedora 21 and up, yum otherwise.
Supports color / no color.

Does this script handle PAE kernel? Not yet.

Guest additions need kernel-devel-$(uname -r) and gcc
COMMENT

# Variables
# Additional packages usually needed for a successful install of VirtualBox
packfiles="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 dkms wget SDL"

# At some point, when Oracle releases an updated RPM, these variables will need to be changed.
vbox_src_file="VirtualBox-4.3-4.3.20_96996_fedora18-1.`uname -m`.rpm"
vbox_ext_src="Oracle_VM_VirtualBox_Extension_Pack-4.3.20-96996.vbox-extpack"

# Color definitions; the variables are null if the option NOCOLOR is set
# Thanks Skull One!
if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 2)
OK=$(tput setaf 2)
ERR=$(tput bold;tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERR=
RST=
fi

# Need root permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
echo -e "You're going to need root permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\""
exit 0
fi

# Release 19 and later only
function get_release()
{
printf $OK"Checking Fedora release version... "$RST
relnum=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $relnum < "18" ]] ; then
printf $ERR"\nThis script is for Fedora release 18 and later only.\nThis appears to be Fedora release $relnum.\n"$RST
exit 0
else printf $OKB" ✓"$RST
# Determine if we're going to use dnf or yum.
if [[ $relnum < "21" ]] ; then
install_with="yum"
else
install_with="dnf"
fi
fi
echo
}

# Clear screen and print a banner
function banner()
{
clear
printf $OKB"==> VirtualBox installation script for Fedora 18 and up.\n"$RST
printf $OKB"==> Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
}

# Remove Oracle VirtualBox source files if they exist
function remove_source()
{
for i in $vbox_src_file $vbox_ext_src ; do
rm -f $i
done
}

# Remove any installed version of VirtualBox
function remove_fed_vbox()
{
vbox_installed=$(rpm -qa | grep VirtualBox)
if [[ $vbox_installed ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
$install_with -y -q erase $vbox_installed 2>/dev/null
printf $OK"\nDone.\n"$RST
fi
}

# Install the downloaded source RPM from Oracle
function install_source()
{
if [[ -f $vbox_src_file ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $vbox_src_file
else
echo $ERR"Source file missing."$RST
exit 0
fi
}

# Get any necessary packages needed to complete the VirtualBox installation without errors
function get_packages()
{
echo -e -n $OK"Checking for necessary packages..."$RST
echo
newpkgs=""
for i in $packfiles ; do
echo -e -n $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
echo $OKB"✓"$RST
else
echo $ERR"✗"$RST
newpkgs="${newpkgs} $i"
fi
done
if [ -n "${newpkgs}" ]; then
echo -e -n $OK"==> Installing ${newpkgs}... "$RST
$install_with -y -q install ${newpkgs} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
echo $OKB"==> Nothing new to install."$RST
fi
}

# Get the VirtualBox source RPM from Oracle
function get_source()
{
echo -e -n $OK"Getting VirtualBox source from the Oracle download site..."$RST
remove_source
wget -q http://download.virtualbox.org/virtualbox/4.3.20/$vbox_src_file
echo -e $OKB" ✓"$RST
echo -e -n $OK"Getting the VirtualBox Extension Pack source file..."$RST
wget -q http://download.virtualbox.org/virtualbox/4.3.20/$vbox_ext_src
echo -e $OKB" ✓"$RST
echo
}

function install_extpack()
{
if [[ -f $vbox_ext_src ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack"$RST
VBoxManage extpack install --replace $vbox_ext_src
else
echo $OK"Trying to install the Oracle VirtualBox extension pack but can't find the source file!"$RST
fi
}

function script_complete()
{
remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

function script_cancel()
{
tput cuu1
tput el
printf $OK"Script cancelled.\n"$RST
}

function menu()
{
clear
banner
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into to newest kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n> "$RST
read yn
case $yn in
y) get_release
remove_source
remove_fed_vbox
get_packages
get_source
install_source
install_extpack
script_complete
;;

n) script_cancel
exit 0
;;
*) script_cancel
exit 0
;;
esac
}
menu

glennzo
27th January 2015, 01:27 AM
I'm open to suggestions if anyone feels that the script can be improved.

So far it has proven useful to a couple Fedora users. Hope it helps a few more.

sea
27th January 2015, 11:30 AM
@ marko. I'm all about how the script looks. ....

Well...
In that case, let me ask, did you like (visualy) my efi-helper script, vhs or alike?
They all use TUI (http://forums.fedoraforum.org/showthread.php?t=302039).

Have a preview of what it (or the single commands) could look like: Screenshots/ (https://sea.fedorapeople.org/review/tui/screenshots/)
The installation is 2 lines: https://github.com/sri-arjuna/tui/wiki/Installation.

I've been asked what TUI is about, its about to help others with the task of making a script with an interface.
For example: tui-download would show how much it already downloaded (eg: 5mb, 1gb) (remember my 'game' script with zak mckracken? you pointed that out ;) )

Hope this helps

glennzo
1st February 2015, 09:53 AM
The latest version of my script. Works for Fedora 18 and up, I686, I686+PAE and x86_64.


#!/bin/bash
# 21_oracle_virtualbox.sh

# Install and configure the Oracle version of VirtualBox for Fedora 20 and later.
# Install the Oracle VirtualBox Extension Pack.
# Handle all platforms, i686, PAE and x86_64 .
# Clean up when finished.
# Use DNF for Fedora 21 and up, YUM for Fedora 20 and earlier.
# Remove previously installed VirtualBox.
# Support color / no color (sudo NOCOLOR=1 21_oracle_virtualbox.sh)

# Glenn A. Johnson
# Started January 18, 2015
# Updated February 27, 2015

# 02.25.15 - Betterer code to discover kernel arch.
# 02.23.15 - New code to discover kernel arch
# 02.22.15 - Seems that kernel arch discovery is not working.
# 02.21.15 - New version of VirtualBox

# A tip of the fedora to Fedora Forum members Sea, Skull One, marko, Dangermouse
# for help with code

# Variables - Additional packages usually needed for a successful install of VirtualBox
# over the different platforms, x86_64, i686 and i686+PAE
#PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"

# Determine OS platform and install correct packages.
getvers=$(uname -r | grep "PAE")
if [[ $getvers ]] ; then
PACKFILES="kernel-PAE-devel gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"
else
PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"
fi

# We can easily make changes to the source file versions by changing
# a few variables below.

VB_REL_VER="4.3-4.3.22_98236"
VB_EXT_VER="4.3.22-98236"
VB_REL_DIST="fedora18-1"
VBOX_SRC_FILE="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
VBOX_EXT_SRC="Oracle_VM_VirtualBox_Extension_Pack-${VB_EXT_VER}.vbox-extpack"
SRC_PATH="http://download.virtualbox.org/virtualbox/4.3.22"
#http://download.virtualbox.org/virtualbox/4.3.22/VirtualBox-4.3-4.3.22_98236_fedora18-1.i686.rpm

# Color definitions; the variables are null if the option NOCOLOR is set.
# Thanks Skull One!

if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 6)
OK=$(tput setaf 6)
ERRB=$(tput bold;tput setaf 1)
ERR=$(tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERRB=
ERR=
RST=
fi

# Need root permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
printf $OK"You're going to need root permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\"\n"$RST
exit 0
fi

# Release 20 and later only
function get_release()
{
printf $OK"Checking Fedora release version... "$RST
RELNUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $RELNUM < "20" ]] ; then
printf $ERR"\nThis script is for Fedora release 20 and later only.\n"$RST
exit 0
else printf $OKB"Fedora $RELNUM ✓"$RST
# Determine if we're going to use dnf or yum.
if [[ $RELNUM < "21" ]] ; then
install_with="yum"
else
install_with="dnf"
fi
fi
echo
}

# Clear screen and print a headline.
function headline()
{
clear
printf $OKB"==> VirtualBox installation script for Fedora 20 and up.\n"$RST
printf $OKB"==> Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
}

# Remove Oracle VirtualBox source files if they exist in the current working directory.
function remove_source()
{
for i in $VBOX_SRC_FILE $VBOX_EXT_SRC ; do
rm -f $i
done
}

# Remove any installed version of VirtualBox.
function remove_fed_vbox()
{
VBOX_INSTALLED=$(rpm -qa | grep VirtualBox)
if [[ $VBOX_INSTALLED ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
$install_with -y -q erase $VBOX_INSTALLED 2>/dev/null
printf $OKB" ✓\n\n"$RST
fi
}

# Install Oracle VirtualBox from the downloaded source RPM.
function install_source()
{
if [[ -f $VBOX_SRC_FILE ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $VBOX_SRC_FILE
else
printf $ERR"The source file missing.\nThere was an error downloading the file.\n"$RST
exit 0
fi
}

# Install the Oracle VirtualBox Extension Pack.
function install_extpack()
{
if [[ -f $VBOX_EXT_SRC ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack."$RST
VBoxManage extpack install --replace $VBOX_EXT_SRC
else
printf $ERR"Oracle VirtualBox extension pack source file missing!\n"$RST
fi
}

# Get any Fedora packages typically needed to complete the VirtualBox installation without errors.
function get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Installing necessary packages$OKB "${NEWPKGS}"... "$RST
#echo "Installing ${NEWPKGS}"
$install_with -y -q install ${NEWPKGS} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
fi
}

# Get the VirtualBox source files from Oracle
function get_source()
{
printf $OK"Getting VirtualBox source from the Oracle download site..."$RST
remove_source
wget -q $SRC_PATH/$VBOX_SRC_FILE
printf $OKB" ✓\n"$RST
printf $OK"Getting the VirtualBox Extension Pack source file..."$RST
wget -q $SRC_PATH/$VBOX_EXT_SRC
printf $OKB" ✓\n"$RST
echo
}

# The script run has completed. Print a short message stating same.
function script_complete()
{
remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

# Script execution has been cancelled by the user.
function script_cancel()
{
tput cuu1
tput el
printf $OK"Script cancelled.\n"$RST
}

# Main script flow
function menu()
{
clear
headline
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into the newest kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n/t> "$RST
read yn
case $yn in
y) get_release
remove_fed_vbox
get_packages
get_source
install_source
install_extpack
script_complete
;;

n) script_cancel
exit 0
;;
# Test menu entry
t) get_release
get_packages
get_source
script_complete
;;

*) script_cancel
exit 0
;;
esac
}
menu

glennzo
27th February 2015, 12:02 PM
Has anyone else tried this script? How well did it work? I've tested it fairly extensively on virtual machines, Fedora 21 and 20, x86_64, i686 and i686+PAE. Feedback would be awesome.

Updated code in post #23 as of today.

Disregard the "test" menu option. I needed something that would do some quick testing without doing the full installation.

glennzo
15th March 2015, 10:46 PM
Minor code updates and tested for Fedora 22 Workstation Alpha x86_64.


#!/bin/bash
# 21_oracle_virtualbox.sh

# Install and configure the Oracle version of VirtualBox for Fedora 20 and later.
# Install the Oracle VirtualBox Extension Pack.
# Handle all platforms, i686, PAE and x86_64 .
# Clean up when finished.
# Use DNF for Fedora 21 and up, YUM for Fedora 20 and earlier.
# Remove previously installed VirtualBox.
# Support color / no color (sudo NOCOLOR=1 21_oracle_virtualbox.sh)

# Glenn A. Johnson
# Started January 18, 2015
# Updated March 15, 2015

# 03.15.15 - Tested under Fedora 22 Workstation Alpha (x86_64).
# 03.14.15 - New VirtualBox version
# 02.25.15 - Betterer code to discover kernel arch.
# 02.23.15 - New code to discover kernel arch
# 02.22.15 - Seems that kernel arch discovery is not working.
# 02.21.15 - New version of VirtualBox

# A tip of the fedora to Fedora Forum members Sea, Skull One, marko, Dangermouse
# for help with code

# Variables - Additional packages usually needed for a successful install of VirtualBox
# over the different platforms, x86_64, i686 and i686+PAE
#PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"

# Determine OS platform and install correct packages.
GETVERS=$(uname -r | grep "PAE")
if [[ $GETVERS ]] ; then
PACKFILES="kernel-PAE-devel gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"
else
PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"
fi

# We can easily make changes to the source file versions by changing
# a few variables below.
VB_REL_VER="4.3-4.3.24_98716"
VB_EXT_VER="4.3.24-98716"
VB_REL_DIST="fedora18-1"
VBOX_SRC_FILE="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
VBOX_EXT_SRC="Oracle_VM_VirtualBox_Extension_Pack-${VB_EXT_VER}.vbox-extpack"
SRC_PATH="http://download.virtualbox.org/virtualbox/4.3.24"

# Color definitions; the variables are null if the option NOCOLOR is set.
# Thanks Skull One!

if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 6)
OK=$(tput setaf 6)
ERRB=$(tput bold;tput setaf 1)
ERR=$(tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERRB=
ERR=
RST=
fi

# Need root permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
printf $OK"You're going to need root permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\"\n"$RST
exit 0
fi

# Release 20 and later only
function get_release()
{
printf $OK"Checking Fedora release version... "$RST
RELNUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $RELNUM < "20" ]] ; then
printf $ERR"\nThis script is for Fedora release 20 and later only.\n"$RST
exit 0
else printf $OKB"Fedora $RELNUM ✓"$RST
# Determine if we're going to use dnf or yum.
if [[ $RELNUM < "21" ]] ; then
install_with="yum"
else
install_with="dnf"
fi
fi
echo
}

# Clear screen and print a headline.
function headline()
{
clear
printf $OK"==>$OKB VirtualBox installation script for Fedora 20 and up.\n"$RST
printf $OK"==>$OKB Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
}

# Remove Oracle VirtualBox source files if they exist in the current working directory.
function remove_source()
{
for i in $VBOX_SRC_FILE $VBOX_EXT_SRC ; do
rm -f $i
done
}

# Remove any installed version of VirtualBox.
function remove_fed_vbox()
{
VBOX_INSTALLED=$(rpm -qa | grep VirtualBox)
if [[ $VBOX_INSTALLED ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
$install_with -y -q erase $VBOX_INSTALLED 2>/dev/null
printf $OKB" ✓\n\n"$RST
fi
}

# Install Oracle VirtualBox from the downloaded source RPM.
function install_source()
{
if [[ -f $VBOX_SRC_FILE ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $VBOX_SRC_FILE
else
printf $ERR"The source file missing.\nThere was an error downloading the file.\n"$RST
exit 0
fi
}

# Install the Oracle VirtualBox Extension Pack.
function install_extpack()
{
if [[ -f $VBOX_EXT_SRC ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack."$RST
VBoxManage extpack install --replace $VBOX_EXT_SRC
else
printf $ERR"Oracle VirtualBox extension pack source file missing!\n"$RST
fi
}

# Get any Fedora packages typically needed to complete the VirtualBox installation without errors.
function get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Installing necessary packages$OKB "${NEWPKGS}"... "$RST
$install_with -y -q install ${NEWPKGS} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
fi
}

# Get the VirtualBox source files from Oracle
function get_source()
{
printf $OK"Getting VirtualBox source from the Oracle download site..."$RST
remove_source
wget -q $SRC_PATH/$VBOX_SRC_FILE
printf $OKB" ✓\n"$RST
printf $OK"Getting the VirtualBox Extension Pack source file..."$RST
wget -q $SRC_PATH/$VBOX_EXT_SRC
printf $OKB" ✓\n"$RST
echo
}

# The script run has completed. Print a short message stating same.
function script_complete()
{
remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

# The test script run has completed.
function script_test_complete()
{
remove_source
printf $OKB"This script test is now complete.\n"
printf $OKB"All necessary Fedora packages are installed.\n"$RST
}

# Script execution has been cancelled by the user.
function script_cancel()
{
tput cuu1
tput el
printf $OK"Script cancelled.\n"$RST
}

# Main script flow
function menu()
{
clear
headline
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into the newest kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n/t> "$RST
read yn
case $yn in
y) get_release
remove_fed_vbox
get_packages
get_source
install_source
install_extpack
script_complete
;;

n) script_cancel
exit 0
;;
# Test menu entry
t) get_release
get_packages
get_source
script_test_complete
;;

*) script_cancel
exit 0
;;
esac
}
menu

medicman2002
29th March 2015, 07:09 PM
Hello, if I could make this work then it would be great. Something in your code would likely correct my install issues. I do not understand at what point I'd use your script though. I am very new to fedora and have limited experience with VMBox. I've DL the latest VMBox (4.3.26) and am on a host Windows 7 64-bit Dell Inspiron laptop. I need to get some version of fedora (my text book uses fedora 13 to show how far behind our professors are) on my VMBox. I've tried already with fedora 21 (worstation) x86 version. I'd like to try with an iso of fedora 13 but don't know where to find that archived file.

Where or how does your script come into play-- and could you tell me generally what I've done incorrectly? I'd appreciate any help at all.

glennzo
30th March 2015, 09:52 AM
My script will be of no use to you. It is for a Fedora host.

You need the VirtualBox.exe file for a Windows host. http://download.virtualbox.org/virtualbox/4.3.26/VirtualBox-4.3.26-98988-Win.exe

Install that along with VirtualBox Extension Pack http://download.virtualbox.org/virtualbox/4.3.26/Oracle_VM_VirtualBox_Extension_Pack-4.3.26-98988.vbox-extpack. Click on the extension pack file and VirtualBox will open and offer to install it.

Then you need Fedora 13 32 Bit (http://archive.fedoraproject.org/pub/archive/fedora/linux/releases/13/Fedora/i386/iso/) or 64 Bit (http://archive.fedoraproject.org/pub/archive/fedora/linux/releases/13/Fedora/x86_64/iso/).

glennzo
26th April 2015, 01:26 PM
Has anyone else tried this script? It would be wonderful to get some feedback. Did it work well?

Tested under Fedora 22 Beta x86_64 (virtual machine). Worked well :)

Still can't upload attachments :dis:

Copy and paste. Save as anythingyoulike.sh
Run

sudo ./anythingyoulike.sh


#!/bin/bash
# 21_oracle_virtualbox.sh

# Install and configure the Oracle version of VirtualBox for Fedora 20 and later.
# Install the Oracle VirtualBox Extension Pack.
# Handle all platforms, i686, PAE and x86_64 .
# Clean up when finished.
# Use DNF for Fedora 21 and up, YUM for Fedora 20 and earlier.
# Remove previously installed VirtualBox.
# Support color / no color (sudo NOCOLOR=1 21_oracle_virtualbox.sh)

# Glenn A. Johnson
# Started January 18, 2015
# Updated April 26, 2015

# 04.26.15 - Can I add an uninstall (safely) feature?
# 04.26.15 - Testing... 1,2,3
# 03.26.15 - Cosmetic changes and version update
# 03.15.15 - Tested under Fedora 22 Workstation Alpha (x86_64).
# 03.14.15 - New VirtualBox version
# 02.25.15 - Betterer code to discover kernel arch.
# 02.23.15 - New code to discover kernel arch
# 02.22.15 - Seems that kernel arch discovery is not working.
# 02.21.15 - New version of VirtualBox

# A tip of the fedora to Fedora Forum members Sea, Skull One, marko, Dangermouse
# for help with code

# Variables - Additional packages usually needed for a successful install of VirtualBox
# over the different platforms, x86_64, i686 and i686+PAE
#PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"

# Determine OS platform and install correct packages.
# PAE or no?
GETVERS=$(uname -r | grep "PAE")
if [[ $GETVERS ]] ; then
PACKFILES="kernel-PAE-devel gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"
else
PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"
fi

# We can easily make changes to the source file versions by changing a few variables below.
# Most recent is http://download.virtualbox.org/virtualbox/4.3.26/VirtualBox-4.3-4.3.26_98988_fedora18-1.x86_64.rpm
VB_REL_VER="4.3-4.3.26_98988"
VB_EXT_VER="4.3.26-98988"
VB_REL_DIST="fedora18-1"
VBOX_SRC_FILE="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
VBOX_EXT_SRC="Oracle_VM_VirtualBox_Extension_Pack-${VB_EXT_VER}.vbox-extpack"
SRC_PATH="http://download.virtualbox.org/virtualbox/4.3.26"

# Color definitions; the variables are null if the option NOCOLOR is set.
# Thanks Skull One!

if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 6)
OK=$(tput setaf 6)
ERRB=$(tput bold;tput setaf 1)
ERR=$(tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERRB=
ERR=
RST=
fi

# Need root permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
printf $OK"You're going to need root permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\"\n"$RST
exit 0
fi

# Release 20 and later only
function get_release()
{
printf $OK"Checking Fedora release version... "$RST
RELNUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $RELNUM < "20" ]] ; then
printf $ERR"\nThis script is for Fedora release 20 and later only.\n"$RST
exit 0
else printf $OKB"Fedora $RELNUM ✓"$RST
# Determine if we're going to use dnf or yum.
if [[ $RELNUM < "21" ]] ; then
install_with="yum"
else
install_with="dnf"
fi
fi
echo
}

# Clear screen and print a headline.
function headline()
{
clear
printf $OK"==>$OKB VirtualBox installation script for Fedora 20 and up.\n"$RST
printf $OK"==>$OKB Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
printf $OK"==>$OKB VirtualBox release $VB_REL_VER\n"$RST
}

# Remove Oracle VirtualBox source files if they exist in the current working directory.
function remove_source()
{
for i in $VBOX_SRC_FILE $VBOX_EXT_SRC ; do
rm -f $i
done
}

# Remove any installed version of VirtualBox.
function remove_fed_vbox()
{
VBOX_INSTALLED=$(rpm -qa | grep VirtualBox)
if [[ $VBOX_INSTALLED ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
$install_with -y -q erase $VBOX_INSTALLED 2>/dev/null
printf $OKB" ✓\n\n"$RST
fi
}

# Install Oracle VirtualBox from the downloaded source RPM.
function install_source()
{
if [[ -f $VBOX_SRC_FILE ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $VBOX_SRC_FILE
else
printf $ERR"The source file missing.\nThere was an error downloading the file.\n"$RST
exit 0
fi
}

# Install the Oracle VirtualBox Extension Pack.
function install_extpack()
{
if [[ -f $VBOX_EXT_SRC ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack."$RST
VBoxManage extpack install --replace $VBOX_EXT_SRC
else
printf $ERR"Oracle VirtualBox extension pack source file missing!\n"$RST
fi
}

# Get any Fedora packages typically needed to complete the VirtualBox installation without errors.
function get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Installing necessary packages$OKB "${NEWPKGS}"... "$RST
$install_with -y -q install ${NEWPKGS} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
fi
}

# Get the VirtualBox source files from Oracle
function get_source()
{
printf $OK"Getting the VirtualBox source RPM from the Oracle download site..."$RST
remove_source
wget -q $SRC_PATH/$VBOX_SRC_FILE
printf $OKB" ✓\n"$RST
printf $OK"Getting the VirtualBox Extension Pack source file..."$RST
wget -q $SRC_PATH/$VBOX_EXT_SRC
printf $OKB" ✓\n"$RST
echo
}

# The script run has completed. Print a short message stating same.
function script_complete()
{
remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

# The test script run has completed.
function script_test_complete()
{
remove_source
printf $OKB"This script test is now complete.\n"
printf $OKB"All necessary Fedora packages are installed.\n"$RST
}

# Script execution has been cancelled by the user.
function script_cancel()
{
tput cuu1
tput el
printf $OK"Script cancelled.\n"$RST
}

# Main script flow
function menu()
{
clear
headline
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into the newest kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n/t> "$RST
read yn
case $yn in
y) get_release
remove_fed_vbox
get_packages
get_source
install_source
install_extpack
script_complete
;;

n) script_cancel
exit 0
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is install missing packages. It also downloads VirtualBox and the Extension Pack.
t) get_release
get_packages
get_source
script_test_complete
;;

*) script_cancel
exit 0
;;
esac
}
menu

zuser
14th May 2015, 05:57 PM
glennzo:

Thanks again for this. After several upgrades in both kernel and VirtualBox, script continues to work flawlessly. Staying current is sooooo easy.

glennzo
14th May 2015, 06:08 PM
You're welcome.

Oddly enough, there is a new version of VirtualBox. I've updated the script for that version but haven't had time to update here. (At work at the moment). I believe, and correct me if I'm wrong, that there is an extremely serious vulnerability with virtual machines run under VirtualBox. Here's an example of what I've read somewhere else.
http://www.zdnet.com/article/venom-security-flaw-millions-of-virtual-machines-datacenters/

glennzo
15th May 2015, 12:15 AM
OK. Newest version of VirtualBox, 4.3.28


#!/bin/bash
# 21_oracle_virtualbox.sh

# Install and configure the Oracle version of VirtualBox for Fedora 20 and later.
# Install the Oracle VirtualBox Extension Pack.
# Handle all platforms, i686, PAE and x86_64 .
# Clean up when finished.
# Use DNF for Fedora 21 and up, YUM for Fedora 20 and earlier.
# Remove previously installed VirtualBox.
# Support color / no color (sudo NOCOLOR=1 21_oracle_virtualbox.sh)

# Glenn A. Johnson
# Started January 18, 2015
# Updated May 14, 2015

# 05.14.15 - Add feature to import and install the Oracle public key
# 05.14.15 - Update VirtualBox version to 4.3.28
# 05.12.15 - Test run under Fedora 22 Beta.
# 04.26.15 - Can I add an uninstall (safely) feature?
# 04.26.15 - Testing... 1,2,3
# 03.26.15 - Cosmetic changes and version update
# 03.15.15 - Tested under Fedora 22 Workstation Alpha (x86_64).
# 03.14.15 - New VirtualBox version
# 02.25.15 - Betterer code to discover kernel arch.
# 02.23.15 - New code to discover kernel arch
# 02.22.15 - Seems that kernel arch discovery is not working.
# 02.21.15 - New version of VirtualBox

# A tip of the fedora to Fedora Forum members Sea, Skull One, marko, Dangermouse
# for help with code

# Variables - Additional packages usually needed for a successful install of VirtualBox
# over the different platforms, x86_64, i686 and i686+PAE
#PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"

# Determine OS platform and install correct packages.
# PAE or no?
GETVERS=$(uname -r | grep "PAE")
if [[ $GETVERS ]] ; then
PACKFILES="kernel-PAE-devel gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"
else
PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"
fi

# We can easily make changes to the source file versions by changing a few variables below.
# Most recent is http://download.virtualbox.org/virtualbox/4.3.28/VirtualBox-4.3-4.3.28_100309_fedora18-1.x86_64.rpm
VB_REL_VER="4.3-4.3.28_100309"
VB_EXT_VER="4.3.28-100309"
VB_REL_DIST="fedora18-1"
VBOX_SRC_FILE="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
VBOX_EXT_SRC="Oracle_VM_VirtualBox_Extension_Pack-${VB_EXT_VER}.vbox-extpack"
SRC_PATH="http://download.virtualbox.org/virtualbox/4.3.28"
PUB_KEY="oracle_vbox.asc"

# Color definitions; the variables are null if the option NOCOLOR is set.
# Thanks Skull One!

if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 6)
OK=$(tput setaf 6)
ERRB=$(tput bold;tput setaf 1)
ERR=$(tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERRB=
ERR=
RST=
fi

# Need root permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
printf $OK"You're going to need root permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\"\n"$RST
exit 0
fi

# Release 20 and later only
function get_release()
{
printf $OK"Checking Fedora release version... "$RST
RELNUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $RELNUM < "20" ]] ; then
printf $ERR"\nThis script is for Fedora release 20 and later only.\n"$RST
exit 0
else printf $OK"Fedora $RELNUM $OKB✓"$RST
# Determine if we're going to use dnf or yum.
if [[ $RELNUM < "21" ]] ; then
install_with="yum"
else
install_with="dnf"
fi
fi
echo
}

# Clear screen and print a headline.
function headline()
{
clear
printf $OK"==>$OKB VirtualBox installation script for Fedora 20 and up.\n"$RST
printf $OK"==>$OKB Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
printf $OK"==>$OKB VirtualBox release $VB_REL_VER\n"$RST
}

# Remove Oracle VirtualBox source files if they exist in the current working directory.
function remove_source()
{
for i in $VBOX_SRC_FILE $VBOX_EXT_SRC $PUB_KEY; do
rm -f $i
done
}

# Remove any installed version of VirtualBox.
function remove_fed_vbox()
{
VBOX_INSTALLED=$(rpm -qa | grep VirtualBox)
if [[ $VBOX_INSTALLED ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
$install_with -y -q erase $VBOX_INSTALLED 2>/dev/null
printf $OKB" ✓\n\n"$RST
fi
}

# Download and import the Oracle public key.
function get_public_key()
{
printf $OK"Installing the Oracle public key.\n"$RST
wget -q https://www.virtualbox.org/download/$PUB_KEY
rpm --import $PUB_KEY
}

# Install Oracle VirtualBox from the downloaded source RPM.
function install_source()
{
if [[ -f $VBOX_SRC_FILE ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $VBOX_SRC_FILE
else
printf $ERR"The source file missing.\nThere was an error downloading the file.\n"$RST
exit 0
fi
}

# Install the Oracle VirtualBox Extension Pack.
function install_extpack()
{
if [[ -f $VBOX_EXT_SRC ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack."$RST
VBoxManage extpack install --replace $VBOX_EXT_SRC
else
printf $ERR"Oracle VirtualBox extension pack source file missing!\n"$RST
fi
}

# Get any Fedora packages typically needed to complete the VirtualBox installation without errors.
function get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Installing necessary packages$OKB "${NEWPKGS}"... "$RST
$install_with -y -q install ${NEWPKGS} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
fi
}

# Get the VirtualBox source files from Oracle
function get_source()
{
printf $OK"Getting the VirtualBox source RPM from the Oracle download site..."$RST
remove_source
wget -q $SRC_PATH/$VBOX_SRC_FILE
printf $OKB" ✓\n"$RST
printf $OK"Getting the VirtualBox Extension Pack source file..."$RST
wget -q $SRC_PATH/$VBOX_EXT_SRC
printf $OKB" ✓\n"$RST
echo
}

# The script run has completed. Print a short message stating same.
function script_complete()
{
remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

# The test script run has completed.
function script_test_complete()
{
remove_source
printf $OKB"This script test is now complete.\n"
printf $OKB"All necessary Fedora packages are installed.\n"$RST
}

# Script execution has been cancelled by the user.
function script_cancel()
{
tput cuu1
tput el
printf $OK"Script cancelled.\n"$RST
}

# Main script flow
function menu()
{
clear
headline
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into the newest kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n/t> "$RST
read yn
case $yn in
y) get_release
remove_fed_vbox
get_packages
get_public_key
get_source
install_source
install_extpack
script_complete
;;

n) script_cancel
exit 0
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is install missing packages. It also downloads VirtualBox and the Extension Pack.
t) get_release
get_packages
get_source
script_test_complete
;;

*) script_cancel
exit 0
;;
esac
}
menu

MadmanRB
5th June 2015, 11:29 AM
Its a no go it seems.
Why cant fedora just use a RPM?
What too busy pushing that piece of crap called boxes?
I think its just time to go to vmware, its too annoying to have to result to using scripts.
Dont have to do that with ubuntu, or OpenSUSE, hell even arch doesnt neerd a rotten script

glennzo
5th June 2015, 11:08 PM
Its a no go it seems.
Why cant fedora just use a RPM?
What too busy pushing that piece of crap called boxes?
I think its just time to go to vmware, its too annoying to have to result to using scripts.
Dont have to do that with ubuntu, or OpenSUSE, hell even arch doesnt neerd a rotten script

So angry :confused:

glennzo
6th June 2015, 09:45 AM
The script still works well as of this morning.

On a Fedora 22 host.
http://www.forums.fedoraforum.org/picture.php?albumid=366&pictureid=2149

marko
6th June 2015, 11:51 AM
Its a no go it seems.
Why cant fedora just use a RPM?


Fedora does have a VirtualBox rpm, it's in rpmfusion.

dnf search VirtualBox
Last metadata expiration check performed 0:04:18 ago on Sat Jun 6 06:44:15 2015.
================================ N/S Matched: VirtualBox =================================
VirtualBox.x86_64 : A general-purpose full virtualizer for PC hardware
VirtualBox-devel.x86_64 : VirtualBox SDK
VirtualBox-devel.i686 : VirtualBox SDK
VirtualBox-guest.x86_64 : VirtualBox Guest Additions
python-VirtualBox.x86_64 : Python bindings for VirtualBox
VirtualBox-kmodsrc.x86_64 : VirtualBox kernel module source code
akmod-VirtualBox.x86_64 : Akmod package for VirtualBox kernel module(s)
kmod-VirtualBox.x86_64 : Metapackage which tracks in VirtualBox kernel module for newest
: kernel
kmod-VirtualBox-4.0.2-300.fc22.x86_64.x86_64 : VirtualBox kernel module(s) for
: 4.0.2-300.fc22.x86_64
libvirt-daemon-driver-vbox.x86_64 : VirtualBox driver plugin for the libvirtd daemon
RemoteBox.noarch : Open Source VirtualBox Client with Remote Management
libvirt-daemon-vbox.x86_64 : Server side daemon & driver required to run VirtualBox guests



Some people prefer to get the VirtualBox straight from VirtualBox, which is what the script is for

DrewP
8th July 2015, 01:39 PM
Thank you for that. The script worked perfectly for me this morning after having updated my computer to Fedora 22.

In response to a question above it is worth pointing out that the script DOES use an rpm (Oracle's own rpm), but as Oracle chooses not to maintain a repository that follows Fedora conventions the usual tools like yum and dnf cannot use it directly The script takes the pain out of locating, downloading and installling the rpm locally.

I was wondering if you had ever considered reading the contents of
http://download.virtualbox.org/virtualbox/LATEST.TXT into a variable (it's currently 4.3.28)
then parse the result of grepping for the fedora release and architecture in
http://download.virtualbox.org/virtualbox/(variable)/MD5SUMS
(currently http://download.virtualbox.org/virtualbox/4.3.28/MD5SUMS) to get the name of the file that currently has to be manually assigned to VBOX_SRC_FILE

I appreciate that the same rpm is used for Fedora releases 18,19,20 and 21 so would have to parse for the filename that contains the highest release version less than or equal to the installed Fedora release, which makes the process a bit less trivial than I am trying to make it look.

I think all the other manually assigned variables can be derived from what has been found above.

I wouldn't hesitate to do all the above in perl but my bash scripting is very weak.

It was only when I was reviewing your script to compose this comment that I realized I had concentrated so much on the Oracle numbers in the manually assigned variables that I had forgotten to update the Fedora release to 22.

The script appears to have worked equally well removing the 18 release and installing the 22 release.

I could guarantee you one grateful user if it's possible to assign all those variables programatically.

Thanks again.

glennzo
9th July 2015, 11:37 PM
Version 5.0

DrewP. Your request duly noted.


#!/bin/bash
# 21_oracle_virtualbox.sh

# Glenn A. Johnson
# Started January 18, 2015
# Updated July 9, 2015

# A tip of the fedora to Fedora Forum members Sea, Skull One, marko, Dangermouse
# for help with code

<< COMMENT
* Install and configure the Oracle version of VirtualBox for Fedora 21 and later.
* Install the Oracle VirtualBox Extension Pack.
* Handle all platforms, i686, PAE and x86_64 .
* Clean up when finished.
* Use DNF for Fedora 21 and up, YUM for Fedora 20 and earlier.
* Remove previously installed VirtualBox.
* Support color / no color (sudo NOCOLOR=1 21_oracle_virtualbox.sh)
COMMENT

# 07.09.15 - Fedora 21 and 22 only. No more Fedora 20.
# 07.09.15 - Version 5.0 ??
# 06.08.18 - Working with the Fedora 22 rpm
# 06.07.17 - Huh?
# 05.14.15 - Add feature to import and install the Oracle public key
# 05.14.15 - Update VirtualBox version to 4.3.28
# 05.12.15 - Test run under Fedora 22 Beta.
# 04.26.15 - Can I add an uninstall (safely) feature?
# 04.26.15 - Testing... 1,2,3
# 03.26.15 - Cosmetic changes and version update
# 03.15.15 - Tested under Fedora 22 Workstation Alpha (x86_64).
# 03.14.15 - New VirtualBox version
# 02.25.15 - Betterer code to discover kernel arch.
# 02.23.15 - New code to discover kernel arch
# 02.22.15 - Seems that kernel arch discovery is not working.
# 02.21.15 - New version of VirtualBox

<< COMMENT
Additional packages needed for a successful install of VirtualBox over the different platforms, x86_64, i686 and i686+PAE include
kernel-devel-$(uname -r), gcc, qt, qt-x11, libpng15, libXmu, libXt, libvpx, dkms, wget and SDL
COMMENT

# Determine OS platform and install correct packages.
# PAE or no?
GETVERS=$(uname -r | grep "PAE")
if [[ $GETVERS ]] ; then
PACKFILES="kernel-PAE-devel gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"
else
PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms wget SDL"
fi

# We can easily make changes to the source file versions by changing a few variables below.
# Most recent is http://download.virtualbox.org/virtualbox/5.0.0/VirtualBox-5.0-5.0.0_101573_fedora22-1.x86_64.rpm

VB_REL_VER="5.0-5.0.0_101573"
VB_EXT_VER="5.0.0-101573"
VB_REL_DIST="fedora22-1"
VBOX_SRC_FILE="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
VBOX_EXT_SRC="Oracle_VM_VirtualBox_Extension_Pack-${VB_EXT_VER}.vbox-extpack"
SRC_PATH="http://download.virtualbox.org/virtualbox/5.0.0"
PUB_KEY="oracle_vbox.asc"

# Color definitions; the variables are null if the option NOCOLOR is set.
# Thanks Skull One!

if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 6)
OK=$(tput setaf 6)
ERRB=$(tput bold;tput setaf 1)
ERR=$(tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERRB=
ERR=
RST=
fi

# Need root permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
printf $OK"You're going to need root permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\"\n"$RST
exit 0
fi

# Release 21 and later only
function get_release()
{
printf $OK"Checking Fedora release version... "$RST
RELNUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $RELNUM < "21" ]] ; then
printf $ERR"\nThis script is for Fedora release 21 and later only.\n"$RST
exit 0
else printf $OK"Fedora $RELNUM $OKB✓"$RST
# Determine if we're going to use dnf or yum.
if [[ $RELNUM < "21" ]] ; then
install_with="yum"
else
install_with="dnf"
fi
fi
echo
}

# Clear screen and print a headline.
function headline()
{
clear
printf $OK"==>$OKB VirtualBox installation script for Fedora 20 and up.\n"$RST
printf $OK"==>$OKB Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
printf $OK"==>$OKB VirtualBox release $VB_REL_VER\n"$RST
}

# Remove Oracle VirtualBox source files if they exist in the current working directory.
function remove_source()
{
for i in $VBOX_SRC_FILE $VBOX_EXT_SRC $PUB_KEY; do
rm -f $i
done
}

# Remove any installed version of VirtualBox.
function remove_fed_vbox()
{
VBOX_INSTALLED=$(rpm -qa | grep VirtualBox)
if [[ $VBOX_INSTALLED ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
$install_with -y -q erase $VBOX_INSTALLED 2>/dev/null
printf $OKB" ✓\n\n"$RST
fi
}

# Download and import the Oracle public key.
function get_public_key()
{
printf $OK"Installing the Oracle public key.\n"$RST
wget -q https://www.virtualbox.org/download/$PUB_KEY
rpm --import $PUB_KEY
}

# Install Oracle VirtualBox from the downloaded source RPM.
function install_source()
{
if [[ -f $VBOX_SRC_FILE ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $VBOX_SRC_FILE
else
printf $ERR"The source file missing.\nThere was an error downloading the file.\n"$RST
exit 0
fi
}

# Install the Oracle VirtualBox Extension Pack.
function install_extpack()
{
if [[ -f $VBOX_EXT_SRC ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack."$RST
VBoxManage extpack install --replace $VBOX_EXT_SRC
else
printf $ERR"Oracle VirtualBox extension pack source file missing!\n"$RST
fi
}

# Get any Fedora packages typically needed to complete the VirtualBox installation without errors.
function get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Installing necessary packages$OKB "${NEWPKGS}"... "$RST
$install_with -y -q install ${NEWPKGS} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
fi
}

# Get the VirtualBox source files from Oracle
function get_source()
{
printf $OK"Getting the VirtualBox source RPM from the Oracle download site..."$RST
remove_source
wget -q $SRC_PATH/$VBOX_SRC_FILE
printf $OKB" ✓\n"$RST
printf $OK"Getting the VirtualBox Extension Pack source file..."$RST
wget -q $SRC_PATH/$VBOX_EXT_SRC
printf $OKB" ✓\n"$RST
echo
}

# The script run has completed. Print a short message stating same.
function script_complete()
{
remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

# The test script run has completed.
function script_test_complete()
{
remove_source
printf $OKB"This script test is now complete.\n"
printf $OKB"All necessary Fedora packages are installed.\n"$RST
}

# Script execution has been cancelled by the user.
function script_cancel()
{
tput cuu1
tput el
printf $OK"Script cancelled.\n"$RST
}

# Add a yum repository for Oracle VirtualBox
function add_yum_repo()
{
if [[ -f $VBOX_REPO ]] ; then
printf $OK"A yum repository for Oracle VirtualBox already exists.\n"$RST
else
printf $OK"Creating a yum repository for Oracle VirtualBox.\n"$RST
touch $VBOX_REPO
echo "
[virtualbox]
name=Fedora \$releasever - \$basearch - VirtualBox
baseurl=http://download.virtualbox.org/virtualbox/rpm/fedora/\$releasever/\$basearch
enabled=1
gpgcheck=1
gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc" > $VBOX_REPO
fi
}

# Main script flow
function menu()
{
clear
headline
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into the newest kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n/t> "$RST
read yn
case $yn in
y) get_release
remove_fed_vbox
get_packages
get_public_key
get_source
install_source
install_extpack
script_complete
;;

n) script_cancel
exit 0
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is install missing packages. It also downloads VirtualBox and the Extension Pack.
t) get_release
get_packages
get_source
script_test_complete
;;

*) script_cancel
exit 0
;;
esac
}
menu

romu70
20th July 2015, 08:26 PM
Hi,
Thanks Glenn for the script. Unfortunately, it doesn't change anything to my problem, I can't get any USB device detected. Here is an example, I've connected a Sony eInk Reader. The lsusb ouput is:


Bus 001 Device 003: ID 054c:05c2 Sony Corp.


But VB says "No peripheral found" when I try to add the reader to my W8 VM. Any idea?

Of course, the extension pack is installed.

glennzo
21st July 2015, 09:19 AM
The script was created to help install VirtualBox. As for personal settings / preferences I'm afraid I can't be of much help.

broadstairs
21st July 2015, 09:51 AM
I got the impression from that article that VirtualBox 4.3.30 or above would fix this but I've not yet checked.

Stuart

broadstairs
21st July 2015, 10:03 AM
Just modified the script variables and installed V5.0.5 successfully.

Stuart

glennzo
15th August 2015, 11:09 AM
#!/bin/bash
# 21_oracle_virtualbox.sh

# Glenn A. Johnson
# Started January 18, 2015
# Updated August 15, 2015

# A tip of the fedora to Fedora Forum members Sea, Skull One, marko, Dangermouse
# for help with code

<< COMMENT
* Install and configure the Oracle version of VirtualBox for Fedora 21 and later.
* Install the Oracle VirtualBox Extension Pack.
* Handle all platforms, i686, PAE and x86_64 .
* Clean up when finished.
* Remove previously installed VirtualBox.
* Support color / no color (sudo NOCOLOR=1 21_oracle_virtualbox.sh)
COMMENT

# 08.15.15 - Debug session. Trouble with extended versioning.
# 07.09.15 - Fedora 21 and 22 only. No more Fedora 20.
# 07.09.15 - Version 5.0 ??
# 06.08.18 - Working with the Fedora 22 rpm
# 06.07.17 - Huh?
# 05.14.15 - Add feature to import and install the Oracle public key
# 05.14.15 - Update VirtualBox version to 4.3.28
# 05.12.15 - Test run under Fedora 22 Beta.
# 04.26.15 - Can I add an uninstall (safely) feature?
# 04.26.15 - Testing... 1,2,3
# 03.26.15 - Cosmetic changes and version update
# 03.15.15 - Tested under Fedora 22 Workstation Alpha (x86_64).
# 03.14.15 - New VirtualBox version
# 02.25.15 - Betterer code to discover kernel arch.
# 02.23.15 - New code to discover kernel arch
# 02.22.15 - Seems that kernel arch discovery is not working.
# 02.21.15 - New version of VirtualBox

<< COMMENT
Additional packages needed for a successful install of VirtualBox over the different platforms, x86_64, i686 and i686+PAE include
kernel-devel-$(uname -r), gcc, qt, qt-x11, libpng15, libXmu, libXt, libvpx, dkms, and SDL
COMMENT

# Determine OS platform and install correct packages.
# PAE or no?
GETVERS=$(uname -r | grep "PAE")
if [[ $GETVERS ]] ; then
PACKFILES="kernel-PAE-devel gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms SDL"
else
PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms SDL"
fi

# Determine the current version of VirtualBox
curl -Os http://download.virtualbox.org/virtualbox/LATEST.TXT
current_version=$(cat LATEST.TXT)
rm LATEST.TXT

# We can easily make changes to the source file versions by changing a few variables below.
# Most recent is http://download.virtualbox.org/virtualbox/5.0.0/VirtualBox-5.0-5.0.0_102096_fedora22-1.x86_64.rpm

VB_REL_VER="5.0-"$current_version"_102096"
VB_EXT_VER="$current_version"-102096
VB_REL_DIST="fedora22-1"
VBOX_SRC_FILE="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
VBOX_EXT_SRC="Oracle_VM_VirtualBox_Extension_Pack-${VB_EXT_VER}.vbox-extpack"
SRC_PATH="http://download.virtualbox.org/virtualbox/$current_version"
PUB_KEY="oracle_vbox.asc"

# Color definitions; the variables are null if the option NOCOLOR is set.
# Thanks Skull One!

if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 6)
OK=$(tput setaf 6)
ERRB=$(tput bold;tput setaf 1)
ERR=$(tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERRB=
ERR=
RST=
fi

# Need root permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
printf $OK"You're going to need root permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\"\n"$RST
exit 0
fi

# Release 21 and later only
function get_release()
{
printf $OK"Checking Fedora release version... "$RST
RELNUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $RELNUM < "21" ]] ; then
printf $ERR"\nThis script is for Fedora release 21 and later only.\n"$RST
exit 0
else printf $OK"Fedora $RELNUM $OKB✓"$RST
fi
echo
}

# Clear screen and print a headline.
function headline()
{
clear
printf $OK"==>$OKB VirtualBox installation script for Fedora 21 and up.\n"$RST
printf $OK"==>$OKB Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
printf $OK"==>$OKB VirtualBox release $VB_REL_VER\n"$RST
}

# Remove Oracle VirtualBox source files if they exist in the current working directory.
function remove_source()
{
for i in $VBOX_SRC_FILE $VBOX_EXT_SRC $PUB_KEY; do
rm -f $i
done
}

# Remove any installed version of VirtualBox.
function remove_fed_vbox()
{
VBOX_INSTALLED=$(rpm -qa | grep VirtualBox)
if [[ $VBOX_INSTALLED ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
dnf -y -q erase $VBOX_INSTALLED 2>/dev/null
printf $OKB" ✓\n\n"$RST
fi
}

# Download and import the Oracle public key.
function get_public_key()
{
printf $OK"Installing the Oracle public key.\n"$RST
curl -Os https://www.virtualbox.org/download/$PUB_KEY
rpm --import $PUB_KEY
}

# Install Oracle VirtualBox from the downloaded source RPM.
function install_source()
{
if [[ -f $VBOX_SRC_FILE ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $VBOX_SRC_FILE
else
printf $ERR"The source file missing.\nThere was an error downloading the file.\n"$RST
exit 0
fi
}

# Install the Oracle VirtualBox Extension Pack.
function install_extpack()
{
if [[ -f $VBOX_EXT_SRC ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack."$RST
VBoxManage extpack install --replace $VBOX_EXT_SRC
else
printf $ERR"Oracle VirtualBox extension pack source file missing!\n"$RST
fi
}

# Get any Fedora packages typically needed to complete the VirtualBox installation without errors.
function get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Installing necessary packages$OKB "${NEWPKGS}"... "$RST
dnf -y -q install ${NEWPKGS} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
fi
}

# Get the VirtualBox source files from Oracle
function get_source()
{
printf $OK"Getting the VirtualBox source RPM from the Oracle download site..."$RST
remove_source
curl -Os $SRC_PATH/$VBOX_SRC_FILE
printf $OKB" ✓\n"$RST
printf $OK"Getting the VirtualBox Extension Pack source file..."$RST
curl -Os $SRC_PATH/$VBOX_EXT_SRC
printf $OKB" ✓\n"$RST
echo
}

# The script run has completed. Print a short message stating same.
function script_complete()
{
remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

# Script execution has been cancelled by the user.
function script_cancel()
{
clear
printf $OK"Script execution cancelled.\n"$RST
}

# Main script flow
function menu()
{
clear
headline
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into the newest kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n> "$RST
read yn
case $yn in
y) get_release
remove_fed_vbox
get_packages
get_public_key
get_source
install_source
install_extpack
script_complete
;;

n) script_cancel
exit 0
;;

*) script_cancel
exit 0
;;
esac
}
menu

broadstairs
15th August 2015, 06:03 PM
The only problem I had using this script was that the dkms.conf for the old version of VirtualBox was not removed and caused issues and would not update the kernel modifcations properly until I removed it.

Stuart

glennzo
15th August 2015, 10:31 PM
Haven't had that happen to me, at least not yet.

glennzo
8th September 2015, 09:37 AM
A minor update to the script this morning. One test run. Worked perfectly.


#!/bin/bash
# 22_oracle_virtualbox.sh

# Glenn A. Johnson
# Started January 18, 2015
# Updated September 8, 2015

# A tip of the fedora to Fedora Forum members Sea, Skull One, marko, Dangermouse
# for help with code

<< COMMENT
* Install and configure the Oracle version of VirtualBox for Fedora 22 only.
* Install the Oracle VirtualBox Extension Pack.
* Handle all platforms, i686, PAE and x86_64 .
* Clean up when finished.
* Remove previously installed VirtualBox.
* Support color / no color (sudo NOCOLOR=1 22_oracle_virtualbox.sh)
COMMENT

# 09.08.15 - Minor VirtualBox version change
# 07.22.15 - Decided to support only the current release of Fedora
# 07.19.15 - No longer need YUM since we're Fedora 21 and later.
# 07.19.15 - Got me a couple errors to deal with ...
# 07.09.15 - Fedora 21 and 22 only. No more Fedora 20.
# 07.09.15 - Version 5.0 ??
# 06.08.18 - Working with the Fedora 22 rpm
# 06.07.17 - Huh?
# 05.14.15 - Add feature to import and install the Oracle public key
# 05.14.15 - Update VirtualBox version to 4.3.28
# 05.12.15 - Test run under Fedora 22 Beta.
# 04.26.15 - Can I add an uninstall (safely) feature?
# 04.26.15 - Testing... 1,2,3
# 03.26.15 - Cosmetic changes and version update
# 03.15.15 - Tested under Fedora 22 Workstation Alpha (x86_64).
# 03.14.15 - New VirtualBox version
# 02.25.15 - Betterer code to discover kernel arch.
# 02.23.15 - New code to discover kernel arch
# 02.22.15 - Seems that kernel arch discovery is not working.
# 02.21.15 - New version of VirtualBox

<< COMMENT
Additional packages needed for a successful install of VirtualBox over the different platforms, x86_64, i686 and i686+PAE include
kernel-devel-$(uname -r), gcc, qt, qt-x11, libpng15, libXmu, libXt, libvpx, dkms, and SDL
COMMENT

# Determine OS platform and install correct packages.
# PAE or no?
GETVERS=$(uname -r | grep "PAE")
if [[ $GETVERS ]] ; then
PACKFILES="kernel-PAE-devel gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms SDL"
else
PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms SDL"
fi

# Determine the current version of VirtualBox
curl -Os http://download.virtualbox.org/virtualbox/LATEST.TXT
current_version=$(cat LATEST.TXT)
rm LATEST.TXT

# We can easily make changes to the source file versions by changing a few variables below.
# Most recent is http://download.virtualbox.org/virtualbox/5.0.0/VirtualBox-5.0-5.0.0_102096_fedora22-1.x86_64.rpm

VB_REL_VER="5.0-"$current_version"_102096"
VB_EXT_VER="$current_version"-102096
VB_REL_DIST="fedora22-1"
VBOX_SRC_FILE="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
VBOX_EXT_SRC="Oracle_VM_VirtualBox_Extension_Pack-${VB_EXT_VER}.vbox-extpack"
SRC_PATH="http://download.virtualbox.org/virtualbox/$current_version"
PUB_KEY="oracle_vbox.asc"

# Color definitions; the variables are null if the option NOCOLOR is set.
# Thanks Skull One!

if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 6)
OK=$(tput setaf 6)
ERRB=$(tput bold;tput setaf 1)
ERR=$(tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERRB=
ERR=
RST=
fi

# Need elevated permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
printf $OK"You're going to need elevated permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\"\n"$RST
exit 0
fi

# Release 22 only
function get_release()
{
printf $OK"Checking Fedora release version... "$RST
RELNUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $RELNUM < "22" ]] ; then
clear
printf $ERR"This script is for Fedora release 22 only.\n"$RST
exit 0
else printf $OK"Fedora $RELNUM $OKB✓"$RST
fi
echo
}

# Clear screen and print a headline.
function headline()
{
clear
printf $OK"==>$OKB VirtualBox installation script for Fedora 22.\n"$RST
printf $OK"==>$OKB Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
printf $OK"==>$OKB VirtualBox release $VB_REL_VER\n"$RST
}

# Remove Oracle VirtualBox source files if they exist in the current working directory.
function remove_source()
{
for i in $VBOX_SRC_FILE $VBOX_EXT_SRC $PUB_KEY; do
rm -f $i
done
}

# Remove any installed version of VirtualBox.
function remove_fed_vbox()
{
VBOX_INSTALLED=$(rpm -qa | grep VirtualBox)
if [[ $VBOX_INSTALLED ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
dnf -y -q erase $VBOX_INSTALLED 2>/dev/null
printf $OKB" ✓\n\n"$RST
fi
}

# Download and import the Oracle public key.
function get_public_key()
{
printf $OK"Installing the Oracle public key.\n"$RST
curl -Os https://www.virtualbox.org/download/$PUB_KEY
rpm --import $PUB_KEY
}

# Install Oracle VirtualBox from the downloaded source RPM.
function install_source()
{
if [[ -f $VBOX_SRC_FILE ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $VBOX_SRC_FILE
else
printf $ERR"The source file missing.\nThere was an error downloading the file.\n"$RST
exit 0
fi
}

# Install the Oracle VirtualBox Extension Pack.
function install_extpack()
{
if [[ -f $VBOX_EXT_SRC ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack."$RST
VBoxManage extpack install --replace $VBOX_EXT_SRC
else
printf $ERR"Oracle VirtualBox extension pack source file missing!\n"$RST
fi
}

# Get any Fedora packages typically needed to complete the VirtualBox installation without errors.
function get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Installing necessary packages$OKB "${NEWPKGS}"... "$RST
dnf -y -q install ${NEWPKGS} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
fi
}

# Test retrieval of any Fedora packages typically needed to complete the VirtualBox installation without errors.
function test_get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Packages that need to be installed are: $OKB "${NEWPKGS}"... "$RST
echo
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
echo
fi
}

# Get the VirtualBox source files from Oracle
function get_source()
{
printf $OK"Getting the VirtualBox source RPM from the Oracle download site..."$RST
remove_source
curl -Os $SRC_PATH/$VBOX_SRC_FILE
printf $OKB" ✓\n"$RST
printf $OK"Getting the VirtualBox Extension Pack source file..."$RST
curl -Os $SRC_PATH/$VBOX_EXT_SRC
printf $OKB" ✓\n"$RST
echo
}

# The script run has completed. Print a short message stating same.
function script_complete()
{
#remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

# The test script run has completed.
function script_test_complete()
{
remove_source
printf $OKB"This script test is now complete.\n"
printf $OKB"All necessary Fedora packages are installed.\n"$RST
}

# Script execution has been cancelled by the user.
function script_cancel()
{
clear
printf $OK"Script execution cancelled.\n"$RST
}

# Testing only. Show value of all variables
function show_vars()
{
echo
printf $OK"VB_REL_VER is $OKB$VB_REL_VER\n"$RST
printf $OK"VB_EXT_VER is $OKB$VB_EXT_VER\n"$RST
printf $OK"VB_REL_DIST is $OKB$VB_REL_DIST\n"$RST
printf $OK"VBOX_SRC_FILE is $OKB$VBOX_SRC_FILE\n"$RST
printf $OK"VBOX_EXT_SRC is $OKB$VBOX_EXT_SRC\n"$RST
printf $OK"SRC_PATH is $OKB$SRC_PATH\n"$RST
}

function testonly()
{
clear
printf $ERRB"===== TEST ONLY. NO PACKAGES ARE BEING INSTALLED. NOTHING IS BEING WRITTEN TO DISK.=====\n"$RST
}

# Main script flow
function menu()
{
clear
headline
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into the newest kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n/t/v> "$RST
read yn
case $yn in
y) get_release
remove_fed_vbox
get_packages
get_public_key
get_source
install_source
install_extpack
script_complete
;;

n) script_cancel
exit 0
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is install missing packages. It also downloads VirtualBox and the Extension Pack.
t) testonly
get_release
test_get_packages
get_source
script_test_complete
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is show the current value of all of the variables.
v) get_release
show_vars
;;
*) script_cancel
exit 0
;;
esac
}
menu

zuser
22nd September 2015, 10:57 PM
glennzo,

Updated script has failed for the 1st time.
While running it produces a long list of "format" errors and ends with the following:




Installing Oracle VirtualBox extension pack.
./InstallVBox.sh: line 162: VBoxManage: command not found
Oracle VirtualBox is now installed.
Script run complete.

While it states installation is complete, it actually is not. No icon installed and cannot find any new files.

I am running F22_64 workstation (gnome 3)
Any suggestions?

A1MiXeS
2nd October 2015, 01:55 AM
OK, so im new to different operating systems. New to coding,,,, just a basic newb. Ive spent the last two days installing Fedora 22 on Virtualbox host windows 7. Everytime it installs and reboots, it reboots to the installation screen again. It just wont start up. Hopefully this problem can be fixed by noone of that stuff up there ^^^^^^^^ and its something simple i can change in settings. Ive literally fumbled through it to this point using youtube vids and scanning forums. Plese dont write me off i really want to know what im doing, im a quick learner and just need a little help.

glennzo
2nd October 2015, 09:19 AM
glennzo,

Updated script has failed for the 1st time.
While running it produces a long list of "format" errors and ends with the following:





While it states installation is complete, it actually is not. No icon installed and cannot find any new files.

I am running F22_64 workstation (gnome 3)
Any suggestions?

Sorry, didn't see this post until just now. Have you tried the script in the last few days? I believe the errror(s) were caused by a version mismatch type of issue. The Oracle web page that I pull latest version info from was not updated at the same time VirtualBox was, so for several days it was at 5.0.2 when everything VirtualBox was at 5.0.4. The script has worked well for me once the versioning info was updated on Oracle's end.

glennzo
2nd October 2015, 09:24 AM
In the menu, go to Settings>System and move "Hard Disk" to the top of the list. I'm guessing that Optical is currently at the top, hence the constant attempt to install the OS.

http://www.forums.fedoraforum.org/picture.php?albumid=366&pictureid=2179

A1MiXeS
2nd October 2015, 03:20 PM
In the menu, go to Settings>System and move "Hard Disk" to the top of the list. I'm guessing that Optical is currently at the top, hence the constant attempt to install the OS.

http://www.forums.fedoraforum.org/picture.php?albumid=366&pictureid=2179

Bloody Legend mate! Knew it was something simple :dance:

glennzo
4th October 2015, 10:02 AM
New numbers, new version... Still seems to be working really well for Fedora 22/23.


#!/bin/bash
# 22_oracle_virtualbox.sh

# Glenn A. Johnson
# Started January 18, 2015
# Updated October 4, 2015

# A tip of the fedora to Fedora Forum members Sea, Skull One, marko, Dangermouse
# for help with code

<< COMMENT
* Install and configure the Oracle version of VirtualBox for Fedora 22 only.
* Install the Oracle VirtualBox Extension Pack.
* Handle all platforms, i686, PAE and x86_64 .
* Clean up when finished.
* Remove previously installed VirtualBox.
* Support color / no color (sudo NOCOLOR=1 22_oracle_virtualbox.sh)
COMMENT

# 10.04.15 - Constantly updating the current VirtualBox versioning numbers.
# 09.13.15 - Adding Fedora 23 to the mix, I think...
# 09.12.15 - Constantly changing VirtualBox versions
# 07.22.15 - Decided to support only the current release of Fedora
# 07.19.15 - No longer need YUM since we're Fedora 21 and later.
# 07.19.15 - Got me a couple errors to deal with ...
# 07.09.15 - Fedora 21 and 22 only. No more Fedora 20.
# 07.09.15 - Version 5.0 ??
# 06.08.18 - Working with the Fedora 22 rpm
# 06.07.17 - Huh?
# 05.14.15 - Add feature to import and install the Oracle public key
# 05.14.15 - Update VirtualBox version to 4.3.28
# 05.12.15 - Test run under Fedora 22 Beta.
# 04.26.15 - Can I add an uninstall (safely) feature?
# 04.26.15 - Testing... 1,2,3
# 03.26.15 - Cosmetic changes and version update
# 03.15.15 - Tested under Fedora 22 Workstation Alpha (x86_64).
# 03.14.15 - New VirtualBox version
# 02.25.15 - Betterer code to discover kernel arch.
# 02.23.15 - New code to discover kernel arch
# 02.22.15 - Seems that kernel arch discovery is not working.
# 02.21.15 - New version of VirtualBox

<< COMMENT
Additional packages needed for a successful install of VirtualBox over the different platforms, x86_64, i686 and i686+PAE include
kernel-devel-$(uname -r), gcc, qt, qt-x11, libpng15, libXmu, libXt, libvpx, dkms, and SDL
COMMENT

# Determine OS platform and install correct packages.
# PAE or no?
GETVERS=$(uname -r | grep "PAE")
if [[ $GETVERS ]] ; then
PACKFILES="kernel-PAE-devel gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms SDL"
else
PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx dkms SDL"
fi

# Determine the current version of VirtualBox
curl -Os http://download.virtualbox.org/virtualbox/LATEST.TXT
current_version=$(cat LATEST.TXT)
echo $current_version
rm LATEST.TXT

# We can easily make changes to the source file versions by changing a few variables below.
# Most recent is http://download.virtualbox.org/virtualbox/5.0.0/VirtualBox-5.0-5.0.0_102096_fedora22-1.x86_64.rpm
# http://download.virtualbox.org/virtualbox/5.0.6/VirtualBox-5.0-5.0.6_103037_fedora22-1.x86_64.rpm

VB_REL_VER="5.0-"$current_version"_103037"
VB_EXT_VER="$current_version"-103037
VB_REL_DIST="fedora22-1"
VBOX_SRC_FILE="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
VBOX_EXT_SRC="Oracle_VM_VirtualBox_Extension_Pack-${VB_EXT_VER}.vbox-extpack"
SRC_PATH="http://download.virtualbox.org/virtualbox/$current_version"
PUB_KEY="oracle_vbox.asc"

# Color definitions; the variables are null if the option NOCOLOR is set.
# Thanks Skull One!

if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 6)
OK=$(tput setaf 6)
ERRB=$(tput bold;tput setaf 1)
ERR=$(tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERRB=
ERR=
RST=
fi

# Need elevated permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
printf $OK"You're going to need elevated permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\"\n"$RST
exit 0
fi

# Release 22 or later
function get_release()
{
printf $OK"Checking Fedora release version... "$RST
RELNUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $RELNUM -lt "22" ]] ; then
clear
printf $ERR"This script is for Fedora release 22 or later.\n"$RST
exit 0
else printf $OK"Fedora $RELNUM $OKB✓"$RST
fi
echo
}

# Clear screen and print a headline.
function headline()
{
clear
printf $OK"==>$OKB VirtualBox installation script for Fedora 22.\n"$RST
printf $OK"==>$OKB Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
printf $OK"==>$OKB VirtualBox release $VB_REL_VER\n"$RST
}

# Remove Oracle VirtualBox source files if they exist in the current working directory.
function remove_source()
{
for i in $VBOX_SRC_FILE $VBOX_EXT_SRC $PUB_KEY; do
rm -f $i
done
}

# Remove any installed version of VirtualBox.
function remove_fed_vbox()
{
VBOX_INSTALLED=$(rpm -qa | grep VirtualBox)
if [[ $VBOX_INSTALLED ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
dnf -y -q erase $VBOX_INSTALLED 2>/dev/null
printf $OKB" ✓\n\n"$RST
fi
}

# Download and import the Oracle public key.
function get_public_key()
{
printf $OK"Installing the Oracle public key.\n"$RST
curl -Os https://www.virtualbox.org/download/$PUB_KEY
rpm --import $PUB_KEY
}

# Install Oracle VirtualBox from the downloaded source RPM.
function install_source()
{
if [[ -f $VBOX_SRC_FILE ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $VBOX_SRC_FILE
else
printf $ERR"The source file missing.\nThere was an error downloading the file.\n"$RST
exit 0
fi
}

# Install the Oracle VirtualBox Extension Pack.
function install_extpack()
{
if [[ -f $VBOX_EXT_SRC ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack."$RST
VBoxManage extpack install --replace $VBOX_EXT_SRC
else
printf $ERR"Oracle VirtualBox extension pack source file missing!\n"$RST
fi
}

# Get any Fedora packages typically needed to complete the VirtualBox installation without errors.
function get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Installing necessary packages$OKB "${NEWPKGS}"... "$RST
dnf -y -q install ${NEWPKGS} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
fi
}

# Test retrieval of any Fedora packages typically needed to complete the VirtualBox installation without errors.
function test_get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Packages that need to be installed are: $OKB "${NEWPKGS}"... "$RST
echo
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
echo
fi
}

# Get the VirtualBox source files from Oracle
function get_source()
{
printf $OK"Getting the VirtualBox source RPM from the Oracle download site..."$RST
remove_source
curl -Os $SRC_PATH/$VBOX_SRC_FILE
printf $OKB" ✓\n"$RST
printf $OK"Getting the VirtualBox Extension Pack source file..."$RST
curl -Os $SRC_PATH/$VBOX_EXT_SRC
printf $OKB" ✓\n"$RST
echo
}

# The script run has completed. Print a short message stating same.
function script_complete()
{
#remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

# The test script run has completed.
function script_test_complete()
{
remove_source
printf $OKB"This script test is now complete.\n"
printf $OKB"All necessary Fedora packages are installed.\n"$RST
}

# Script execution has been cancelled by the user.
function script_cancel()
{
clear
printf $OK"Script execution cancelled.\n"$RST
}

# Testing only. Show value of all variables
function show_vars()
{
echo
printf $OK"VB_REL_VER is $OKB$VB_REL_VER\n"$RST
printf $OK"VB_EXT_VER is $OKB$VB_EXT_VER\n"$RST
printf $OK"VB_REL_DIST is $OKB$VB_REL_DIST\n"$RST
printf $OK"VBOX_SRC_FILE is $OKB$VBOX_SRC_FILE\n"$RST
printf $OK"VBOX_EXT_SRC is $OKB$VBOX_EXT_SRC\n"$RST
printf $OK"SRC_PATH is $OKB$SRC_PATH\n"$RST
}

function testonly()
{
clear
printf $ERRB"===== TEST ONLY. NO PACKAGES ARE BEING INSTALLED.=====\n"$RST
}

# Main script flow
function menu()
{
clear
headline
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into the newest kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n/t/v> "$RST
read yn
case $yn in
y) get_release
remove_fed_vbox
get_packages
get_public_key
get_source
install_source
install_extpack
script_complete
;;

n) script_cancel
exit 0
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is install missing packages. It also downloads VirtualBox and the Extension Pack.
t) testonly
get_release
test_get_packages
get_source
script_test_complete
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is show the current value of all of the variables.
v) get_release
show_vars
;;
*) script_cancel
exit 0
;;
esac
}
menu

glennzo
4th October 2015, 04:08 PM
Got an error while using the script on a fresh install to a physical machine.


error: Failed dependencies:
libvpx.so.1()(64bit) is needed by VirtualBox-5.0-5.0.6_103037_fedora22-1.x86_64


I solved this by installing compat-libvpx1 and re-running the installation script.

dnf install compat-libvpx1

This was on a Fedora 23 Mate install. You may not get the same error under Gnome or others.

zuser
4th October 2015, 09:00 PM
Sorry, didn't see this post until just now. Have you tried the script in the last few days? I believe the errror(s) were caused by a version mismatch type of issue. The Oracle web page that I pull latest version info from was not updated at the same time VirtualBox was, so for several days it was at 5.0.2 when everything VirtualBox was at 5.0.4. The script has worked well for me once the versioning info was updated on Oracle's end.

glennzo,
Thanks for that. I'm away for a few days but will try again when I get back

flyingdutchman
5th October 2015, 12:30 PM
I always install Virtualbox with Autoten from autoten.co.uk it works perfectly.

There is no need to re-invent the wheel.

glennzo
5th October 2015, 01:02 PM
I always install Virtualbox with Autoten from autoten.co.uk it works perfectly.

There is no need to re-invent the wheel.

Helpful. Thanks!

MrNice
12th November 2015, 05:24 PM
Hi,

I had to update your script to get the last version:

COMMENT

# 10.12.15 - Update to current version VirtualBox-5.0-5.0.10_104061_fedora22-1.x86_64

...
VB_REL_VER="5.0-"$current_version"_104061"
VB_EXT_VER="$current_version"_104061


However I had a first error and I fixed it by removing the tags in the curl command

# Determine the current version of VirtualBox
# curl -Os http://download.virtualbox.org/virtualbox/LATEST.TXT
curl -Os http://download.virtualbox.org/virtualbox/LATEST.TXT
current_version=$(cat LATEST.TXT)
echo $current_version
rm LATEST.TXT

The I had a second error and I am stuck:

Updating / installing...
1:VirtualBox-5.0-5.0.10_104061_fedo################################ # [100%]

Creating group 'vboxusers'. VM users must be member of that group!

No precompiled module for this kernel found -- trying to build one. Messages
emitted during module compilation will be logged to /var/log/vbox-install.log.

Stopping VirtualBox kernel modules [ OK ]
Uninstalling old VirtualBox DKMS kernel modules [ OK ]
Trying to register the VirtualBox kernel modules using DKMS[ OK ]
Starting VirtualBox kernel modules [FAILED]
(modprobe vboxdrv failed. Please use 'dmesg' to find out why)
Installing Oracle VirtualBox extension pack.
WARNING: The vboxdrv kernel module is not loaded. Either there is no module
available for the current kernel (4.2.5-201.fc22.x86_64) or it failed to
load. Please recompile the kernel module and install it by

sudo /sbin/vboxconfig

You will not be able to start VMs until this problem is fixed.
VBoxManage: error: RTZipGzipDecompressIoStream failed: VERR_ZIP_BAD_HEADER
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component ExtPackFileWrap, interface IExtPackFile, callee nsISupports
VBoxManage: error: Context: "Install(fReplace, __null, ptrProgress.asOutParam())" at line 1156 of file VBoxManageMisc.cpp
Oracle VirtualBox is now installed.
Script run complete.
dmesg says

[ 3315.864431] audit: type=1130 audit(1447344605.514:222): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=vboxballoonctrl-service comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
[ 3315.886832] audit: type=1130 audit(1447344605.536:223): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=vboxautostart-service comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
[ 3315.909387] audit: type=1130 audit(1447344605.559:224): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=vboxweb-service comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
[ 3316.162429] audit: type=1106 audit(1447344605.812:225): pid=3235 uid=1000 auid=1000 ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:session_close grantors=pam_keyinit,pam_limits,pam_systemd,pam_un ix,pam_xauth acct="root" exe="/usr/bin/su" hostname=? addr=? terminal=pts/0 res=success'
[ 3316.162666] audit: type=1104 audit(1447344605.812:226): pid=3235 uid=1000 auid=1000 ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:setcred grantors=pam_unix acct="root" exe="/usr/bin/su" hostname=? addr=? terminal=pts/0 res=success'

Could you help me?
Thanks

glennzo
13th November 2015, 09:14 AM
First thing that comes to mind is kernel-devel. Is that installed? The script should have installed it, but ...


gjohnson@toshiba23=> rpm -qa | grep kernel-devel
kernel-devel-4.2.5-300.fc23.x86_64

This script is not the be all to end all. It needs constant tweaking so it will be able to stay with the current version of VirtualBox and the Extension Pack. There is a constant chase to remain current that I don't know how to handle in the script.

I just made a change to the minor version (101573 to 104061) and the script ran flawlessly on a Fedora 22 LXDE virtual machine.

Works for Fedora 23 also, but need to install compat-libvpx1 (at least for LXDE) which was not installed by the script.

There is a minor error under Fedora 23 when the script looks at the Fedora release number but it doesn't negatively affect the script's execution or results.

MrNice
13th November 2015, 10:35 AM
Kernel-devel is installed

rpm -qa | grep kernel-devel
kernel-devel-4.2.5-201.fc22.x86_64
kernel-devel-4.1.7-200.fc22.x86_64
kernel-devel-4.2.3-200.fc22.x86_64
Another idea?

Edit: Maybe I should upgrade to F23 before?

glennzo
13th November 2015, 10:38 AM
May be a silly question but, are you running kernel 4.2.5-201? Sometimes we forget that we need to reboot the machine...

MrNice
13th November 2015, 10:56 AM
uname -r
4.2.5-201.fc22.x86_64
I think so

glennzo
13th November 2015, 11:04 AM
I honestly think that the problem is with VirtualBox and not the script.

Run the script again but this time choose the "t" option. This will tell you if all necessary packages are installed / were installed.

The "t" option makes no changes to your system. It is merely a simple test.

MrNice
13th November 2015, 11:17 AM
===== TEST ONLY. NO PACKAGES ARE BEING INSTALLED.=====
Checking Fedora release version... Fedora 22 ✓
Checking for necessary packages...
==> kernel-devel-4.2.5-201.fc22.x86_64: ✓
==> gcc: ✓
==> qt: ✓
==> qt-x11: ✓
==> libpng15: ✓
==> libXmu: ✓
==> libXt: ✓
==> libvpx: ✓
==> dkms: ✓
==> SDL: ✓
==> Nothing new to install.

I'll upgrade and see if it's better. I'll let you know

glennzo
13th November 2015, 11:28 AM
As you wish.

MrNice
15th November 2015, 03:39 PM
Hi glennzo,

I am back with

uname -r
4.2.5-300.fc23.x86_64
I changed the script

VB_REL_VER="5.0-"$current_version"_104061"
VB_EXT_VER="$current_version"-104061
Unfortunately I still get the same error

Creating group 'vboxusers'. VM users must be member of that group!

No precompiled module for this kernel found -- trying to build one. Messages
emitted during module compilation will be logged to /var/log/vbox-install.log.

Stopping VirtualBox kernel modules [ OK ]
Uninstalling old VirtualBox DKMS kernel modules [ OK ]
Trying to register the VirtualBox kernel modules using DKMS[ OK ]
Starting VirtualBox kernel modules [FAILED]
(modprobe vboxdrv failed. Please use 'dmesg' to find out why)
Installing Oracle VirtualBox extension pack.
WARNING: The vboxdrv kernel module is not loaded. Either there is no module
available for the current kernel (4.2.5-300.fc23.x86_64) or it failed to
load. Please recompile the kernel module and install it by

sudo /sbin/vboxconfig

You will not be able to start VMs until this problem is fixed.
0%...10%...20%...30%...40%...50%...60%...70%...80% ...90%...100%
Successfully installed "Oracle VM VirtualBox Extension Pack".
Oracle VirtualBox is now installed.
Script run complete.


dmesg | tail
[20976.027872] audit: type=1131 audit(1447597569.939:311): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=fprintd comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
[21023.383106] audit: type=1107 audit(1447597617.337:312): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='Unknown permission stop for class system exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
[21023.383693] audit: type=1107 audit(1447597617.338:313): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='Unknown permission stop for class system exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
[21023.432143] audit: type=1107 audit(1447597617.386:314): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='Unknown permission stop for class system exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
[21023.432382] audit: type=1107 audit(1447597617.387:315): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='Unknown permission stop for class system exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
[21023.475104] audit: type=1107 audit(1447597617.429:316): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='Unknown permission stop for class system exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
[21023.475342] audit: type=1107 audit(1447597617.430:317): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='Unknown permission stop for class system exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
[21023.853701] audit: type=1107 audit(1447597617.808:318): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='Unknown permission stop for class system exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
[21023.854016] audit: type=1107 audit(1447597617.809:319): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='Unknown permission stop for class system exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
[21023.982420] audit: type=1107 audit(1447597617.937:320): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='Unknown permission stop for class system exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'

Any idea?

MrNice
15th November 2015, 04:17 PM
I found this thread
https://forums.virtualbox.org/viewtopic.php?f=7&t=69356
Look at the last post

Solved it. I just had to change the boot mode from 'UEFI' to 'UEFI with CSM'. Virtualbox now works fine.
I'll find how is my boot.
What do you think?

glennzo
15th November 2015, 05:15 PM
Boot mode where, in the system BIOS?

glennzo
15th November 2015, 05:33 PM
On my new EFI/UEFI laptop, minutes ago.
http://www.forums.fedoraforum.org/picture.php?albumid=366&pictureid=2195
http://www.forums.fedoraforum.org/picture.php?albumid=366&pictureid=2196

MrNice
15th November 2015, 05:56 PM
I can't find CSM, moreover this could jeopardize the security.

MrNice
15th November 2015, 09:23 PM
I found another track
http://gorka.eguileor.com/category/technology/linux/

$ su -c 'systemctl status vboxdrv'
Password:
● vboxdrv.service - VirtualBox Linux kernel module
Loaded: loaded (/usr/lib/virtualbox/vboxdrv.sh; enabled; vendor preset: disabled)
Active: active (exited) since Sun 2015-11-15 18:26:54 GMT; 1h 30min ago
Process: 866 ExecStart=/usr/lib/virtualbox/vboxdrv.sh start (code=exited, status=0/SUCCESS)

Nov 15 18:26:54 bla.bla systemd[1]: Starting VirtualBox Linux kernel module...
Nov 15 18:26:54 bla.bla vboxdrv.sh[866]: Starting VirtualBox kernel modules [FAILED]
Nov 15 18:26:54 bla.bla vboxdrv.sh[866]: (modprobe vboxdrv failed. Please use 'dmesg' to find out why)
Nov 15 18:26:54 bla.bla systemd[1]: Started VirtualBox Linux kernel module.


$ su -c 'modprobe -v vboxdrv'
Password:
insmod /lib/modules/4.2.5-300.fc23.x86_64/extra/vboxdrv.ko
modprobe: ERROR: could not insert 'vboxdrv': Required key not available


openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj "/CN=Akrog/"
Generating a 2048 bit RSA private key
.................................................. ............+++
.....+++
writing new private key to 'MOK.priv'
-----

$ modinfo vboxdrv
filename: /lib/modules/4.2.5-300.fc23.x86_64/extra/vboxdrv.ko
version: 5.0.10 (0x00240000)
license: GPL
description: Oracle VM VirtualBox Support Driver
author: Oracle Corporation
srcversion: 342F9F95905EFBCEFD26E63
depends:
vermagic: 4.2.5-300.fc23.x86_64 SMP mod_unload
signer: Akrog
sig_key: CE:CF:93:26:C4:B3:A7:3F:47:BC:CF:EE:DB:CD:1B:A3:13 :FA:B8:C1
sig_hashalgo: sha256
parm: force_async_tsc:force the asynchronous TSC mode (int)

$ su -c '/usr/src/kernels/$(uname -r)/scripts/sign-file sha256 ./MOK.priv ./MOK.der $(modinfo -n vboxdrv)'

$ modinfo vboxdrv
filename: /lib/modules/4.2.5-300.fc23.x86_64/extra/vboxdrv.ko
version: 5.0.10 (0x00240000)
license: GPL
description: Oracle VM VirtualBox Support Driver
author: Oracle Corporation
srcversion: 342F9F95905EFBCEFD26E63
depends:
vermagic: 4.2.5-300.fc23.x86_64 SMP mod_unload
signer: Akrog
sig_key: 01:48:C2:35:2B:E2:F3:51:C1:E3:79:89:06:93:01:72:7D :F7:FA:BA
sig_hashalgo: sha256
parm: force_async_tsc:force the asynchronous TSC mode (int)

$ mokutil --import MOK.der
input password:
input password again:
Failed to enroll new keys

ATTENTION:
This last command need to be run as root !!!
$ su -c 'mokutil --import MOK.der'

I don't know what is the last requested password. Is it a new to set or a previous to access rights?
MokManager.efi is installed in boot partition.
What did I miss?

MrNice
16th November 2015, 09:09 AM
I found the answer of my previous question
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-signing-kernel-modules-for-secure-boot.html
26.8.4.3. System Administrator Manually Adding Public Key to the MOK List

However I am wondering why I have to do all that manually. This should be done by the system in the same way here
https://ask.fedoraproject.org/en/question/75010/what-would-cause-mokutil-to-fail-when-trying-to-enroll-new-keys/

Where is my mistake?

Edit:
Second answer
https://ask.fedoraproject.org/en/question/71742/mokutil-failed-to-write-mokpw/
mokutil needs to be run as root, have you tried sudo?

Did it, accepted, now I'll reboot

Edit 2:
In the boot, I had a new screen to enroll the key. I had to enter the MOK password created with mokutil then reboot.
Now Virtualbox is running fine.
I hope I'll NOT have to do this every time I'll have an update...
However I have the way to do.

At least solved for now.
Hope this will help other.

Many thanks glennzo for your help

glennzo
9th January 2016, 04:35 PM
Latest version of my script. Tested minutes ago for Fedora 23 / LXDE / X86_64.


#!/bin/bash
# 22_oracle_virtualbox.sh

# Glenn A. Johnson
# Started January 18, 2015
# Updated January 9, 2016

# A tip of the fedora to Fedora Forum members Sea, Skull One, marko, Dangermouse
# for help with code

<< COMMENT
* Install and configure the Oracle version of VirtualBox for Fedora 22 or later.
* Install the Oracle VirtualBox Extension Pack.
* Handle all platforms, i686, PAE and x86_64 .
* Clean up when finished.
* Remove previously installed VirtualBox.
* Support color / no color (sudo NOCOLOR=1 22_oracle_virtualbox.sh)

Additional packages needed for a successful install of VirtualBox over the different platforms, x86_64, i686 and i686+PAE include
kernel-devel-$(uname -r), gcc, qt, qt-x11, libpng15, libXmu, libXt, libvpx, compat-libvpx1, dkms, and SDL
COMMENT

# Determine OS platform and install correct packages.
# PAE or no?
GETVERS=$(uname -r | grep "PAE")
if [[ $GETVERS ]] ; then
PACKFILES="kernel-PAE-devel gcc qt qt-x11 libpng15 libXmu libXt libvpx compat-libvpx1 dkms SDL"
else
PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx compat-libvpx1 dkms SDL"
fi

# Determine the current version of VirtualBox
curl -Os http://download.virtualbox.org/virtualbox/LATEST.TXT
current_version=$(cat LATEST.TXT)
echo $current_version
rm LATEST.TXT

# We can easily make changes to the source file versions by changing a few variables below.
# Most recent is http://download.virtualbox.org/virtualbox/5.0.10/VirtualBox-5.0-5.0.10_104815_fedora22-1.x86_64.rpm
# http://download.virtualbox.org/virtualbox/5.0.10/VirtualBox-5.0-5.0.10_104815_fedora22-1.x86_64.rpm

VB_REL_VER="5.0-"$current_version"_104815"
VB_EXT_VER="$current_version"-104815
VB_REL_DIST="fedora22-1"
VBOX_SRC_FILE="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
VBOX_EXT_SRC="Oracle_VM_VirtualBox_Extension_Pack-${VB_EXT_VER}.vbox-extpack"
SRC_PATH="http://download.virtualbox.org/virtualbox/$current_version"
PUB_KEY="oracle_vbox.asc"

# Color definitions; the variables are null if the option NOCOLOR is set.
# Thanks Skull One!

if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 6)
OK=$(tput setaf 6)
ERRB=$(tput bold;tput setaf 1)
ERR=$(tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERRB=
ERR=
RST=
fi

# Need elevated permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
printf $OK"You're going to need elevated permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\"\n"$RST
exit 0
fi

# Release 22 or later
function get_release()
{
printf $OK"Checking Fedora release version... "$RST
RELNUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $RELNUM -lt "22" ]] ; then
clear
printf $ERR"This script is for Fedora release 22 or later.\n"$RST
exit 0
else printf $OK"Fedora $RELNUM $OKB✓"$RST
fi
echo
}

# Clear screen and print a headline.
function headline()
{
clear
printf $OK"==>$OKB VirtualBox installation script for Fedora 22.\n"$RST
printf $OK"==>$OKB Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
printf $OK"==>$OKB VirtualBox release $VB_REL_VER\n"$RST
}

# Remove Oracle VirtualBox source files if they exist in the current working directory.
function remove_source()
{
for i in $VBOX_SRC_FILE $VBOX_EXT_SRC $PUB_KEY; do
rm -f $i
done
}

# Remove any installed version of VirtualBox.
function remove_fed_vbox()
{
VBOX_INSTALLED=$(rpm -qa | grep VirtualBox)
if [[ $VBOX_INSTALLED ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
dnf -y -q erase $VBOX_INSTALLED 2>/dev/null
printf $OKB" ✓\n\n"$RST
fi
}

# Download and import the Oracle public key.
function get_public_key()
{
printf $OK"Installing the Oracle public key.\n"$RST
curl -Os https://www.virtualbox.org/download/$PUB_KEY
rpm --import $PUB_KEY
}

# Install Oracle VirtualBox from the downloaded source RPM.
function install_source()
{
if [[ -f $VBOX_SRC_FILE ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $VBOX_SRC_FILE
else
printf $ERR"The source file missing.\nThere was an error downloading the file.\n"$RST
exit 0
fi
}

# Install the Oracle VirtualBox Extension Pack.
function install_extpack()
{
if [[ -f $VBOX_EXT_SRC ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack."$RST
VBoxManage extpack install --replace $VBOX_EXT_SRC
else
printf $ERR"Oracle VirtualBox extension pack source file missing!\n"$RST
fi
}

# Get any Fedora packages typically needed to complete the VirtualBox installation without errors.
function get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Installing necessary packages$OKB "${NEWPKGS}"... "$RST
dnf -y -q install ${NEWPKGS} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
fi
}

# Test retrieval of any Fedora packages typically needed to complete the VirtualBox installation without errors.
function test_get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Packages that need to be installed are: $OKB "${NEWPKGS}"... "$RST
echo
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
echo
fi
}

# Get the VirtualBox source files from Oracle
function get_source()
{
printf $OK"Getting the VirtualBox source RPM from the Oracle download site..."$RST
remove_source
curl -Os $SRC_PATH/$VBOX_SRC_FILE
printf $OKB" ✓\n"$RST
printf $OK"Getting the VirtualBox Extension Pack source file..."$RST
curl -Os $SRC_PATH/$VBOX_EXT_SRC
printf $OKB" ✓\n"$RST
echo
}

# The script run has completed. Print a short message stating same.
function script_complete()
{
#remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

# The test script run has completed.
function script_test_complete()
{
remove_source
printf $OKB"This script test is now complete.\n"
#printf $OKB"All necessary Fedora packages are installed.\n"$RST
}

# Script execution has been cancelled by the user.
function script_cancel()
{
clear
printf $OK"Script execution cancelled.\n"$RST
}

# Testing only. Show value of all variables
function show_vars()
{
echo
printf $OK"VB_REL_VER is $OKB$VB_REL_VER\n"$RST
printf $OK"VB_EXT_VER is $OKB$VB_EXT_VER\n"$RST
printf $OK"VB_REL_DIST is $OKB$VB_REL_DIST\n"$RST
printf $OK"VBOX_SRC_FILE is $OKB$VBOX_SRC_FILE\n"$RST
printf $OK"VBOX_EXT_SRC is $OKB$VBOX_EXT_SRC\n"$RST
printf $OK"SRC_PATH is $OKB$SRC_PATH\n"$RST
}

function testonly()
{
clear
printf $ERRB"===== TEST ONLY. NO PACKAGES ARE BEING INSTALLED.=====\n"$RST
}

# Main script flow
function menu()
{
clear
headline
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into the newest kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n/t/v> "$RST
read yn
case $yn in
y) get_release
remove_fed_vbox
get_packages
get_public_key
get_source
install_source
install_extpack
script_complete
;;

n) script_cancel
exit 0
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is install missing packages. It also downloads VirtualBox and the Extension Pack.
t) testonly
get_release
test_get_packages
get_source
script_test_complete
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is show the current value of all of the variables.
v) get_release
show_vars
;;
*) script_cancel
exit 0
;;
esac
}
menu # Call the main menu.

romu70
14th January 2016, 11:21 AM
Doesn't work for me Glenn, here is an extract of the output:


Installing the Oracle public key.
Getting the VirtualBox source RPM from the Oracle download site... ✓
Getting the VirtualBox Extension Pack source file... ✓

Installing Oracle VirtualBox
error: open of <html> failed: No such file or directory
error: open of <head> failed: No such file or directory
...

glennzo
17th January 2016, 12:18 PM
Did the virtuabox rpm and the extension pack download as expected? Do those files exist in your working folder?

Possible cause and solution here (http://forums.fedoraforum.org/archive/index.php/t-272001.html).

romu70
18th January 2016, 12:38 PM
Hi Glenn,
I managed to get VB thanks to another way, but here is what I remembered:
- yes, both files (VB and VB Extension Pack) did exist in my home folder
- The VB RPM was not completely downloaded, because at the script crash, the file was less than 60 kB.

roundboy
19th January 2016, 05:17 AM
Hi Glenn,

I had 2 problems with the script, both easy to fix:

1) I cut and past of the script into a 22_oracle_virtualbox.sh file using gedit. The copy included a space at the end of each line. For some reason COMMENT didn't like this. I do not know why. All I did was remove the spaces at the end of lines 11 thru 21.

2) The invocation of curl on line 33 is causing a problem. The copy expands the link's markup. I took out the {url} and {/url} and the script worked for me.

I had fun debugging this script. I haven't done this in at least 10 years and I now know how the rust builds up in the brain.

Great script. Works great. Thanks.

Dave

glennzo
19th January 2016, 09:59 AM
Hi Glenn,

I had 2 problems with the script, both easy to fix:

1) Cut and past of the script into a 22_oracle_virtualbox.sh file using gedit. The copy included a space at the end of each line. For some reason COMMENT didn't like this. I do not know why. All I did was remove the spaces at the end of lines 11 thru 21.

2) The following invocation of curl on line 33 is causing the problem.
curl -Os http://download.virtualbox.org/virtualbox/LATEST.TXT

I took out the "" and "" references and the script worked for me.

I had fun debugging this script. I haven't done this in at least 10 years and I now know how the rust builds up in the brain.

Great script. Works great. Thanks.

Dave
Maybe copy/paste isn't the best method for passing a script to one another? File uploads are broken within the forum else I'd upload a .tar.gz file of same.

glennzo
2nd July 2016, 11:05 PM
Hey today! I maintain this script for my own amusement. Here's the latest update. The script worked well, minutes ago, for Fedora 24 Mate (x86_64).


#!/bin/bash
# 22_oracle_virtualbox.sh

# Glenn A. Johnson
# Started January 18, 2015
# Updated July 2, 2016

# A tip of the fedora to Fedora Forum members Sea, Skull One, marko, Dangermouse
# for help with code

<< COMMENT
* Install and configure the Oracle version of VirtualBox for Fedora 22 or later.
* Install the Oracle VirtualBox Extension Pack.
* Handle all platforms, i686, PAE and x86_64 .
* Clean up when finished.
* Remove previously installed VirtualBox.
* Support color / no color (sudo NOCOLOR=1 22_oracle_virtualbox.sh)
COMMENT

# 07.02.16 - Just checking
# 05.04.16 - Never ending version updates.
# 01.30.16 - Never ending version updates.
# 01.24.16 - Never ending version updates.
# 01.05.16 - Checking in.
# 12.27.15 - VirtualBox version update
# 12.15.15 - VirtualBox version update
# 11.13.15 - Constantly updating the current VirtualBox versioning numbers.
# 10.21.15 - Constantly updating the current VirtualBox versioning numbers.
# 10.04.15 - Constantly updating the current VirtualBox versioning numbers.
# 09.13.15 - Adding Fedora 23 to the mix, I think...
# 09.12.15 - Constantly changing VirtualBox versions
# 07.22.15 - Decided to support only the current release of Fedora
# 07.19.15 - No longer need YUM since we're Fedora 21 and later.
# 07.19.15 - Got me a couple errors to deal with ...
# 07.09.15 - Fedora 21 and 22 only. No more Fedora 20.
# 07.09.15 - Version 5.0 ??
# 06.08.18 - Working with the Fedora 22 rpm
# 06.07.17 - Huh?
# 05.14.15 - Add feature to import and install the Oracle public key
# 05.14.15 - Update VirtualBox version to 4.3.28
# 05.12.15 - Test run under Fedora 22 Beta.
# 04.26.15 - Can I add an uninstall (safely) feature?
# 04.26.15 - Testing... 1,2,3
# 03.26.15 - Cosmetic changes and version update
# 03.15.15 - Tested under Fedora 22 Workstation Alpha (x86_64).
# 03.14.15 - New VirtualBox version
# 02.25.15 - Betterer code to discover kernel arch.
# 02.23.15 - New code to discover kernel arch
# 02.22.15 - Seems that kernel arch discovery is not working.
# 02.21.15 - New version of VirtualBox

<< COMMENT
Additional packages needed for a successful install of VirtualBox over the different platforms, x86_64, i686 and i686+PAE include
kernel-devel-$(uname -r), gcc, qt, qt-x11, libpng15, libXmu, libXt, libvpx, compat-libvpx1, dkms, and SDL
COMMENT

# Determine OS platform and install correct packages.
# PAE or no?
GETVERS=$(uname -r | grep "PAE")
if [[ $GETVERS ]] ; then
PACKFILES="kernel-PAE-devel gcc qt qt-x11 libpng15 libXmu libXt libvpx compat-libvpx1 dkms SDL"
else
PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx compat-libvpx1 dkms SDL"
fi

# Determine the current version of VirtualBox
curl -Os http://download.virtualbox.org/virtualbox/LATEST.TXT
current_version=$(cat LATEST.TXT)
echo $current_version
rm LATEST.TXT

# We can easily make changes to the source file versions by changing a few variables below.
# Most recent is http://download.virtualbox.org/virtualbox/5.0.10/VirtualBox-5.0-5.0.10_108355_fedora22-1.x86_64.rpm
# http://download.virtualbox.org/virtualbox/5.0.10/VirtualBox-5.0-5.0.10_108355_fedora22-1.x86_64.rpm
# http://download.virtualbox.org/virtualbox/5.0.20/VirtualBox-5.0-5.0.20_108355_fedora22-1.x86_64.rpm

VB_REL_VER="5.0-"$current_version"_108355"
VB_EXT_VER="$current_version"-108355
VB_REL_DIST="fedora24-1"
VBOX_SRC_FILE="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
VBOX_EXT_SRC="Oracle_VM_VirtualBox_Extension_Pack-${VB_EXT_VER}.vbox-extpack"
SRC_PATH="http://download.virtualbox.org/virtualbox/$current_version"
PUB_KEY="oracle_vbox.asc"

# Color definitions; the variables are null if the option NOCOLOR is set.
# Thanks Skull One!

if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 6)
OK=$(tput setaf 6)
ERRB=$(tput bold;tput setaf 1)
ERR=$(tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERRB=
ERR=
RST=
fi

# Need elevated permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
printf $OK"You're going to need elevated permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\"\n"$RST
exit 0
fi

# Release 22 or later
function get_release()
{
printf $OK"Checking Fedora release version... "$RST
RELNUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $RELNUM -lt "22" ]] ; then
clear
printf $ERR"This script is for Fedora release 22 or later.\n"$RST
exit 0
else printf $OK"Fedora $RELNUM $OKB✓"$RST
fi
echo
}

# Clear screen and print a headline.
function headline()
{
clear
printf $OK"==>$OKB VirtualBox installation script for Fedora 22.\n"$RST
printf $OK"==>$OKB Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
printf $OK"==>$OKB VirtualBox release $VB_REL_VER\n"$RST
}

# Remove Oracle VirtualBox source files if they exist in the current working directory.
function remove_source()
{
for i in $VBOX_SRC_FILE $VBOX_EXT_SRC $PUB_KEY; do
rm -f $i
done
}

# Remove any installed version of VirtualBox.
function remove_fed_vbox()
{
VBOX_INSTALLED=$(rpm -qa | grep VirtualBox)
if [[ $VBOX_INSTALLED ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
dnf -y -q erase $VBOX_INSTALLED 2>/dev/null
printf $OKB" ✓\n\n"$RST
fi
}

# Download and import the Oracle public key.
function get_public_key()
{
printf $OK"Installing the Oracle public key.\n"$RST
curl -Os https://www.virtualbox.org/download/$PUB_KEY
rpm --import $PUB_KEY
}

# Install Oracle VirtualBox from the downloaded source RPM.
function install_source()
{
if [[ -f $VBOX_SRC_FILE ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $VBOX_SRC_FILE
else
printf $ERR"The source file missing.\nThere was an error downloading the file.\n"$RST
exit 0
fi
}

# Install the Oracle VirtualBox Extension Pack.
function install_extpack()
{
if [[ -f $VBOX_EXT_SRC ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack."$RST
VBoxManage extpack install --replace $VBOX_EXT_SRC
else
printf $ERR"Oracle VirtualBox extension pack source file missing!\n"$RST
fi
}

# Get any Fedora packages typically needed to complete the VirtualBox installation without errors.
function get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Installing necessary packages$OKB "${NEWPKGS}"... "$RST
dnf -y -q install ${NEWPKGS} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
fi
}

# Test retrieval of any Fedora packages typically needed to complete the VirtualBox installation without errors.
function test_get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Packages that need to be installed are: $OKB "${NEWPKGS}"... "$RST
echo
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
echo
fi
}

# Get the VirtualBox source files from Oracle
function get_source()
{
printf $OK"Getting the VirtualBox source RPM from the Oracle download site..."$RST
remove_source
curl -Os $SRC_PATH/$VBOX_SRC_FILE
printf $OKB" ✓\n"$RST
printf $OK"Getting the VirtualBox Extension Pack source file..."$RST
curl -Os $SRC_PATH/$VBOX_EXT_SRC
printf $OKB" ✓\n"$RST
echo
}

# The script run has completed. Print a short message stating same.
function script_complete()
{
#remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

# The test script run has completed.
function script_test_complete()
{
remove_source
printf $OKB"This script test is now complete.\n"
#printf $OKB"All necessary Fedora packages are installed.\n"$RST
}

# Script execution has been cancelled by the user.
function script_cancel()
{
clear
printf $OK"Script execution cancelled.\n"$RST
}

# Testing only. Show value of all variables
function show_vars()
{
echo
printf $OK"VB_REL_VER is $OKB$VB_REL_VER\n"$RST
printf $OK"VB_EXT_VER is $OKB$VB_EXT_VER\n"$RST
printf $OK"VB_REL_DIST is $OKB$VB_REL_DIST\n"$RST
printf $OK"VBOX_SRC_FILE is $OKB$VBOX_SRC_FILE\n"$RST
printf $OK"VBOX_EXT_SRC is $OKB$VBOX_EXT_SRC\n"$RST
printf $OK"SRC_PATH is $OKB$SRC_PATH\n"$RST
}

function testonly()
{
clear
printf $ERRB"===== TEST ONLY. NO PACKAGES ARE BEING INSTALLED.=====\n"$RST
}

# Main script flow
function menu()
{
clear
headline
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into the newest kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n/t/v> "$RST
read yn
case $yn in
y) get_release
remove_fed_vbox
get_packages
get_public_key
get_source
install_source
install_extpack
remove_source
script_complete
;;

n) script_cancel
exit 0
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is test for missing packages and test the download process for VirtualBox and GuestAdditions.
t) testonly
get_release
test_get_packages
get_source
script_test_complete
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is show the current value of all of the variables.
v) get_release
show_vars
;;
*) script_cancel
exit 0
;;
esac
}
menu # Call the main menu.

http://www.forums.fedoraforum.org/picture.php?albumid=430&pictureid=2317

So, while I'm not the most elegant script writer, it works. There are a few tweaks that I'd like to make. Just can't figure out how. Maybe I'll request some help soon.

glennzo
18th December 2016, 12:06 AM
Latest working script. Fedora 25.


#!/bin/bash
# 25_oracle_virtualbox.sh
# This script is for Fedora 25 only at this time

# Glenn A. Johnson
# Started January 18, 2015
# Updated December 11, 2016

<< COMMENT
* Install and configure the Oracle version of VirtualBox for Fedora 22 or later.
* Install the Oracle VirtualBox Extension Pack.
* Handle all platforms, i686, PAE and x86_64 .
* Clean up when finished.
* Remove previously installed VirtualBox.
* Support color / no color (sudo NOCOLOR=1 22_oracle_virtualbox.sh)
COMMENT

<< COMMENT
Additional packages needed for a successful install of VirtualBox over the different platforms, x86_64, i686 and i686+PAE include
kernel-devel-$(uname -r), curl gcc, qt, qt-x11, libpng15, libXmu, libXt, libvpx, compat-libvpx1, dkms, SDL and wget

qt5-qtx11extras (this brings in other packages like qt5-qtbase qt5-qtbase-gui amongst others)
libpython2.7.so.1.0()(64bit) - Well, Fedora 24 ships with Python35
python(abi) = 2.7 - Well, Fedora 24 ships with Pythin35
COMMENT

# Determine OS platform and install correct packages.
# PAE or no?
GETVERS=$(uname -r | grep "PAE")
if [[ $GETVERS ]] ; then
PACKFILES="kernel-PAE-devel curl dkms gcc libpng15 libXmu libXt libvpx qt qt-x11 qt5-qtx11extras SDL wget"
else
PACKFILES="kernel-devel-$(uname -r) curl dkms gcc libpng15 libXmu libXt libvpx qt qt-x11 qt5-qtx11extras SDL wget"
fi

# Determine the current version of VirtualBox
curl_installed=$(rpm -qa | grep curl)
if [[ ! $curl_installed ]] ; then
printf "Installing package curl. Please wait ..."
dnf -y -q install curl
echo
fi
curl -Os http://download.virtualbox.org/virtualbox/LATEST.TXT
current_version=$(cat LATEST.TXT)
echo $current_version
rm LATEST.TXT

# We can easily make changes to the source file versions by changing a few variables below.
# Most recent is http://download.virtualbox.org/virtualbox/5.1.10/VirtualBox-5.1-5.1.10_112026_fedora25-1.x86_64.rpm

VB_REL_VER="5.1-"$current_version"_112026"
VB_EXT_VER="$current_version"-112026
VB_REL_DIST="fedora25-1"
VBOX_SRC_FILE="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
VBOX_EXT_SRC="Oracle_VM_VirtualBox_Extension_Pack-${VB_EXT_VER}.vbox-extpack"
SRC_PATH="http://download.virtualbox.org/virtualbox/$current_version"
PUB_KEY="oracle_vbox.asc"

# Color definitions; the variables are null if the option NOCOLOR is set.
# Thanks Skull One!

if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 6)
OK=$(tput setaf 6)
ERRB=$(tput bold;tput setaf 1)
ERR=$(tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERRB=
ERR=
RST=
fi

# Need elevated permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
printf $OK"You're going to need elevated permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\"\n"$RST
exit 0
fi

# Redhat derivatives and release 24 only
function get_release()
{
if [[ ! -f /etc/redhat-release ]] ; then
printf $ERRB"This script is for Redhat derivatives only.\n"$RST
exit 0
else
printf $OK"Checking Fedora release version... "$RST
RELNUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $RELNUM -lt "25" ]] ; then #!= "24"
clear
printf $ERR"This script is for Fedora release 25 only.\n"$RST
exit 0
else printf $OK"Fedora $RELNUM $OKB✓"$RST
fi
fi
echo
}

# Clear screen and print a headline.
function headline()
{
clear
printf $OK"==>$OKB VirtualBox installation script for Fedora Linux.\n"$RST
printf $OK"==>$OKB Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
printf $OK"==>$OKB VirtualBox release $VB_REL_VER\n"$RST
}

# Remove Oracle VirtualBox source files if they exist in the current working directory.
function remove_source()
{
for i in $VBOX_SRC_FILE $VBOX_EXT_SRC $PUB_KEY; do
rm -f $i
done
}

# Remove any installed version of VirtualBox.
function remove_fed_vbox()
{
VBOX_INSTALLED=$(rpm -qa | grep VirtualBox)
if [[ $VBOX_INSTALLED ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
dnf -y -q erase $VBOX_INSTALLED 2>/dev/null
printf $OKB" ✓\n\n"$RST
fi
}

# Download and import the Oracle public key.
function get_public_key()
{
curl_installed=$(rpm -qa | grep curl )
if [[ ! $curl_installed ]] ; then
printf $OK"Installing package curl. Please wait ..."$RST
dnf -y -q install curl
echo
fi
printf $OK"Installing the Oracle public key ... ✓\n"$RST
curl -Os https://www.virtualbox.org/download/$PUB_KEY
rpm --import $PUB_KEY
}

# Install Oracle VirtualBox from the downloaded source RPM.
function install_source()
{
if [[ -f $VBOX_SRC_FILE ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $VBOX_SRC_FILE
else
printf $ERR"The source file missing.\nThere was an error downloading the file.\n"$RST
exit 0
fi
}

# Install the Oracle VirtualBox Extension Pack.
function install_extpack()
{
if [[ -f $VBOX_EXT_SRC ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack."$RST
VBoxManage extpack install --replace $VBOX_EXT_SRC
else
printf $ERR"Oracle VirtualBox extension pack source file missing!\n"$RST
fi
}

# Get any Fedora packages typically needed to complete the VirtualBox installation without errors.
function get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Installing necessary packages$OKB "${NEWPKGS}"... "$RST
dnf -y -q install ${NEWPKGS} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
fi
}

# Test retrieval of any Fedora packages typically needed to complete the VirtualBox installation without errors.
function test_get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Packages that need to be installed are: $OKB "${NEWPKGS}"... "$RST
echo
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
echo
fi
}

# Get the VirtualBox source files from Oracle
function get_source()
{
printf $OK"Getting the VirtualBox source RPM from the Oracle download site..."$RST
remove_source
curl -Os $SRC_PATH/$VBOX_SRC_FILE
printf $OKB" ✓\n"$RST
printf $OK"Getting the VirtualBox Extension Pack source file..."$RST
curl -Os $SRC_PATH/$VBOX_EXT_SRC
printf $OKB" ✓\n"$RST
echo
}

# The script run has completed. Print a short message stating same.
function script_complete()
{
#remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

# The test script run has completed.
function script_test_complete()
{
remove_source
printf $OKB"This script test is now complete.\n"
#printf $OKB"All necessary Fedora packages are installed.\n"$RST
}

# Script execution has been cancelled by the user.
function script_cancel()
{
clear
printf $OK"Script execution cancelled.\n"$RST
}

# Testing only. Show value of all variables
function show_vars()
{
echo
printf $OK"VB_REL_VER is $OKB$VB_REL_VER\n"$RST
printf $OK"VB_EXT_VER is $OKB$VB_EXT_VER\n"$RST
printf $OK"VB_REL_DIST is $OKB$VB_REL_DIST\n"$RST
printf $OK"VBOX_SRC_FILE is $OKB$VBOX_SRC_FILE\n"$RST
printf $OK"VBOX_EXT_SRC is $OKB$VBOX_EXT_SRC\n"$RST
printf $OK"SRC_PATH is $OKB$SRC_PATH\n"$RST
}

function testonly()
{
clear
printf $ERRB"===== TEST ONLY. NO PACKAGES ARE BEING INSTALLED.=====\n"$RST
}

# Main script flow
function menu()
{
clear
#get_release
headline
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into the newest kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n> "$RST
read yn
case $yn in
y) remove_fed_vbox
get_packages
get_public_key
get_source
install_source
install_extpack
remove_source
script_complete
;;

n) script_cancel
exit 0
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is test for missing packages and test the download process for VirtualBox and GuestAdditions.
t) testonly
test_get_packages
get_source
script_test_complete
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is show the current value of all of the variables.
v) show_vars
;;
*) script_cancel
exit 0
;;
esac
}
menu # Call the main menu.

glennzo
16th May 2017, 01:15 AM
Latest update to the install script.


#!/bin/bash
# 25_oracle_virtualbox.sh
# This script is for Fedora 25 and up

# Glenn A. Johnson
# Started January 18, 2015
# Updated May 14, 2017

<< COMMENT
* Install and configure the Oracle version of VirtualBox for Fedora 25 or later.
* Install the Oracle VirtualBox Extension Pack.
* Handle all platforms, i686, PAE and x86_64 .
* Clean up when finished.
* Remove previously installed VirtualBox.
* Support color / no color (sudo NOCOLOR=1 22_oracle_virtualbox.sh)

* Additional packages needed for a successful install of VirtualBox over the different platforms, x86_64, i686 and i686+PAE include
* kernel-devel-$(uname -r), curl gcc, qt, qt-x11, libpng15, libXmu, libXt, libvpx, compat-libvpx1, SDL and wget
* qt5-qtx11extras (this brings in other packages like qt5-qtbase qt5-qtbase-gui amongst others)
* libpython2.7.so.1.0()(64bit)
COMMENT

# Determine OS platform and install correct packages.
# PAE or no?
GETVERS=$(uname -r | grep "PAE")
if [[ $GETVERS ]] ; then
PACKFILES="kernel-PAE-devel curl gcc libpng15 libXmu libXt libvpx qt qt-x11 qt5-qtx11extras SDL wget"
else
PACKFILES="kernel-devel-$(uname -r) curl gcc libpng15 libXmu libXt libvpx qt qt-x11 qt5-qtx11extras SDL wget"
fi

# Determine the newest available version of VirtualBox
curl_installed=$(rpm -qa | grep curl)
if [[ ! $curl_installed ]] ; then
printf "Installing package curl. Please wait ..."
dnf -y -q install curl
echo
fi
curl -Os http://download.virtualbox.org/virtualbox/LATEST.TXT
current_version=$(cat LATEST.TXT)
echo $current_version
rm LATEST.TXT

# We can easily make changes to the source file versions by changing a few variables below.
# Most recent is http://download.virtualbox.org/virtualbox/5.1.22/VirtualBox-5.1-5.1.22_115126_fedora25-1.x86_64.rpm

VB_REL_VER="5.1-"$current_version"_115126"
VB_EXT_VER="$current_version"-115126
VB_REL_DIST="fedora25-1"
VBOX_SRC_FILE="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
VBOX_EXT_SRC="Oracle_VM_VirtualBox_Extension_Pack-${VB_EXT_VER}.vbox-extpack"
SRC_PATH="http://download.virtualbox.org/virtualbox/$current_version"
PUB_KEY="oracle_vbox.asc"

# Color definitions; the variables are null if the option NOCOLOR is set.
# Thanks Skull One!

if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 6)
OK=$(tput setaf 6)
ERRB=$(tput bold;tput setaf 1)
ERR=$(tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERRB=
ERR=
RST=
fi

# Need elevated permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
printf $OK"You're going to need elevated permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\"\n"$RST
exit 0
fi

# Redhat and derivatives - release 25 only
function get_release()
{
if [[ ! -f /etc/redhat-release ]] ; then
printf $ERRB"This script is for Redhat derivatives only.\n"$RST
exit 0
else
printf $OK"Checking Fedora release version... "$RST
RELNUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $RELNUM -lt "25" ]] ; then
clear
printf $ERR"This script is for Fedora release 25 only.\n"$RST
exit 0
else printf $OK"Fedora $RELNUM $OKB✓"$RST
fi
fi
echo
}

# Clear screen and print a headline.
function headline()
{
clear
printf $OK"==>$OKB VirtualBox installation script for Fedora Linux.\n"$RST
printf $OK"==>$OKB Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
printf $OK"==>$OKB VirtualBox release $VB_REL_VER\n"$RST
}

# Remove Oracle VirtualBox source files if they exist in the current working directory.
function remove_source()
{
for i in $VBOX_SRC_FILE $VBOX_EXT_SRC $PUB_KEY; do
rm -f $i
done
}

# Remove any installed version of VirtualBox.
function remove_fed_vbox()
{
VBOX_INSTALLED=$(rpm -qa | grep VirtualBox)
if [[ $VBOX_INSTALLED ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
dnf -y -q erase $VBOX_INSTALLED 2>/dev/null
printf $OKB" ✓\n\n"$RST
fi
}

# Download and import the Oracle public key.
function get_public_key()
{
curl_installed=$(rpm -qa | grep curl )
if [[ ! $curl_installed ]] ; then
printf $OK"Installing package curl. Please wait ..."$RST
dnf -y -q install curl
echo
fi
printf $OK"Installing the Oracle public key ... ✓\n"$RST
curl -Os https://www.virtualbox.org/download/$PUB_KEY
rpm --import $PUB_KEY
}

# Install Oracle VirtualBox from the downloaded source RPM.
function install_source()
{
if [[ -f $VBOX_SRC_FILE ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $VBOX_SRC_FILE --quiet
else
printf $ERR"The source file missing.\nThere was an error downloading the file.\n"$RST
exit 0
fi
}

# Install the Oracle VirtualBox Extension Pack.
function install_extpack()
{
if [[ -f $VBOX_EXT_SRC ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack."$RST
VBoxManage extpack install --replace --accept-license=715c7246dc0f779ceab39446812362b2f9bf64a55e d5d3a905f053cfab36da9e $VBOX_EXT_SRC
else
printf $ERR"Oracle VirtualBox extension pack source file missing!\n"$RST
fi
# License accepted. For batch installaltion add
# --accept-license=715c7246dc0f779ceab39446812362b2f9bf64a55e d5d3a905f053cfab36da9e
# to the VBoxManage command line.
}

# Get any Fedora packages typically needed to complete the VirtualBox installation without errors.
function get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Installing necessary packages$OKB "${NEWPKGS}"... "$RST
dnf -y -q install ${NEWPKGS} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
fi
}

# Test retrieval of any Fedora packages typically needed to complete the VirtualBox installation without errors.
function test_get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Packages that need to be installed are: $OKB "${NEWPKGS}"... "$RST
echo
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
echo
fi
}

# Get the VirtualBox source files from Oracle
function get_source()
{
printf $OK"Getting the VirtualBox source RPM from the Oracle download site..."$RST
remove_source
curl -Os $SRC_PATH/$VBOX_SRC_FILE
printf $OKB" ✓\n"$RST
printf $OK"Getting the VirtualBox Extension Pack source file..."$RST
curl -Os $SRC_PATH/$VBOX_EXT_SRC
printf $OKB" ✓\n"$RST
echo
}

# The script run has completed. Print a short message stating same.
function script_complete()
{
#remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

# The test script run has completed.
function script_test_complete()
{
remove_source
printf $OKB"This script test is now complete.\n"
#printf $OKB"All necessary Fedora packages are installed.\n"$RST
}

# Script execution has been cancelled by the user.
function script_cancel()
{
clear
printf $OK"Script execution cancelled.\n"$RST
}

# Testing only. Show value of all variables
function show_vars()
{
echo
printf $OK"VB_REL_VER is $OKB$VB_REL_VER\n"$RST
printf $OK"VB_EXT_VER is $OKB$VB_EXT_VER\n"$RST
printf $OK"VB_REL_DIST is $OKB$VB_REL_DIST\n"$RST
printf $OK"VBOX_SRC_FILE is $OKB$VBOX_SRC_FILE\n"$RST
printf $OK"VBOX_EXT_SRC is $OKB$VBOX_EXT_SRC\n"$RST
printf $OK"SRC_PATH is $OKB$SRC_PATH\n"$RST
}

function testonly()
{
clear
printf $ERRB"===== TEST ONLY. NO PACKAGES ARE BEING INSTALLED.=====\n"$RST
}

# Main script flow
function menu()
{
clear
headline
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into the newest installed kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n> "$RST
read yn
case $yn in
y) remove_fed_vbox
get_packages
get_public_key
get_source
install_source
install_extpack
remove_source
script_complete
;;

n) script_cancel
exit 0
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is test for missing packages and test the download process for VirtualBox and GuestAdditions.
t) testonly
test_get_packages
get_source
script_test_complete
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is show the current value of all of the variables.
v) show_vars
;;
*) script_cancel
exit 0
;;
esac
}
menu # Call the main menu.

robertdaleweir
25th September 2017, 04:24 PM
Hey today! I maintain this script for my own amusement. Here's the latest update. The script worked well, minutes ago, for Fedora 24 Mate (x86_64).


#!/bin/bash
# 22_oracle_virtualbox.sh

# Glenn A. Johnson
# Started January 18, 2015
# Updated July 2, 2016

# A tip of the fedora to Fedora Forum members Sea, Skull One, marko, Dangermouse
# for help with code

<< COMMENT
* Install and configure the Oracle version of VirtualBox for Fedora 22 or later.
* Install the Oracle VirtualBox Extension Pack.
* Handle all platforms, i686, PAE and x86_64 .
* Clean up when finished.
* Remove previously installed VirtualBox.
* Support color / no color (sudo NOCOLOR=1 22_oracle_virtualbox.sh)
COMMENT



# Determine OS platform and install correct packages.
# PAE or no?
GETVERS=$(uname -r | grep "PAE")
if [[ $GETVERS ]] ; then
PACKFILES="kernel-PAE-devel gcc qt qt-x11 libpng15 libXmu libXt libvpx compat-libvpx1 dkms SDL"
else
PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx compat-libvpx1 dkms SDL"
fi

# Determine the current version of VirtualBox
curl -Os http://download.virtualbox.org/virtualbox/LATEST.TXT
current_version=$(cat LATEST.TXT)
echo $current_version
rm LATEST.TXT

# We can easily make changes to the source file versions by changing a few variables below.
# Most recent is http://download.virtualbox.org/virtualbox/5.0.10/VirtualBox-5.0-5.0.10_108355_fedora22-1.x86_64.rpm
# http://download.virtualbox.org/virtualbox/5.0.10/VirtualBox-5.0-5.0.10_108355_fedora22-1.x86_64.rpm
# http://download.virtualbox.org/virtualbox/5.0.20/VirtualBox-5.0-5.0.20_108355_fedora22-1.x86_64.rpm

VB_REL_VER="5.0-"$current_version"_108355"
VB_EXT_VER="$current_version"-108355
VB_REL_DIST="fedora24-1"
VBOX_SRC_FILE="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm"
VBOX_EXT_SRC="Oracle_VM_VirtualBox_Extension_Pack-${VB_EXT_VER}.vbox-extpack"
SRC_PATH="http://download.virtualbox.org/virtualbox/$current_version"
PUB_KEY="oracle_vbox.asc"

# Color definitions; the variables are null if the option NOCOLOR is set.
# Thanks Skull One!

if [ -z "$NOCOLOR" ]; then
OKB=$(tput bold;tput setaf 6)
OK=$(tput setaf 6)
ERRB=$(tput bold;tput setaf 1)
ERR=$(tput setaf 1)
RST=$(tput sgr0)
else
OKB=
OK=
ERRB=
ERR=
RST=
fi

# Need elevated permissions at some point, might as well do it now.
if [[ $EUID -ne 0 ]] ; then
clear
printf $OK"You're going to need elevated permissions at some point. Let's get that out of the way now.\nUse "sudo" or "su -c"\n"$RST
exit 0
fi

# Release 22 or later
function get_release()
{
printf $OK"Checking Fedora release version... "$RST
RELNUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
if [[ $RELNUM -lt "22" ]] ; then
clear
printf $ERR"This script is for Fedora release 22 or later.\n"$RST
exit 0
else printf $OK"Fedora $RELNUM $OKB✓"$RST
fi
echo
}

# Clear screen and print a headline.
function headline()
{
clear
printf $OK"==>$OKB VirtualBox installation script for Fedora 22.\n"$RST
printf $OK"==>$OKB Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$RST
printf $OK"==>$OKB VirtualBox release $VB_REL_VER\n"$RST
}

# Remove Oracle VirtualBox source files if they exist in the current working directory.
function remove_source()
{
for i in $VBOX_SRC_FILE $VBOX_EXT_SRC $PUB_KEY; do
rm -f $i
done
}

# Remove any installed version of VirtualBox.
function remove_fed_vbox()
{
VBOX_INSTALLED=$(rpm -qa | grep VirtualBox)
if [[ $VBOX_INSTALLED ]] ; then
printf $OK"Removing previously installed instance of VirtualBox. Please wait..."$RST
dnf -y -q erase $VBOX_INSTALLED 2>/dev/null
printf $OKB" ✓\n\n"$RST
fi
}

# Download and import the Oracle public key.
function get_public_key()
{
printf $OK"Installing the Oracle public key.\n"$RST
curl -Os https://www.virtualbox.org/download/$PUB_KEY
rpm --import $PUB_KEY
}

# Install Oracle VirtualBox from the downloaded source RPM.
function install_source()
{
if [[ -f $VBOX_SRC_FILE ]] ; then
printf $OK"Installing Oracle VirtualBox\n"$RST
rpm -Uvh $VBOX_SRC_FILE
else
printf $ERR"The source file missing.\nThere was an error downloading the file.\n"$RST
exit 0
fi
}

# Install the Oracle VirtualBox Extension Pack.
function install_extpack()
{
if [[ -f $VBOX_EXT_SRC ]] ; then
echo $OK"Installing Oracle VirtualBox extension pack."$RST
VBoxManage extpack install --replace $VBOX_EXT_SRC
else
printf $ERR"Oracle VirtualBox extension pack source file missing!\n"$RST
fi
}

# Get any Fedora packages typically needed to complete the VirtualBox installation without errors.
function get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Installing necessary packages$OKB "${NEWPKGS}"... "$RST
dnf -y -q install ${NEWPKGS} 2>/dev/null
echo -e $OKB"\nDone installing packages.\n"$RST
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
fi
}

# Test retrieval of any Fedora packages typically needed to complete the VirtualBox installation without errors.
function test_get_packages()
{
printf $OK"Checking for necessary packages..."$RST
echo
NEWPKGS=""
for i in $PACKFILES ; do
printf $OK"==> $i: "
rpm -q $i > /dev/null
if [ $? -eq 0 ] ; then
printf $OKB"✓\n"$RST
else
printf $ERR"✗\n"$RST
NEWPKGS="${NEWPKGS} $i"
fi
done
if [ -n "${NEWPKGS}" ]; then
echo -e -n $OK"==> Packages that need to be installed are: $OKB "${NEWPKGS}"... "$RST
echo
else
printf $OK"==>$OKB Nothing new to install.\n"$RST
echo
fi
}

# Get the VirtualBox source files from Oracle
function get_source()
{
printf $OK"Getting the VirtualBox source RPM from the Oracle download site..."$RST
remove_source
curl -Os $SRC_PATH/$VBOX_SRC_FILE
printf $OKB" ✓\n"$RST
printf $OK"Getting the VirtualBox Extension Pack source file..."$RST
curl -Os $SRC_PATH/$VBOX_EXT_SRC
printf $OKB" ✓\n"$RST
echo
}

# The script run has completed. Print a short message stating same.
function script_complete()
{
#remove_source
printf $OKB"Oracle VirtualBox is now installed.\n"
printf $OKB"Script run complete.\n"$RST
}

# The test script run has completed.
function script_test_complete()
{
remove_source
printf $OKB"This script test is now complete.\n"
#printf $OKB"All necessary Fedora packages are installed.\n"$RST
}

# Script execution has been cancelled by the user.
function script_cancel()
{
clear
printf $OK"Script execution cancelled.\n"$RST
}

# Testing only. Show value of all variables
function show_vars()
{
echo
printf $OK"VB_REL_VER is $OKB$VB_REL_VER\n"$RST
printf $OK"VB_EXT_VER is $OKB$VB_EXT_VER\n"$RST
printf $OK"VB_REL_DIST is $OKB$VB_REL_DIST\n"$RST
printf $OK"VBOX_SRC_FILE is $OKB$VBOX_SRC_FILE\n"$RST
printf $OK"VBOX_EXT_SRC is $OKB$VBOX_EXT_SRC\n"$RST
printf $OK"SRC_PATH is $OKB$SRC_PATH\n"$RST
}

function testonly()
{
clear
printf $ERRB"===== TEST ONLY. NO PACKAGES ARE BEING INSTALLED.=====\n"$RST
}

# Main script flow
function menu()
{
clear
headline
printf $OK"\nFor this script to succeed you need to be running the newest available and installed kernel.\n\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system. Then boot into the newest kernel and run this script again.\n"$RST
printf $OKB"\nShall we continue? <y/n/t/v> "$RST
read yn
case $yn in
y) get_release
remove_fed_vbox
get_packages
get_public_key
get_source
install_source
install_extpack
remove_source
script_complete
;;

n) script_cancel
exit 0
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is test for missing packages and test the download process for VirtualBox and GuestAdditions.
t) testonly
get_release
test_get_packages
get_source
script_test_complete
;;
# Test menu entry used for development. End user should ignore this menu option.
# All this does is show the current value of all of the variables.
v) get_release
show_vars
;;
*) script_cancel
exit 0
;;
esac
}
menu # Call the main menu.

http://www.forums.fedoraforum.org/picture.php?albumid=430&pictureid=2317

So, while I'm not the most elegant script writer, it works. There are a few tweaks that I'd like to make. Just can't figure out how. Maybe I'll request some help soon.

Hi glennzo
I am going to ask for a bit of assistance with this particular script. I am using F24 (I know it is EOL). Is there anyway I can use this script to install VirtualBox on my F24. It doesn't find the source, which is understandable. Is there any place where I could get the source files so the script could install VirtualBox for me? I had to cut some of your script out to post < 10000 Characters.

glennzo
25th September 2017, 05:19 PM
Hello. If you can wait (I'm at work) I'll post help tonight. You're about 3 hours behind me. I'm on the east coast north of Boston.

Tough to do on a Windows machine.

robertdaleweir
25th September 2017, 11:39 PM
Hello. If you can wait (I'm at work) I'll post help tonight. You're about 3 hours behind me. I'm on the east coast north of Boston.

Tough to do on a Windows machine.

Hi 'glennzo'
No problem, I just got home myself. I am trying to install it on F24 (Desktop) and I was successful on my F24 Laptop but cannot seem to get it working on my Desktop F24. It seems to be missing something critical, as it never grabs the win2k.iso which I have successfully installed on my Laptop and on a Win7 VirtualBox as well.
I must have used your script on my Laptop prior to EOL and thereby everything was there online and now it is not. I actually cannot remember.

dd_wizard
25th September 2017, 11:58 PM
Try installing the dependencies listed in the script manually with dnf and see which ones aren't available in repos. Then you can go to koji and grab the packages, I believe, and manually install them.

dd_wizard

---------- Post added at 03:58 PM ---------- Previous post was at 03:54 PM ----------

Wow, talk about a blast from the past... I haven't seen that avatar in years. :D

dd_wizard

glennzo
26th September 2017, 12:41 AM
Hi 'glennzo'
No problem, I just got home myself. I am trying to install it on F24 (Desktop) and I was successful on my F24 Laptop but cannot seem to get it working on my Desktop F24. It seems to be missing something critical, as it never grabs the win2k.iso which I have successfully installed on my Laptop and on a Win7 VirtualBox as well.
I must have used your script on my Laptop prior to EOL and thereby everything was there online and now it is not. I actually cannot remember.

Are there some error message(s) that you see?

I don't understand the reference to the win2k.iso?

robertdaleweir
26th September 2017, 12:51 AM
Are there some error message(s) that you see?

I don't understand the reference to the win2k.iso?

Hi
I was trying to install a WIN2K ISO which I was able to do on my Laptop. It never asks me for the Image file during the install of the VM. See attached for Error messages. Thanks...

glennzo
26th September 2017, 12:55 AM
May be a silly question but have you rebooted the Fedora machine? If not, please do. Then try installing win2k.iso

robertdaleweir
26th September 2017, 12:56 AM
May be a silly question but have you rebooted the Fedora machine? If not, please do. Then try installing win2k.iso

Yes I have but I will try that again.

glennzo
26th September 2017, 12:57 AM
So VirtualBox installed properly but you can't seem to install Windows?

robertdaleweir
26th September 2017, 12:59 AM
So VirtualBox installed properly but you can't seem to install Windows?

Correct and yes it is the same and I rebooted.

glennzo
26th September 2017, 01:00 AM
Is the Fedora machine running the newest available kernel?

And kernel-devel for the newest kernel.

robertdaleweir
26th September 2017, 01:01 AM
Is the Fedora machine running the newest available kernel?

Yes it is running Kernel 4.11.12-100.fc24.x86_64 which I believe is the last for F24.
Virtual box is 5.1.26 r117224.

These are the same as are on my Laptop which allowed me to install Win2k

dd_wizard
26th September 2017, 01:09 AM
If the kernel module isn't present, at least dkms, and maybe kernel-devel aren't installed. You probably need to manually download and install dependencies since this is F24.

dd_wizard

robertdaleweir
26th September 2017, 01:16 AM
If the kernel module isn't present, at least dkms, and maybe kernel-devel aren't installed. You probably need to manually download and install dependencies since this is F24.

dd_wizard

Hi dd_wizard
When I run one of the lines in the 'F22 and up' script it doesn't find kernel-devel and dkms.


[root@PANTRY ~]# dnf install kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 libXmu libXt libvpx compat-libvpx1 dkms SDL

Last metadata expiration check: 1:29:05 ago on Mon Sep 25 15:43:18 2017.
No package kernel-devel-4.11.12-100.fc24.x86_64 available.
Package gcc-6.3.1-1.fc24.x86_64 is already installed, skipping.
Package qt-1:4.8.7-18.fc24.i686 is already installed, skipping.
Package qt-1:4.8.7-18.fc24.x86_64 is already installed, skipping.
Package qt-x11-1:4.8.7-18.fc24.i686 is already installed, skipping.
Package qt-x11-1:4.8.7-18.fc24.x86_64 is already installed, skipping.
Package libXmu-1.1.2-4.fc24.x86_64 is already installed, skipping.
Package libXmu-1.1.2-4.fc24.i686 is already installed, skipping.
Package libXt-1.1.5-3.fc24.x86_64 is already installed, skipping.
Package libXt-1.1.5-3.fc24.i686 is already installed, skipping.
Package libvpx-1.5.0-4.fc24.x86_64 is already installed, skipping.
Package SDL-1.2.15-21.fc24.x86_64 is already installed, skipping.
Error: Unable to find a match.

How can I get those two packages?

dd_wizard
26th September 2017, 05:27 AM
Top right of the forum page, click on "Fedora Project", click on "Fedora Build System (Koji)" near the bottom of the drop down menu. Search for kernel in the Koji window. Use "uname -r" in a terminal to find out which kernel you're using. Pick the kernel version that you got with "uname -r". Scroll down to the the correct archecture, then pick kernel-devel. I have a folder named RPMS that I use for rpms from Koji. Then search for dkms in Koji and download the most recent F24 dkms from Koji to the same directory. Open a terminal window in that directory and run "sudo dnf install ./kernel-devel* ./dkms*". Reboot and a virtualbox kernel module should be built. If your CPU activity runs high for 30 seconds or so, it did.

dd_wizard

robertdaleweir
26th September 2017, 05:43 AM
Top right of the forum page, click on "Fedora Project", click on "Fedora Build System (Koji)" near the bottom of the drop down menu. Search for kernel in the Koji window. Use "uname -r" in a terminal to find out which kernel you're using. Pick the kernel version that you got with "uname -r". Scroll down to the the correct archecture, then pick kernel-devel. I have a folder named RPMS that I use for rpms from Koji. Then search for dkms in Koji and download the most recent F24 dkms from Koji to the same directory. Open a terminal window in that directory and run "sudo dnf install ./kernel-devel* ./dkms*". Reboot and a virtualbox kernel module should be built. If your CPU activity runs high for 30 seconds or so, it did.

dd_wizard

Hi dd_wizard
Thank you so much. I looked around the Web but I got a lot of 404 errors and had probelms fionding those two packages. Have a great day!

ATITNoor
4th November 2017, 11:54 AM
It proceeds Object because of type-erasure which replaces all nonspecific types with Purpose. There is no way to determine at runtime what generic type was on condition that at compile-time.