summaryrefslogtreecommitdiff
blob: f92b67f639cd98cb4d1446f6a3a437dceaa3f9e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh

INSTALL_DIR=/opt/VirtualBox
USER=$( whoami )

SERVER_PID=$( ps -U $USER | grep VBoxSVC | awk '{ print $1 }' )

if [ "$1" = shutdown ]; then
    if [ "$SERVER_PID" != "" ]; then
        kill -TERM $SERVER_PID
        sleep 2
    fi
    exit 0
fi

[ -z "$VBOX_USER_HOME" ] && VBOX_USER_HOME="$HOME/.VirtualBox"

mkdir -p "$VBOX_USER_HOME"
LOG="$VBOX_USER_HOME/VBoxSVC.log"

if [ -e /proc/modules -a ! -e /dev/vboxdrv ] ; then
	echo "Error: vboxdrv kernel module is not loaded..."
	echo "Please load the module before starting VirtualBox."
	exit 1
elif [ ! -w /dev/vboxdrv ]; then
	if [ "`id | grep vboxusers`" = "" ]; then
		echo "Error: You are not a member of the \"vboxusers\" group..."
		echo "Please add yourself to this group before starting VirtualBox."
	else
		echo "Error: /dev/vboxdrv is not writable for some reason..." 
		echo "If you recently added the current user to the vboxusers group,"
		echo "then you have to logout and re-login to take the change effect."
	fi
	exit 1
fi

export LD_LIBRARY_PATH="$INSTALL_DIR"

if [ -z "$SERVER_PID" ]; then
	rm -rf /tmp/.vbox-$USER-ipc
	[ -f "$LOG.1" ] && mv "$LOG.1" "$LOG.2"
	[ -f "$LOG.0" ] && mv "$LOG.0" "$LOG.1"
	[ -f "$LOG" ] && mv "$LOG" "$LOG.0"
	/opt/VirtualBox/VBoxSVC --daemonize >"$LOG" 2>&1
fi

APP=$( command -v "$0" )
APP=${APP##/*/}
case "$APP" in
	virtualbox)
		exec "$INSTALL_DIR/VirtualBox" "$@"
		;;
	vboxmanage)
		exec "$INSTALL_DIR/VBoxManage" "$@"
		;;
	vboxsdl)
		exec "$INSTALL_DIR/VBoxSDL" "$@"
		;;
	vboxvrdp)
		exec "$INSTALL_DIR/VBoxVRDP" "$@"
		;;
	*)
		echo "Error: Unknown application - $APP"
		exit 1
		;;
esac