VirtualBox

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

Last change on this file since 49824 was 49540, checked in by vboxsync, 11 years ago

Installer/darwin: 'ln -vh' => '/bin/ln -vh' -- see public ticket 12275

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
1#!/bin/sh
2# $Id: VirtualBoxStartup.sh 49540 2013-11-18 20:23:28Z 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-2013 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 VBOXUSB="VBoxUSB"
73
74 #
75 # Switch the binaries to the right architecture.
76 #
77 VBOX_ARCH=`uname -m`
78 if test "$VBOX_ARCH" = "x86_64"; then
79 VBOX_ARCH="amd64"
80 else
81 VBOX_ARCH="x86"
82 fi
83 for VBOX_TRG in `ls /Applications/VirtualBox.app/Contents/MacOS/*-${VBOX_ARCH}`;
84 do
85 VBOX_LINKNAME=`echo "$VBOX_TRG" | sed -e 's|-'"${VBOX_ARCH}"'$||' `
86 if test "$VBOX_LINKNAME" != "$VBOX_TRG"; then
87 rm -f "$VBOX_LINKNAME"
88 if ! /bin/ln -vh "$VBOX_TRG" "$VBOX_LINKNAME"; then
89 ConsoleMessage "Error: /bin/ln -vh $VBOX_TRG $VBOX_LINKNAME failed"
90 VBOX_RC=1
91 fi
92 else
93 ConsoleMessage "Error: Script error VBOX_TRG=$VBOX_TRG"
94 VBOX_RC=1
95 fi
96 done
97
98 #
99 # Check that all the directories exist first.
100 #
101 if [ ! -d "/Library/Application Support/VirtualBox/${VBOXDRV}.kext" ]; then
102 ConsoleMessage "Error: /Library/Application Support/VirtualBox/${VBOXDRV}.kext is missing"
103 VBOX_RC=1
104 fi
105 if [ ! -d "/Library/Application Support/VirtualBox/${VBOXUSB}.kext" ]; then
106 ConsoleMessage "Error: /Library/Application Support/VirtualBox/${VBOXUSB}.kext is missing"
107 VBOX_RC=1
108 fi
109 if [ ! -d "/Library/Application Support/VirtualBox/VBoxNetFlt.kext" ]; then
110 ConsoleMessage "Error: /Library/Application Support/VirtualBox/VBoxNetFlt.kext is missing"
111 VBOX_RC=1
112 fi
113 if [ ! -d "/Library/Application Support/VirtualBox/VBoxNetAdp.kext" ]; then
114 ConsoleMessage "Error: /Library/Application Support/VirtualBox/VBoxNetAdp.kext is missing"
115 VBOX_RC=1
116 fi
117
118 #
119 # Check that no drivers are currently running.
120 # (Try stop the service if this is the case.)
121 #
122 if [ $VBOX_RC -eq 0 ]; then
123 if kextstat -lb org.virtualbox.kext.VBoxDrv 2>&1 | grep -q org.virtualbox.kext.VBoxDrv; then
124 ConsoleMessage "Error: ${VBOXDRV}.kext is already loaded"
125 VBOX_RC=1
126 fi
127 if kextstat -lb org.virtualbox.kext.VBoxUSB 2>&1 | grep -q org.virtualbox.kext.VBoxUSB; then
128 ConsoleMessage "Error: ${VBOXUSB}.kext is already loaded"
129 VBOX_RC=1
130 fi
131 if kextstat -lb org.virtualbox.kext.VBoxNetFlt 2>&1 | grep -q org.virtualbox.kext.VBoxNetFlt; then
132 ConsoleMessage "Error: VBoxNetFlt.kext is already loaded"
133 VBOX_RC=1
134 fi
135 if kextstat -lb org.virtualbox.kext.VBoxNetAdp 2>&1 | grep -q org.virtualbox.kext.VBoxNetAdp; then
136 ConsoleMessage "Error: VBoxNetAdp.kext is already loaded"
137 VBOX_RC=1
138 fi
139 fi
140
141 #
142 # Load the drivers.
143 #
144 if [ $VBOX_RC -eq 0 ]; then
145 ConsoleMessage "Loading ${VBOXDRV}.kext"
146 if ! kextload "/Library/Application Support/VirtualBox/${VBOXDRV}.kext"; then
147 ConsoleMessage "Error: Failed to load /Library/Application Support/VirtualBox/${VBOXDRV}.kext"
148 VBOX_RC=1
149 fi
150
151 ConsoleMessage "Loading ${VBOXUSB}.kext"
152 if ! kextload -d "/Library/Application Support/VirtualBox/${VBOXDRV}.kext" "/Library/Application Support/VirtualBox/${VBOXUSB}.kext"; then
153 ConsoleMessage "Error: Failed to load /Library/Application Support/VirtualBox/${VBOXUSB}.kext"
154 VBOX_RC=1
155 fi
156
157 ConsoleMessage "Loading VBoxNetFlt.kext"
158 if ! kextload -d "/Library/Application Support/VirtualBox/${VBOXDRV}.kext" "/Library/Application Support/VirtualBox/VBoxNetFlt.kext"; then
159 ConsoleMessage "Error: Failed to load /Library/Application Support/VirtualBox/VBoxNetFlt.kext"
160 VBOX_RC=1
161 fi
162
163 ConsoleMessage "Loading VBoxNetAdp.kext"
164 if ! kextload -d "/Library/Application Support/VirtualBox/${VBOXDRV}.kext" "/Library/Application Support/VirtualBox/VBoxNetAdp.kext"; then
165 ConsoleMessage "Error: Failed to load /Library/Application Support/VirtualBox/VBoxNetAdp.kext"
166 VBOX_RC=1
167 fi
168
169 if [ $VBOX_RC -ne 0 ]; then
170 # unload the drivers (ignoring failures)
171 kextunload -b org.virtualbox.kext.VBoxNetAdp
172 kextunload -b org.virtualbox.kext.VBoxNetFlt
173 kextunload -b org.virtualbox.kext.VBoxUSB
174 kextunload -b org.virtualbox.kext.VBoxDrv
175 fi
176 fi
177
178 #
179 # Set the error on failure.
180 #
181 if [ "$VBOX_RC" -ne "0" ]; then
182 ConsoleMessage -f VirtualBox
183 exit $VBOX_RC
184 fi
185}
186
187
188StopService()
189{
190 VBOX_RC=0
191 VBOXDRV="VBoxDrv"
192 VBOXUSB="VBoxUSB"
193
194 if kextstat -lb org.virtualbox.kext.VBoxUSB 2>&1 | grep -q org.virtualbox.kext.VBoxUSB; then
195 ConsoleMessage "Unloading ${VBOXUSB}.kext"
196 if ! kextunload -m org.virtualbox.kext.VBoxUSB; then
197 ConsoleMessage "Error: Failed to unload VBoxUSB.kext"
198 VBOX_RC=1
199 fi
200 fi
201
202 if kextstat -lb org.virtualbox.kext.VBoxNetFlt 2>&1 | grep -q org.virtualbox.kext.VBoxNetFlt; then
203 ConsoleMessage "Unloading VBoxNetFlt.kext"
204 if ! kextunload -m org.virtualbox.kext.VBoxNetFlt; then
205 ConsoleMessage "Error: Failed to unload VBoxNetFlt.kext"
206 VBOX_RC=1
207 fi
208 fi
209
210 if kextstat -lb org.virtualbox.kext.VBoxNetAdp 2>&1 | grep -q org.virtualbox.kext.VBoxNetAdp; then
211 ConsoleMessage "Unloading VBoxNetAdp.kext"
212 if ! kextunload -m org.virtualbox.kext.VBoxNetAdp; then
213 ConsoleMessage "Error: Failed to unload VBoxNetAdp.kext"
214 VBOX_RC=1
215 fi
216 fi
217
218 # This must come last because of dependencies.
219 if kextstat -lb org.virtualbox.kext.VBoxDrv 2>&1 | grep -q org.virtualbox.kext.VBoxDrv; then
220 ConsoleMessage "Unloading ${VBOXDRV}.kext"
221 if ! kextunload -m org.virtualbox.kext.VBoxDrv; then
222 ConsoleMessage "Error: Failed to unload VBoxDrv.kext"
223 VBOX_RC=1
224 fi
225 fi
226
227 # Set the error on failure.
228 if [ "$VBOX_RC" -ne "0" ]; then
229 ConsoleMessage -f VirtualBox
230 exit $VBOX_RC
231 fi
232}
233
234
235RestartService()
236{
237 StopService
238 StartService
239}
240
241
242RunService "$1"
243
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