VBox.sh revision b4915d0cee39500bb2f42e15c25e176619929150
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync#!/bin/sh
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync#
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync# Oracle VM VirtualBox startup script, Linux hosts.
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync#
c58f1213e628a545081c70e26c6b67a841cff880vboxsync# Copyright (C) 2006-2012 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
b4915d0cee39500bb2f42e15c25e176619929150vboxsyncif test -r "${CONFIG}"; then
b4915d0cee39500bb2f42e15c25e176619929150vboxsync . "${CONFIG}"
b4915d0cee39500bb2f42e15c25e176619929150vboxsyncelif test -f /usr/lib/virtualbox/VirtualBox &&
b4915d0cee39500bb2f42e15c25e176619929150vboxsync test -x /usr/lib/virtualbox/VirtualBox; then
b4915d0cee39500bb2f42e15c25e176619929150vboxsync INSTALL_DIR=/usr/lib/virtualbox
b4915d0cee39500bb2f42e15c25e176619929150vboxsyncelse
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync echo "Could not find VirtualBox installation. Please reinstall."
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsync exit 1
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncfi
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
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsyncrun_in_group()
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync{
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync if id -G -n $(id -u -n) | tr ' ' '\n' | grep -q "vboxusers"; then
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync AWK_SCRIPT='BEGIN { for ( i=1; i < ARGC; i++) {gsub(/'\''/, "'\''\\'\''", ARGV[i]); printf "'\''%s'\'' ", ARGV[i]}}'
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync AWK_SCRIPT="BEGIN { for ( i=1; i < ARGC; i++) {gsub(/'/, \"'\\\\'\", ARGV[i]); printf \"'%s' \", ARGV[i]}}"
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync ARGS="$(awk "$AWK_SCRIPT" "$@")"
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync echo ${ARGS} ";" "exit" | exec newgrp vboxusers
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync else
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync exec "$@"
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync fi
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync}
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsyncAPP=`basename $0`
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsynccase "$APP" in
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync VirtualBox|virtualbox)
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync run_in_group "$INSTALL_DIR/VirtualBox" "$@"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync VBoxManage|vboxmanage)
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync run_in_group "$INSTALL_DIR/VBoxManage" "$@"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync VBoxSDL|vboxsdl)
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync run_in_group "$INSTALL_DIR/VBoxSDL" "$@"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync VBoxVRDP|VBoxHeadless|vboxheadless)
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync run_in_group "$INSTALL_DIR/VBoxHeadless" "$@"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
ebd3c63c626c8039fdb7b95570390699333a7072vboxsync VBoxAutostart|vboxautostart)
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync run_in_group "$INSTALL_DIR/VBoxAutostart" "$@"
ebd3c63c626c8039fdb7b95570390699333a7072vboxsync ;;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync VBoxBalloonCtrl|vboxballoonctrl)
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync run_in_group "$INSTALL_DIR/VBoxBalloonCtrl" "$@"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync vboxwebsrv)
a664fa5a4c93cf89efebe6c071cc89e9d3d3cd61vboxsync run_in_group "$INSTALL_DIR/vboxwebsrv" "$@"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync *)
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync echo "Unknown application - $APP"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync exit 1
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync ;;
c3cd0366348bcd10e42bd7be9ea05d194394f389vboxsyncesac
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsyncexit 0