c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync#!/bin/sh
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync## @file
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync# Oracle VM VirtualBox startup script, Linux hosts.
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync#
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync#
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync# Copyright (C) 2006-2016 Oracle Corporation
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync#
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync# available from http://www.virtualbox.org. This file is free software;
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync# you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync# General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync#
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncPATH="/usr/bin:/bin:/usr/sbin:/sbin"
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncCONFIG="/etc/vbox/vbox.cfg"
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync
0162ce58ecb597543f776cbc7a05fad399db033fvboxsynctest -r "${CONFIG}" &&
b4915d0cee39500bb2f42e15c25e176619929150vboxsync . "${CONFIG}"
0162ce58ecb597543f776cbc7a05fad399db033fvboxsynctest -z "${INSTALL_DIR}" &&
0162ce58ecb597543f776cbc7a05fad399db033fvboxsync if test -f /usr/lib/virtualbox/VirtualBox &&
0162ce58ecb597543f776cbc7a05fad399db033fvboxsync test -x /usr/lib/virtualbox/VirtualBox; then
0162ce58ecb597543f776cbc7a05fad399db033fvboxsync INSTALL_DIR=/usr/lib/virtualbox
0162ce58ecb597543f776cbc7a05fad399db033fvboxsync else
0162ce58ecb597543f776cbc7a05fad399db033fvboxsync echo "Could not find VirtualBox installation. Please reinstall."
0162ce58ecb597543f776cbc7a05fad399db033fvboxsync exit 1
0162ce58ecb597543f776cbc7a05fad399db033fvboxsync fi
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync# Note: This script must not fail if the module was not successfully installed
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync# because the user might not want to run a VM but only change VM params!
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncif [ "$1" = "shutdown" ]; then
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync SHUTDOWN="true"
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncelif ! lsmod|grep -q vboxdrv; then
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync cat << EOF
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncWARNING: The vboxdrv kernel module is not loaded. Either there is no module
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync available for the current kernel (`uname -r`) or it failed to
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync load. Please recompile the kernel module and install it by
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync sudo /etc/init.d/vboxdrv setup
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync You will not be able to start VMs until this problem is fixed.
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncEOF
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncelif [ ! -c /dev/vboxdrv ]; then
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync cat << EOF
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncWARNING: The character device /dev/vboxdrv does not exist. Try
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync
ae5af5aa3e87e134919787abd96b8ebfb1a19d62vboxsync sudo /etc/init.d/vboxdrv restart
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync and if that is not successful, try to re-install the package.
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync
7da1c316d25649f85e7590b66a1713c02e69d814vboxsync You will not be able to start VMs until this problem is fixed.
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncEOF
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncfi
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncif [ -f /etc/vbox/module_not_compiled ]; then
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync cat << EOF
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncWARNING: The compilation of the vboxdrv.ko kernel module failed during the
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync installation for some reason. Starting a VM will not be possible.
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync Please consult the User Manual for build instructions.
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncEOF
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncfi
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncSERVER_PID=`ps -U \`whoami\` | grep VBoxSVC | awk '{ print $1 }'`
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncif [ -z "$SERVER_PID" ]; then
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync # Server not running yet/anymore, cleanup socket path.
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync # See IPC_GetDefaultSocketPath()!
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync if [ -n "$LOGNAME" ]; then
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync rm -rf /tmp/.vbox-$LOGNAME-ipc > /dev/null 2>&1
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync else
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync rm -rf /tmp/.vbox-$USER-ipc > /dev/null 2>&1
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync fi
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncfi
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncif [ "$SHUTDOWN" = "true" ]; then
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync if [ -n "$SERVER_PID" ]; then
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync kill -TERM $SERVER_PID
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync sleep 2
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync fi
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync exit 0
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncfi
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsyncAPP=`basename $0`
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsynccase "$APP" in
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync VirtualBox|virtualbox)
299c172e41df2a2f7496c0a9198acb0f45919d51vboxsync exec "$INSTALL_DIR/VirtualBox" "$@"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync VBoxManage|vboxmanage)
299c172e41df2a2f7496c0a9198acb0f45919d51vboxsync exec "$INSTALL_DIR/VBoxManage" "$@"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync VBoxSDL|vboxsdl)
299c172e41df2a2f7496c0a9198acb0f45919d51vboxsync exec "$INSTALL_DIR/VBoxSDL" "$@"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync VBoxVRDP|VBoxHeadless|vboxheadless)
299c172e41df2a2f7496c0a9198acb0f45919d51vboxsync exec "$INSTALL_DIR/VBoxHeadless" "$@"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
ebd3c63c626c8039fdb7b95570390699333a7072vboxsync VBoxAutostart|vboxautostart)
299c172e41df2a2f7496c0a9198acb0f45919d51vboxsync exec "$INSTALL_DIR/VBoxAutostart" "$@"
ebd3c63c626c8039fdb7b95570390699333a7072vboxsync ;;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync VBoxBalloonCtrl|vboxballoonctrl)
299c172e41df2a2f7496c0a9198acb0f45919d51vboxsync exec "$INSTALL_DIR/VBoxBalloonCtrl" "$@"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync VBoxDTrace|vboxdtrace)
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync exec "$INSTALL_DIR/VBoxDTrace" "$@"
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync ;;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync vboxwebsrv)
299c172e41df2a2f7496c0a9198acb0f45919d51vboxsync exec "$INSTALL_DIR/vboxwebsrv" "$@"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync *)
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync echo "Unknown application - $APP"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync exit 1
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncesac
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsyncexit 0