desktop/virtualbox/vboxsetup.sh

148 lines
3.7 KiB
Bash
Raw Normal View History

2011-08-18 07:56:18 +08:00
#!/bin/bash
. /etc/vbox/vbox.cfg
. /etc/conf.d/vboxdrv
2012-09-16 02:18:07 +08:00
if [ "$EUID" -ne "0" ]; then
echo "Please run this script with root privileges"
exit 0
fi
2011-08-18 07:56:18 +08:00
if [[ -n "$INSTALL_DIR" ]]; then
2012-09-16 02:18:07 +08:00
MODULE_SRC="$INSTALL_DIR/src/vboxhost"
2011-08-18 07:56:18 +08:00
else
echo "Missing /etc/vbox/vbox.cfg"
exit 0
fi
2012-09-16 02:18:07 +08:00
BUILDINTMP="$MODULE_SRC/build_in_tmp"
DODKMS="$MODULE_SRC/do_dkms"
2011-08-18 07:56:18 +08:00
# detection of dkms (if not disabled)
if [[ "$DISABLE_DKMS" =~ [yY][eE][sS] ]]; then
USE_DKMS=0
else
which dkms &>/dev/null
USE_DKMS=$((! $?))
fi
# STARTBUILD cannot be used with dkms
(( USE_DKMS == 1 )) && START_BUILD=no
load() {
if [[ "$START_BUILD" =~ [yY][eE][sS] ]]; then
# check if module exists
2012-09-16 02:18:07 +08:00
c=$('find' "/lib/modules/$(uname -r)" -type f -regex '.*/vbox\(drv\|netadp\|netflt\|pci\).ko' | wc -l)
2011-08-18 07:56:18 +08:00
((c == 0 )) && setup
fi
2012-09-16 02:18:07 +08:00
echo "Loading VirtualBox kernel modules"
2011-08-18 07:56:18 +08:00
# trivial loading
2012-09-16 02:18:07 +08:00
for module in vbox{drv,netadp,netflt,pci}; do
2011-08-18 07:56:18 +08:00
modprobe $module &>/dev/null
done
# check
2012-09-16 02:18:07 +08:00
for module in vbox{drv,netadp,netflt,pci}; do
2011-08-18 07:56:18 +08:00
if ! grep -q "^${module}" /proc/modules; then
2012-09-16 02:18:07 +08:00
echo "Module ${module} could not be loaded"
2011-08-18 07:56:18 +08:00
return 1
fi
done
}
unload() {
2012-09-16 02:18:07 +08:00
echo "Unloading VirtualBox kernel modules"
2011-08-18 07:56:18 +08:00
# trivial unload
2012-09-16 02:18:07 +08:00
for module in vbox{pci,netflt,netadp,drv}; do
2011-08-18 07:56:18 +08:00
if grep -q "^${module}" /proc/modules; then
modprobe -r $module &>/dev/null
fi
done
# check
2012-09-16 02:18:07 +08:00
for module in vbox{pci,drv,netadp,netflt}; do
2011-08-18 07:56:18 +08:00
if grep -q "^${module}" /proc/modules; then
2012-09-16 02:18:07 +08:00
echo "Module ${module} could not be unloaded"
2011-08-18 07:56:18 +08:00
return 1
fi
done
}
remove() {
2012-09-16 02:18:07 +08:00
unload
2011-08-18 07:56:18 +08:00
if (( USE_DKMS == 1 )); then
2012-09-16 02:18:07 +08:00
echo "Removing VirtualBox kernel modules with DKMS"
$DODKMS uninstall vboxhost vboxdrv vboxnetflt vboxnetadp > $LOG
2011-08-18 07:56:18 +08:00
else
2012-09-16 02:18:07 +08:00
echo "Removing VirtualBox kernel modules"
find "/lib/modules/$(uname -r)" -type f -regex '.*/vbox\(pci\|drv\|netadp\|netflt\).ko' -delete
2011-08-18 07:56:18 +08:00
fi
}
setup() {
if (( USE_DKMS == 1 )); then
2012-09-16 02:18:07 +08:00
echo "Trying to register the VirtualBox kernel modules using DKMS"
$DODKMS install vboxhost "$INSTALL_VER" >> $LOG
2011-08-18 07:56:18 +08:00
else
remove
2012-09-16 02:18:07 +08:00
echo "Compiling VirtualBox kernel modules"
2011-08-18 07:56:18 +08:00
LOG="/tmp/vbox-install.log"
2012-09-16 02:18:07 +08:00
if ! $BUILDINTMP \
2011-08-18 07:56:18 +08:00
--save-module-symvers /tmp/vboxdrv-Module.symvers \
2012-09-16 02:18:07 +08:00
--module-source "$MODULE_SRC/vboxdrv" \
2011-08-18 07:56:18 +08:00
--no-print-directory install > $LOG 2>&1; then
echo "Look at $LOG to find out what went wrong"
2012-09-16 02:18:07 +08:00
return 1
2011-08-18 07:56:18 +08:00
fi
2012-09-16 02:18:07 +08:00
if ! $BUILDINTMP \
2011-08-18 07:56:18 +08:00
--use-module-symvers /tmp/vboxdrv-Module.symvers \
2012-09-16 02:18:07 +08:00
--module-source "$MODULE_SRC/vboxnetflt" \
2011-08-18 07:56:18 +08:00
--no-print-directory install >> $LOG 2>&1; then
echo "Look at $LOG to find out what went wrong"
2012-09-16 02:18:07 +08:00
return 1
2011-08-18 07:56:18 +08:00
fi
2012-09-16 02:18:07 +08:00
if ! $BUILDINTMP \
2011-08-18 07:56:18 +08:00
--use-module-symvers /tmp/vboxdrv-Module.symvers \
2012-09-16 02:18:07 +08:00
--module-source "$MODULE_SRC/vboxnetadp" \
2011-08-18 07:56:18 +08:00
--no-print-directory install >> $LOG 2>&1; then
echo "Look at $LOG to find out what went wrong"
2012-09-16 02:18:07 +08:00
return 1
fi
if ! $BUILDINTMP \
--use-module-symvers /tmp/vboxdrv-Module.symvers \
--module-source "$MODULE_SRC/vboxpci" \
--no-print-directory install >> $LOG 2>&1; then
echo "Look at $LOG to find out what went wrong"
return 1
2011-08-18 07:56:18 +08:00
fi
depmod -A
2012-09-16 02:18:07 +08:00
fi
echo -e "\n==> Make sure to load the required modules to use VirtualBox"
2011-08-18 07:56:18 +08:00
}
fixusb() {
# Build our device tree
for i in /sys/bus/usb/devices/*; do
if test -r "$i/dev"; then
dev="`cat "$i/dev" 2> /dev/null`"
major="`expr "$dev" : '\(.*\):' 2> /dev/null`"
minor="`expr "$dev" : '.*:\(.*\)' 2> /dev/null`"
class="`cat $i/bDeviceClass 2> /dev/null`"
sh "$INSTALL_DIR/VBoxCreateUSBNode.sh" "$major" "$minor" "$class" 2>/dev/null
fi
done
}
case "$1" in
setup)
setup
load
2011-08-18 07:56:18 +08:00
;;
fixusb)
fixusb
;;
2012-09-16 02:18:07 +08:00
remove)
remove
;;
2011-08-18 07:56:18 +08:00
*)
2012-09-16 02:18:07 +08:00
echo "usage: $0 {setup|fixusb}"
2011-08-18 07:56:18 +08:00
esac