VirtualBox

source: vbox/trunk/src/VBox/Installer/darwin/VBoxKEXTs/VirtualBoxStartup.sh@ 93217

Last change on this file since 93217 was 93217, checked in by vboxsync, 3 years ago

HostDrivers,Installer,Devices: Clean out the VBoxUSB driver which is completely unused since some time now, bugref:9808

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1#!/bin/sh
2# $Id: VirtualBoxStartup.sh 93217 2022-01-13 07:29:50Z vboxsync $
3## @file
4# Startup service for loading the kernel extensions and select the set of VBox
5# binaries that matches the kernel architecture.
6#
7
8#
9# Copyright (C) 2007-2022 Oracle Corporation
10#
11# This file is part of VirtualBox Open Source Edition (OSE), as
12# available from http://www.virtualbox.org. This file is free software;
13# you can redistribute it and/or modify it under the terms of the GNU
14# General Public License (GPL) as published by the Free Software
15# Foundation, in version 2 as it comes in the "COPYING" file of the
16# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18#
19
20if false; then
21 . /etc/rc.common
22else
23 # Fake the startup item functions we're using.
24
25 ConsoleMessage()
26 {
27 if [ "$1" != "-f" ]; then
28 echo "$@"
29 else
30 shift
31 echo "Fatal error: $@"
32 exit 1;
33 fi
34 }
35
36 RunService()
37 {
38 case "$1" in
39 "start")
40 StartService
41 exit $?;
42 ;;
43 "stop")
44 StopService
45 exit $?;
46 ;;
47 "restart")
48 RestartService
49 exit $?;
50 ;;
51 "launchd")
52 if RestartService; then
53 while true;
54 do
55 sleep 3600
56 done
57 fi
58 exit $?;
59 ;;
60 **)
61 echo "Error: Unknown action '$1'"
62 exit 1;
63 esac
64 }
65fi
66
67
68StartService()
69{
70 VBOX_RC=0
71 VBOXDRV="VBoxDrv"
72 MACOS_VERSION_MAJOR=$(sw_vers -productVersion | /usr/bin/sed -e 's/^\([0-9]*\).*$/\1/')
73
74 #
75 # Check that all the directories exist first.
76 #
77 if [ ! -d "/Library/Application Support/VirtualBox/${VBOXDRV}.kext" ]; then
78 ConsoleMessage "Error: /Library/Application Support/VirtualBox/${VBOXDRV}.kext is missing"
79 VBOX_RC=1
80 fi
81 if [ ! -d "/Library/Application Support/VirtualBox/VBoxNetFlt.kext" ]; then
82 ConsoleMessage "Error: /Library/Application Support/VirtualBox/VBoxNetFlt.kext is missing"
83 VBOX_RC=1
84 fi
85 if [ ! -d "/Library/Application Support/VirtualBox/VBoxNetAdp.kext" ]; then
86 ConsoleMessage "Error: /Library/Application Support/VirtualBox/VBoxNetAdp.kext is missing"
87 VBOX_RC=1
88 fi
89
90 #
91 # Check that no drivers are currently running.
92 # (Try stop the service if this is the case.)
93 #
94 if [ $VBOX_RC -eq 0 ]; then
95 if [[ ${MACOS_VERSION_MAJOR} -lt 11 ]]; then
96 if kextstat -lb org.virtualbox.kext.VBoxDrv 2>&1 | grep -q org.virtualbox.kext.VBoxDrv; then
97 ConsoleMessage "Error: ${VBOXDRV}.kext is already loaded"
98 VBOX_RC=1
99 fi
100 if kextstat -lb org.virtualbox.kext.VBoxNetFlt 2>&1 | grep -q org.virtualbox.kext.VBoxNetFlt; then
101 ConsoleMessage "Error: VBoxNetFlt.kext is already loaded"
102 VBOX_RC=1
103 fi
104 if kextstat -lb org.virtualbox.kext.VBoxNetAdp 2>&1 | grep -q org.virtualbox.kext.VBoxNetAdp; then
105 ConsoleMessage "Error: VBoxNetAdp.kext is already loaded"
106 VBOX_RC=1
107 fi
108 else
109 #
110 # Use kmutil directly on BigSur or grep will erroneously trigger because kextstat dumps the kmutil
111 # invocation to stdout...
112 #
113 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxDrv 2>&1 | grep -q org.virtualbox.kext.VBoxDrv; then
114 ConsoleMessage "Error: ${VBOXDRV}.kext is already loaded"
115 VBOX_RC=1
116 fi
117 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxNetFlt 2>&1 | grep -q org.virtualbox.kext.VBoxNetFlt; then
118 ConsoleMessage "Error: VBoxNetFlt.kext is already loaded"
119 VBOX_RC=1
120 fi
121 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxNetAdp 2>&1 | grep -q org.virtualbox.kext.VBoxNetAdp; then
122 ConsoleMessage "Error: VBoxNetAdp.kext is already loaded"
123 VBOX_RC=1
124 fi
125 fi
126 fi
127
128 #
129 # Load the drivers.
130 #
131 if [ $VBOX_RC -eq 0 ]; then
132 if [[ ${MACOS_VERSION_MAJOR} -lt 11 ]]; then
133 ConsoleMessage "Loading ${VBOXDRV}.kext"
134 if ! kextload "/Library/Application Support/VirtualBox/${VBOXDRV}.kext"; then
135 ConsoleMessage "Error: Failed to load /Library/Application Support/VirtualBox/${VBOXDRV}.kext"
136 VBOX_RC=1
137 fi
138
139 ConsoleMessage "Loading VBoxNetFlt.kext"
140 if ! kextload -d "/Library/Application Support/VirtualBox/${VBOXDRV}.kext" "/Library/Application Support/VirtualBox/VBoxNetFlt.kext"; then
141 ConsoleMessage "Error: Failed to load /Library/Application Support/VirtualBox/VBoxNetFlt.kext"
142 VBOX_RC=1
143 fi
144
145 ConsoleMessage "Loading VBoxNetAdp.kext"
146 if ! kextload -d "/Library/Application Support/VirtualBox/${VBOXDRV}.kext" "/Library/Application Support/VirtualBox/VBoxNetAdp.kext"; then
147 ConsoleMessage "Error: Failed to load /Library/Application Support/VirtualBox/VBoxNetAdp.kext"
148 VBOX_RC=1
149 fi
150 else
151 #
152 # On BigSur we can only load by bundle ID because the drivers are baked into a kext collection image
153 # and the real path is never loaded actually.
154 #
155 ConsoleMessage "Loading ${VBOXDRV}.kext"
156 if ! kmutil load -b org.virtualbox.kext.VBoxDrv; then
157 ConsoleMessage "Error: Failed to load org.virtualbox.kext.VBoxDrv"
158 VBOX_RC=1
159 fi
160
161 ConsoleMessage "Loading VBoxNetFlt.kext"
162 if ! kmutil load -b org.virtualbox.kext.VBoxNetFlt; then
163 ConsoleMessage "Error: Failed to load org.virtualbox.kext.VBoxNetFlt"
164 VBOX_RC=1
165 fi
166
167 ConsoleMessage "Loading VBoxNetAdp.kext"
168 if ! kmutil load -b org.virtualbox.kext.VBoxNetAdp; then
169 ConsoleMessage "Error: Failed to load org.virtualbox.kext.VBoxNetAdp"
170 VBOX_RC=1
171 fi
172 fi
173
174 if [ $VBOX_RC -ne 0 ]; then
175 # unload the drivers (ignoring failures)
176 kextunload -b org.virtualbox.kext.VBoxNetAdp
177 kextunload -b org.virtualbox.kext.VBoxNetFlt
178 kextunload -b org.virtualbox.kext.VBoxDrv
179 fi
180 fi
181
182 #
183 # Set the error on failure.
184 #
185 if [ "$VBOX_RC" -ne "0" ]; then
186 ConsoleMessage -f VirtualBox
187 exit $VBOX_RC
188 fi
189}
190
191
192StopService()
193{
194 VBOX_RC=0
195 VBOXDRV="VBoxDrv"
196 VBOXUSB="VBoxUSB"
197 MACOS_VERSION_MAJOR=$(sw_vers -productVersion | /usr/bin/sed -e 's/^\([0-9]*\).*$/\1/')
198
199 if [[ ${MACOS_VERSION_MAJOR} -lt 11 ]]; then
200 if kextstat -lb org.virtualbox.kext.VBoxNetFlt 2>&1 | grep -q org.virtualbox.kext.VBoxNetFlt; then
201 ConsoleMessage "Unloading VBoxNetFlt.kext"
202 if ! kextunload -m org.virtualbox.kext.VBoxNetFlt; then
203 ConsoleMessage "Error: Failed to unload VBoxNetFlt.kext"
204 VBOX_RC=1
205 fi
206 fi
207
208 if kextstat -lb org.virtualbox.kext.VBoxNetAdp 2>&1 | grep -q org.virtualbox.kext.VBoxNetAdp; then
209 ConsoleMessage "Unloading VBoxNetAdp.kext"
210 if ! kextunload -m org.virtualbox.kext.VBoxNetAdp; then
211 ConsoleMessage "Error: Failed to unload VBoxNetAdp.kext"
212 VBOX_RC=1
213 fi
214 fi
215
216 # This must come last because of dependencies.
217 if kextstat -lb org.virtualbox.kext.VBoxDrv 2>&1 | grep -q org.virtualbox.kext.VBoxDrv; then
218 ConsoleMessage "Unloading ${VBOXDRV}.kext"
219 if ! kextunload -m org.virtualbox.kext.VBoxDrv; then
220 ConsoleMessage "Error: Failed to unload VBoxDrv.kext"
221 VBOX_RC=1
222 fi
223 fi
224 else
225 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxNetFlt 2>&1 | grep -q org.virtualbox.kext.VBoxNetFlt; then
226 ConsoleMessage "Unloading VBoxNetFlt.kext"
227 if ! kmutil unload -b org.virtualbox.kext.VBoxNetFlt; then
228 ConsoleMessage "Error: Failed to unload VBoxNetFlt.kext"
229 VBOX_RC=1
230 fi
231 fi
232
233 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxNetAdp 2>&1 | grep -q org.virtualbox.kext.VBoxNetAdp; then
234 ConsoleMessage "Unloading VBoxNetAdp.kext"
235 if ! kmutil unload -b org.virtualbox.kext.VBoxNetAdp; then
236 ConsoleMessage "Error: Failed to unload VBoxNetAdp.kext"
237 VBOX_RC=1
238 fi
239 fi
240
241 # This must come last because of dependencies.
242 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxDrv 2>&1 | grep -q org.virtualbox.kext.VBoxDrv; then
243 ConsoleMessage "Unloading ${VBOXDRV}.kext"
244 if ! kmutil unload -b org.virtualbox.kext.VBoxDrv; then
245 ConsoleMessage "Error: Failed to unload VBoxDrv.kext"
246 VBOX_RC=1
247 fi
248 fi
249 fi
250
251 # Set the error on failure.
252 if [ "$VBOX_RC" -ne "0" ]; then
253 ConsoleMessage -f VirtualBox
254 exit $VBOX_RC
255 fi
256}
257
258
259RestartService()
260{
261 StopService
262 StartService
263}
264
265
266RunService "$1"
267
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette