1 | #!/bin/sh
|
---|
2 | ## @file
|
---|
3 | # Oracle VirtualBox startup script, Linux hosts.
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | #
|
---|
9 | # This file is part of VirtualBox base platform packages, as
|
---|
10 | # available from https://www.virtualbox.org.
|
---|
11 | #
|
---|
12 | # This program is free software; you can redistribute it and/or
|
---|
13 | # modify it under the terms of the GNU General Public License
|
---|
14 | # as published by the Free Software Foundation, in version 3 of the
|
---|
15 | # License.
|
---|
16 | #
|
---|
17 | # This program is distributed in the hope that it will be useful, but
|
---|
18 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | # General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU General Public License
|
---|
23 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | #
|
---|
25 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | #
|
---|
27 |
|
---|
28 | PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
---|
29 |
|
---|
30 | # The below is GNU-specific. See slightly further down for a version which
|
---|
31 | # works on Solaris and OS X.
|
---|
32 | TARGET=`readlink -e -- "${0}"` || exit 1
|
---|
33 | MY_DIR="${TARGET%/[!/]*}"
|
---|
34 |
|
---|
35 | # (
|
---|
36 | # path="${0}"
|
---|
37 | # while test -n "${path}"; do
|
---|
38 | # # Make sure we have at least one slash and no leading dash.
|
---|
39 | # expr "${path}" : / > /dev/null || path="./${path}"
|
---|
40 | # # Filter out bad characters in the path name.
|
---|
41 | # expr "${path}" : ".*[*?<>\\]" > /dev/null && exit 1
|
---|
42 | # # Catch embedded new-lines and non-existing (or path-relative) files.
|
---|
43 | # # $0 should always be absolute when scripts are invoked through "#!".
|
---|
44 | # test "`ls -l -d "${path}" 2> /dev/null | wc -l`" -eq 1 || exit 1
|
---|
45 | # # Change to the folder containing the file to resolve relative links.
|
---|
46 | # folder=`expr "${path}" : "\(.*/\)[^/][^/]*/*$"` || exit 1
|
---|
47 | # path=`expr "x\`ls -l -d "${path}"\`" : "[^>]* -> \(.*\)"`
|
---|
48 | # cd "${folder}"
|
---|
49 | # # If the last path was not a link then we are in the target folder.
|
---|
50 | # test -n "${path}" || pwd
|
---|
51 | # done
|
---|
52 | # )
|
---|
53 |
|
---|
54 | if test -f /usr/lib/virtualbox/VirtualBox &&
|
---|
55 | test -x /usr/lib/virtualbox/VirtualBox; then
|
---|
56 | INSTALL_DIR=/usr/lib/virtualbox
|
---|
57 | elif test -f "${MY_DIR}/VirtualBox" && test -x "${MY_DIR}/VirtualBox"; then
|
---|
58 | INSTALL_DIR="${MY_DIR}"
|
---|
59 | else
|
---|
60 | echo "Could not find VirtualBox installation. Please reinstall."
|
---|
61 | exit 1
|
---|
62 | fi
|
---|
63 |
|
---|
64 | # Note: This script must not fail if the module was not successfully installed
|
---|
65 | # because the user might not want to run a VM but only change VM params!
|
---|
66 |
|
---|
67 | if [ "$1" = "shutdown" ]; then
|
---|
68 | SHUTDOWN="true"
|
---|
69 | elif ! lsmod|grep -q vboxdrv; then
|
---|
70 | cat << EOF
|
---|
71 | WARNING: The vboxdrv kernel module is not loaded. Either there is no module
|
---|
72 | available for the current kernel (`uname -r`) or it failed to
|
---|
73 | load. Please recompile the kernel module and install it by
|
---|
74 |
|
---|
75 | sudo /sbin/vboxconfig
|
---|
76 |
|
---|
77 | You will not be able to start VMs until this problem is fixed.
|
---|
78 | EOF
|
---|
79 | elif [ ! -c /dev/vboxdrv ]; then
|
---|
80 | cat << EOF
|
---|
81 | WARNING: The character device /dev/vboxdrv does not exist. Try
|
---|
82 |
|
---|
83 | sudo /sbin/vboxconfig
|
---|
84 |
|
---|
85 | and if that is not successful, try to re-install the package.
|
---|
86 |
|
---|
87 | You will not be able to start VMs until this problem is fixed.
|
---|
88 | EOF
|
---|
89 | fi
|
---|
90 |
|
---|
91 | if [ -f /etc/vbox/module_not_compiled ]; then
|
---|
92 | cat << EOF
|
---|
93 | WARNING: The compilation of the vboxdrv.ko kernel module failed during the
|
---|
94 | installation for some reason. Starting a VM will not be possible.
|
---|
95 | Please consult the User Manual for build instructions.
|
---|
96 | EOF
|
---|
97 | fi
|
---|
98 |
|
---|
99 | # Get effective user name to use it in order to compose XPCOM IPC socket path.
|
---|
100 | VBOX_EFFECTIVE_USER="$(whoami)"
|
---|
101 | if [ -z "$VBOX_EFFECTIVE_USER" ]; then
|
---|
102 | cat << EOF
|
---|
103 | WARNING: Unable to detect effective user name. VirtualBox might run incorrectly.
|
---|
104 | EOF
|
---|
105 | fi
|
---|
106 |
|
---|
107 | # Variables LOGNAME and USER are used by XPCOM code in order to
|
---|
108 | # compose IPC socket path. If they set to something which is different
|
---|
109 | # from the effective user name, it might result in misbehavior.
|
---|
110 | # Setting VBOX_IPC_SOCKETID will tell XPCOM code which path it should use explicitly.
|
---|
111 | [ -n "$LOGNAME" ] && [ "$LOGNAME" = "$VBOX_EFFECTIVE_USER" ] || vbox_override_env="1"
|
---|
112 | [ -n "$USER" ] && [ "$USER" = "$VBOX_EFFECTIVE_USER" ] || vbox_override_env="1"
|
---|
113 |
|
---|
114 | if [ -n "$vbox_override_env" ]; then
|
---|
115 | cat << EOF
|
---|
116 | WARNING: Environment variable LOGNAME or USER does not correspond to effective user id.
|
---|
117 | EOF
|
---|
118 | export VBOX_IPC_SOCKETID="$VBOX_EFFECTIVE_USER"
|
---|
119 | fi
|
---|
120 |
|
---|
121 | SERVER_PID=`ps -U "$VBOX_EFFECTIVE_USER" | grep VBoxSVC | awk '{ print $1 }'`
|
---|
122 | if [ -z "$SERVER_PID" ]; then
|
---|
123 | # Server not running yet/anymore, cleanup socket path.
|
---|
124 | # See IPC_GetDefaultSocketPath()!
|
---|
125 | rm -rf "/tmp/.vbox-$VBOX_EFFECTIVE_USER-ipc" > /dev/null 2>&1
|
---|
126 | fi
|
---|
127 |
|
---|
128 | if [ "$SHUTDOWN" = "true" ]; then
|
---|
129 | if [ -n "$SERVER_PID" ]; then
|
---|
130 | kill -TERM $SERVER_PID
|
---|
131 | sleep 2
|
---|
132 | fi
|
---|
133 | exit 0
|
---|
134 | fi
|
---|
135 |
|
---|
136 | APP=`basename $0`
|
---|
137 | case "$APP" in
|
---|
138 | VirtualBox|virtualbox)
|
---|
139 | exec "$INSTALL_DIR/VirtualBox" "$@"
|
---|
140 | ;;
|
---|
141 | VirtualBoxVM|virtualboxvm)
|
---|
142 | exec "$INSTALL_DIR/VirtualBoxVM" "$@"
|
---|
143 | ;;
|
---|
144 | VBoxManage|vboxmanage)
|
---|
145 | exec "$INSTALL_DIR/VBoxManage" "$@"
|
---|
146 | ;;
|
---|
147 | VBoxSDL|vboxsdl)
|
---|
148 | exec "$INSTALL_DIR/VBoxSDL" "$@"
|
---|
149 | ;;
|
---|
150 | VBoxVRDP|VBoxHeadless|vboxheadless)
|
---|
151 | exec "$INSTALL_DIR/VBoxHeadless" "$@"
|
---|
152 | ;;
|
---|
153 | VBoxAutostart|vboxautostart)
|
---|
154 | exec "$INSTALL_DIR/VBoxAutostart" "$@"
|
---|
155 | ;;
|
---|
156 | VBoxBalloonCtrl|vboxballoonctrl)
|
---|
157 | exec "$INSTALL_DIR/VBoxBalloonCtrl" "$@"
|
---|
158 | ;;
|
---|
159 | VBoxBugReport|vboxbugreport)
|
---|
160 | exec "$INSTALL_DIR/VBoxBugReport" "$@"
|
---|
161 | ;;
|
---|
162 | VBoxDTrace|vboxdtrace)
|
---|
163 | exec "$INSTALL_DIR/VBoxDTrace" "$@"
|
---|
164 | ;;
|
---|
165 | VBoxAudioTest|vboxaudiotest|vkat)
|
---|
166 | exec "$INSTALL_DIR/VBoxAudioTest" "$@"
|
---|
167 | ;;
|
---|
168 | vboxwebsrv)
|
---|
169 | exec "$INSTALL_DIR/vboxwebsrv" "$@"
|
---|
170 | ;;
|
---|
171 | *)
|
---|
172 | echo "Unknown application - $APP"
|
---|
173 | exit 1
|
---|
174 | ;;
|
---|
175 | esac
|
---|
176 | exit 0
|
---|