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