VBox.sh revision be75da5235e6ed26c171a06f0a7d0e718bd7f60b
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess#!/bin/sh
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess#
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess# Oracle VM VirtualBox
0a05fab9aadd37834734ffe106fc8ad4488fb3e3rbowen#
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess# Copyright (C) 2006-2010 Oracle Corporation
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess#
031b91a62d25106ae69d4693475c79618dd5e884fielding# This file is part of VirtualBox Open Source Edition (OSE), as
031b91a62d25106ae69d4693475c79618dd5e884fielding# available from http://www.virtualbox.org. This file is free software;
031b91a62d25106ae69d4693475c79618dd5e884fielding# you can redistribute it and/or modify it under the terms of the GNU
031b91a62d25106ae69d4693475c79618dd5e884fielding# General Public License (GPL) as published by the Free Software
031b91a62d25106ae69d4693475c79618dd5e884fielding# Foundation, in version 2 as it comes in the "COPYING" file of the
031b91a62d25106ae69d4693475c79618dd5e884fielding# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess#
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess
b3d2e587a32b409eca3ab23d1d1884d5199a8241kessPATH="/usr/bin:/bin:/usr/sbin:/sbin"
b3d2e587a32b409eca3ab23d1d1884d5199a8241kessCONFIG="/etc/vbox/vbox.cfg"
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess
b3d2e587a32b409eca3ab23d1d1884d5199a8241kessif [ ! -r "$CONFIG" ]; then
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess echo "Could not find VirtualBox installation. Please reinstall."
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess exit 1
b3d2e587a32b409eca3ab23d1d1884d5199a8241kessfi
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess. "$CONFIG"
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess# Note: This script must not fail if the module was not successfully installed
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess# because the user might not want to run a VM but only change VM params!
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fndif [ "$1" = "shutdown" ]; then
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess SHUTDOWN="true"
b3d2e587a32b409eca3ab23d1d1884d5199a8241kesselif ! lsmod|grep -q vboxdrv; then
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess cat << EOF
b3d2e587a32b409eca3ab23d1d1884d5199a8241kessWARNING: The vboxdrv kernel module is not loaded. Either there is no module
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess available for the current kernel (`uname -r`) or it failed to
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess load. Please recompile the kernel module and install it by
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess sudo /etc/init.d/vboxdrv setup
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess You will not be able to start VMs until this problem is fixed.
b3d2e587a32b409eca3ab23d1d1884d5199a8241kessEOF
b3d2e587a32b409eca3ab23d1d1884d5199a8241kesselif [ ! -c /dev/vboxdrv ]; then
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess cat << EOF
b3d2e587a32b409eca3ab23d1d1884d5199a8241kessWARNING: The character device /dev/vboxdrv does not exist. Try
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess sudo /etc/init.d/vboxdrv restart
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess and if that is not successful, try to re-install the package.
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess You will not be able to start VMs until this problem is fixed.
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fndEOF
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fndfi
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fndif [ -f /etc/vbox/module_not_compiled ]; then
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd cat << EOF
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fndWARNING: The compilation of the vboxdrv.ko kernel module failed during the
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd installation for some reason. Starting a VM will not be possible.
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd Please consult the User Manual for build instructions.
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fndEOF
b3d2e587a32b409eca3ab23d1d1884d5199a8241kessfi
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fndSERVER_PID=`ps -U \`whoami\` | grep VBoxSVC | awk '{ print $1 }'`
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fndif [ -z "$SERVER_PID" ]; then
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd # Server not running yet/anymore, cleanup socket path.
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd # See IPC_GetDefaultSocketPath()!
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd if [ -n "$LOGNAME" ]; then
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd rm -rf /tmp/.vbox-$LOGNAME-ipc > /dev/null 2>&1
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd else
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd rm -rf /tmp/.vbox-$USER-ipc > /dev/null 2>&1
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd fi
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fndfi
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd
b3d2e587a32b409eca3ab23d1d1884d5199a8241kessif [ "$SHUTDOWN" = "true" ]; then
4b5b56aec9f41dcf656de6534178fd353efbd43bkess if [ -n "$SERVER_PID" ]; then
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd kill -TERM $SERVER_PID
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd sleep 2
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess fi
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess exit 0
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fndfi
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fndAPP=`which $0`
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fndAPP=`basename $APP`
b3d2e587a32b409eca3ab23d1d1884d5199a8241kessAPP=${APP##/*/}
b3d2e587a32b409eca3ab23d1d1884d5199a8241kesscase "$APP" in
4b5b56aec9f41dcf656de6534178fd353efbd43bkess VirtualBox|virtualbox)
4b5b56aec9f41dcf656de6534178fd353efbd43bkess exec "$INSTALL_DIR/VirtualBox" "$@"
4b5b56aec9f41dcf656de6534178fd353efbd43bkess ;;
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess VBoxManage|vboxmanage)
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess exec "$INSTALL_DIR/VBoxManage" "$@"
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd ;;
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd VBoxSDL|vboxsdl)
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd exec "$INSTALL_DIR/VBoxSDL" "$@"
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd ;;
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess VBoxVRDP|VBoxHeadless|vboxheadless)
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess exec "$INSTALL_DIR/VBoxHeadless" "$@"
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess ;;
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess vboxwebsrv)
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess exec "$INSTALL_DIR/vboxwebsrv" "$@"
b3d2e587a32b409eca3ab23d1d1884d5199a8241kess ;;
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd *)
cf02129aebf73dd0bdf369b172eb481ff76ac5f6colm echo "Unknown application - $APP"
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd ;;
b3d2e587a32b409eca3ab23d1d1884d5199a8241kessesac
8f7d6fc3a6ad107d66934d0d75ba4a5a095e1a3fnd