2017-06-30 02:57:32 +02:00
|
|
|
#!/bin/bash
|
2017-05-10 20:01:46 +02:00
|
|
|
#
|
|
|
|
# Script to build VirtualBox host kernel modules
|
|
|
|
# Copyright C 2017 by Larry Finger
|
|
|
|
#
|
|
|
|
# This script is part of the openSUSE VirtualBox package
|
|
|
|
#
|
2017-06-25 02:21:46 +02:00
|
|
|
SOURCE="/usr/src/kernel-modules/virtualbox/src"
|
2017-05-10 20:01:46 +02:00
|
|
|
LOGFILE="/var/log/virtualbox.log"
|
|
|
|
INCLUDE="/lib/modules/`uname -r`/build/include"
|
2017-06-25 19:11:33 +02:00
|
|
|
#
|
2020-01-20 21:15:41 +01:00
|
|
|
# Test if vboxdrv module loaded. If it is, skip everything else
|
|
|
|
loaded=$(lsmod | grep vboxdrv)
|
2017-06-25 19:11:33 +02:00
|
|
|
if [ -n "$loaded" ] ; then
|
2017-08-07 22:33:23 +02:00
|
|
|
echo "Kernel modules are loaded, unload them via"
|
|
|
|
echo "systemctl stop vboxdrv.service if you wish to rebuild them."
|
|
|
|
echo "Quitting .."
|
|
|
|
exit 1
|
2017-06-25 19:11:33 +02:00
|
|
|
fi
|
|
|
|
#
|
2017-08-07 22:33:23 +02:00
|
|
|
# Check if virtualbox-host-source is installed, quit if not
|
|
|
|
if ! rpm -qf "$SOURCE/Makefile" &>/dev/null ; then
|
|
|
|
echo "Sources for building host modules are not present,"
|
2018-09-20 21:27:52 +02:00
|
|
|
echo "Use 'sudo zypper install virtualbox-host-source kernel-devel kernel-default-devel' to install them. Quitting .."
|
2017-08-07 22:33:23 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
# Check if virtualbox-host-source version matches virtualbox version
|
|
|
|
if [ "$(rpm -q virtualbox virtualbox-host-source --queryformat='%{version}-%{release}\n' 2>/dev/null | sort -u | wc -l)" -ne "1" ] ; then
|
2017-11-22 17:53:50 +01:00
|
|
|
echo "virtualbox-host-source package version doesn't match the version of virtualbox package."
|
|
|
|
echo "This situation is probably not fatal, thus we will try to continue .."
|
2017-05-10 20:01:46 +02:00
|
|
|
fi
|
|
|
|
# Prerequisites are available, start build
|
|
|
|
pushd $SOURCE > /dev/null 2>&1
|
|
|
|
echo "Building kernel modules..."
|
2017-08-07 22:33:23 +02:00
|
|
|
make clean &>/dev/null
|
2017-05-10 20:01:46 +02:00
|
|
|
make > $LOGFILE 2>&1
|
2017-06-25 19:11:33 +02:00
|
|
|
if [ "$?" -ne 0 ] ; then
|
2017-05-10 20:01:46 +02:00
|
|
|
echo ""
|
|
|
|
echo "Build of VirtualBox host kernel modules failed."
|
|
|
|
echo "Look at $LOGFILE to find reasons."
|
|
|
|
popd > /dev/null 2>&1
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Kernel modules built correctly. They will now be installed."
|
|
|
|
fi
|
|
|
|
make install >> $LOGFILE 2>&1
|
2017-06-25 19:11:33 +02:00
|
|
|
if [ "$?" -ne 0 ] ; then
|
2017-05-10 20:01:46 +02:00
|
|
|
echo ""
|
|
|
|
echo "Installation of VirtualBox host kernel modules failed."
|
|
|
|
echo "Look at $LOGFILE to find reasons."
|
|
|
|
popd > /dev/null 2>&1
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
depmod -a
|
2020-01-20 21:15:41 +01:00
|
|
|
modprobe -av vboxnetflt vboxnetadp
|
2017-05-10 20:01:46 +02:00
|
|
|
popd > /dev/null 2>&1
|
|
|
|
echo "Kernel modules are installed and loaded."
|
|
|
|
exit 0
|
|
|
|
|