1 | #!/bin/sh
|
---|
2 |
|
---|
3 | #
|
---|
4 | # Copyright (C) 2007-2010 Oracle Corporation
|
---|
5 | #
|
---|
6 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
7 | # available from http://www.virtualbox.org. This file is free software;
|
---|
8 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
9 | # General Public License (GPL) as published by the Free Software
|
---|
10 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
11 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
12 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
13 | #
|
---|
14 |
|
---|
15 | . /etc/rc.common
|
---|
16 |
|
---|
17 |
|
---|
18 | StartService()
|
---|
19 | {
|
---|
20 | VBOX_RC=0
|
---|
21 | VBOXDRV="VBoxDrv"
|
---|
22 | VBOXUSB="VBoxUSB"
|
---|
23 |
|
---|
24 | #
|
---|
25 | # Switch the binaries to the right architecture.
|
---|
26 | #
|
---|
27 | VBOX_ARCH=`uname -m`
|
---|
28 | if test "$VBOX_ARCH" = "x86_64"; then
|
---|
29 | VBOX_ARCH="amd64"
|
---|
30 | else
|
---|
31 | VBOX_ARCH="x86"
|
---|
32 | fi
|
---|
33 | for VBOX_TRG in `ls /Applications/VirtualBox.app/Contents/MacOS/*-${VBOX_ARCH}`;
|
---|
34 | do
|
---|
35 | VBOX_LINKNAME=`echo "$VBOX_TRG" | sed -e 's|-'"${VBOX_ARCH}"'$||' `
|
---|
36 | if test "$VBOX_LINKNAME" != "$VBOX_TRG"; then
|
---|
37 | rm -f "$VBOX_LINKNAME"
|
---|
38 | if ! ln -vh "$VBOX_TRG" "$VBOX_LINKNAME"; then
|
---|
39 | ConsoleMessage "Error: ln -vh $VBOX_TRG $VBOX_LINKNAME failed"
|
---|
40 | VBOX_RC=1
|
---|
41 | fi
|
---|
42 | else
|
---|
43 | ConsoleMessage "Error: Script error VBOX_TRG=$VBOX_TRG"
|
---|
44 | VBOX_RC=1
|
---|
45 | fi
|
---|
46 | done
|
---|
47 |
|
---|
48 | #
|
---|
49 | # Check that all the directories exist first.
|
---|
50 | #
|
---|
51 | if [ ! -d /Library/Extensions/${VBOXDRV}.kext ]; then
|
---|
52 | ConsoleMessage "Error: /Library/Extensions/${VBOXDRV}.kext is missing"
|
---|
53 | VBOX_RC=1
|
---|
54 | fi
|
---|
55 | if [ ! -d /Library/Extensions/${VBOXUSB}.kext ]; then
|
---|
56 | ConsoleMessage "Error: /Library/Extensions/${VBOXUSB}.kext is missing"
|
---|
57 | VBOX_RC=1
|
---|
58 | fi
|
---|
59 | if [ ! -d /Library/Extensions/VBoxNetFlt.kext ]; then
|
---|
60 | ConsoleMessage "Error: /Library/Extensions/VBoxNetFlt.kext is missing"
|
---|
61 | VBOX_RC=1
|
---|
62 | fi
|
---|
63 | if [ ! -d /Library/Extensions/VBoxNetAdp.kext ]; then
|
---|
64 | ConsoleMessage "Error: /Library/Extensions/VBoxNetAdp.kext is missing"
|
---|
65 | VBOX_RC=1
|
---|
66 | fi
|
---|
67 |
|
---|
68 | #
|
---|
69 | # Check that no drivers are currently running.
|
---|
70 | # (Try stop the service if this is the case.)
|
---|
71 | #
|
---|
72 | if [ $VBOX_RC -eq 0 ]; then
|
---|
73 | if kextstat -lb org.virtualbox.kext.VBoxDrv 2>&1 | grep -q org.virtualbox.kext.VBoxDrv; then
|
---|
74 | ConsoleMessage -v "Error: ${VBOXDRV}.kext is already loaded"
|
---|
75 | VBOX_RC=1
|
---|
76 | fi
|
---|
77 | if kextstat -lb org.virtualbox.kext.VBoxUSB 2>&1 | grep -q org.virtualbox.kext.VBoxUSB; then
|
---|
78 | ConsoleMessage -v "Error: ${VBOXUSB}.kext is already loaded"
|
---|
79 | VBOX_RC=1
|
---|
80 | fi
|
---|
81 | if kextstat -lb org.virtualbox.kext.VBoxNetFlt 2>&1 | grep -q org.virtualbox.kext.VBoxNetFlt; then
|
---|
82 | ConsoleMessage -v "Error: VBoxNetFlt.kext is already loaded"
|
---|
83 | VBOX_RC=1
|
---|
84 | fi
|
---|
85 | if kextstat -lb org.virtualbox.kext.VBoxNetAdp 2>&1 | grep -q org.virtualbox.kext.VBoxNetAdp; then
|
---|
86 | ConsoleMessage -v "Error: VBoxNetAdp.kext is already loaded"
|
---|
87 | VBOX_RC=1
|
---|
88 | fi
|
---|
89 | fi
|
---|
90 |
|
---|
91 | #
|
---|
92 | # Load the drivers.
|
---|
93 | #
|
---|
94 | if [ $VBOX_RC -eq 0 ]; then
|
---|
95 | ConsoleMessage "Loading ${VBOXDRV}.kext"
|
---|
96 | if ! kextload /Library/Extensions/${VBOXDRV}.kext; then
|
---|
97 | ConsoleMessage "Error: Failed to load /Library/Extensions/${VBOXDRV}.kext"
|
---|
98 | VBOX_RC=1
|
---|
99 | fi
|
---|
100 |
|
---|
101 | ConsoleMessage "Loading ${VBOXUSB}.kext"
|
---|
102 | if ! kextload -d /Library/Extensions/${VBOXDRV}.kext /Library/Extensions/${VBOXUSB}.kext; then
|
---|
103 | ConsoleMessage "Error: Failed to load /Library/Extensions/${VBOXUSB}.kext"
|
---|
104 | VBOX_RC=1
|
---|
105 | fi
|
---|
106 |
|
---|
107 | ConsoleMessage "Loading VBoxNetFlt.kext"
|
---|
108 | if ! kextload -d /Library/Extensions/${VBOXDRV}.kext /Library/Extensions/VBoxNetFlt.kext; then
|
---|
109 | ConsoleMessage "Error: Failed to load /Library/Extensions/VBoxNetFlt.kext"
|
---|
110 | VBOX_RC=1
|
---|
111 | fi
|
---|
112 |
|
---|
113 | ConsoleMessage "Loading VBoxNetAdp.kext"
|
---|
114 | if ! kextload -d /Library/Extensions/${VBOXDRV}.kext /Library/Extensions/VBoxNetAdp.kext; then
|
---|
115 | ConsoleMessage "Error: Failed to load /Library/Extensions/VBoxNetAdp.kext"
|
---|
116 | VBOX_RC=1
|
---|
117 | fi
|
---|
118 |
|
---|
119 | if [ $VBOX_RC -ne 0 ]; then
|
---|
120 | # unload the drivers (ignoring failures)
|
---|
121 | kextunload -b org.virtualbox.kext.VBoxNetAdp
|
---|
122 | kextunload -b org.virtualbox.kext.VBoxNetFlt
|
---|
123 | kextunload -b org.virtualbox.kext.VBoxUSB
|
---|
124 | kextunload -b org.virtualbox.kext.VBoxDrv
|
---|
125 | fi
|
---|
126 | fi
|
---|
127 |
|
---|
128 | #
|
---|
129 | # Set the error on failure.
|
---|
130 | #
|
---|
131 | if [ "$VBOX_RC" -ne "0" ]; then
|
---|
132 | ConsoleMessage -f VirtualBox
|
---|
133 | exit $VBOX_RC
|
---|
134 | fi
|
---|
135 | }
|
---|
136 |
|
---|
137 |
|
---|
138 | StopService()
|
---|
139 | {
|
---|
140 | VBOX_RC=0
|
---|
141 | VBOXDRV="VBoxDrv"
|
---|
142 | VBOXUSB="VBoxUSB"
|
---|
143 |
|
---|
144 | if kextstat -lb org.virtualbox.kext.VBoxUSB 2>&1 | grep -q org.virtualbox.kext.VBoxUSB; then
|
---|
145 | ConsoleMessage "Unloading ${VBOXUSB}.kext"
|
---|
146 | if ! kextunload -m org.virtualbox.kext.VBoxUSB; then
|
---|
147 | ConsoleMessage -v "Error: Failed to unload VBoxUSB.kext"
|
---|
148 | VBOX_RC=1
|
---|
149 | fi
|
---|
150 | fi
|
---|
151 |
|
---|
152 | if kextstat -lb org.virtualbox.kext.VBoxNetFlt 2>&1 | grep -q org.virtualbox.kext.VBoxNetFlt; then
|
---|
153 | ConsoleMessage "Unloading VBoxNetFlt.kext"
|
---|
154 | if ! kextunload -m org.virtualbox.kext.VBoxNetFlt; then
|
---|
155 | ConsoleMessage -v "Error: Failed to unload VBoxNetFlt.kext"
|
---|
156 | VBOX_RC=1
|
---|
157 | fi
|
---|
158 | fi
|
---|
159 |
|
---|
160 | if kextstat -lb org.virtualbox.kext.VBoxNetAdp 2>&1 | grep -q org.virtualbox.kext.VBoxNetAdp; then
|
---|
161 | ConsoleMessage "Unloading VBoxNetAdp.kext"
|
---|
162 | if ! kextunload -m org.virtualbox.kext.VBoxNetAdp; then
|
---|
163 | ConsoleMessage -v "Error: Failed to unload VBoxNetAdp.kext"
|
---|
164 | VBOX_RC=1
|
---|
165 | fi
|
---|
166 | fi
|
---|
167 |
|
---|
168 | # This must come last because of dependencies.
|
---|
169 | if kextstat -lb org.virtualbox.kext.VBoxDrv 2>&1 | grep -q org.virtualbox.kext.VBoxDrv; then
|
---|
170 | ConsoleMessage "Unloading ${VBOXDRV}.kext"
|
---|
171 | if ! kextunload -m org.virtualbox.kext.VBoxDrv; then
|
---|
172 | ConsoleMessage -v "Error: Failed to unload VBoxDrv.kext"
|
---|
173 | VBOX_RC=1
|
---|
174 | fi
|
---|
175 | fi
|
---|
176 |
|
---|
177 | # Set the error on failure.
|
---|
178 | if [ "$VBOX_RC" -ne "0" ]; then
|
---|
179 | ConsoleMessage -f VirtualBox
|
---|
180 | exit $VBOX_RC
|
---|
181 | fi
|
---|
182 | }
|
---|
183 |
|
---|
184 |
|
---|
185 | RestartService()
|
---|
186 | {
|
---|
187 | StopService
|
---|
188 | StartService
|
---|
189 | }
|
---|
190 |
|
---|
191 |
|
---|
192 | RunService "$1"
|
---|
193 |
|
---|