1 | #! /bin/sh
|
---|
2 | # Sun VirtualBox
|
---|
3 | # Linux Additions kernel module init script ($Revision: 24361 $)
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (C) 2006-2009 Sun Microsystems, Inc.
|
---|
8 | #
|
---|
9 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | # available from http://www.virtualbox.org. This file is free software;
|
---|
11 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | # General Public License (GPL) as published by the Free Software
|
---|
13 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | #
|
---|
17 | # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | # Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | # additional information or have any questions.
|
---|
20 | #
|
---|
21 |
|
---|
22 |
|
---|
23 | # chkconfig: 35 30 70
|
---|
24 | # description: VirtualBox Linux Additions kernel modules
|
---|
25 | #
|
---|
26 | ### BEGIN INIT INFO
|
---|
27 | # Provides: vboxadd
|
---|
28 | # Required-Start:
|
---|
29 | # Required-Stop:
|
---|
30 | # Default-Start: 2 3 4 5
|
---|
31 | # Default-Stop: 0 1 6
|
---|
32 | # Description: VirtualBox Linux Additions kernel modules
|
---|
33 | ### END INIT INFO
|
---|
34 |
|
---|
35 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
36 | BUILDVBOXGUEST=`/bin/ls /usr/src/vboxguest*/build_in_tmp 2>/dev/null|cut -d' ' -f1`
|
---|
37 | BUILDVBOXVFS=`/bin/ls /usr/src/vboxvfs*/build_in_tmp 2>/dev/null|cut -d' ' -f1`
|
---|
38 | BUILDVBOXVIDEO=`/bin/ls /usr/src/vboxvideo*/build_in_tmp 2>/dev/null|cut -d' ' -f1`
|
---|
39 | LOG="/var/log/vboxadd-install.log"
|
---|
40 |
|
---|
41 | if [ -f /etc/arch-release ]; then
|
---|
42 | system=arch
|
---|
43 | elif [ -f /etc/redhat-release ]; then
|
---|
44 | system=redhat
|
---|
45 | elif [ -f /etc/SuSE-release ]; then
|
---|
46 | system=suse
|
---|
47 | elif [ -f /etc/gentoo-release ]; then
|
---|
48 | system=gentoo
|
---|
49 | elif [ -f /etc/lfs-release -a -d /etc/rc.d/init.d ]; then
|
---|
50 | system=lfs
|
---|
51 | else
|
---|
52 | system=other
|
---|
53 | fi
|
---|
54 |
|
---|
55 | if [ "$system" = "arch" ]; then
|
---|
56 | USECOLOR=yes
|
---|
57 | . /etc/rc.d/functions
|
---|
58 | fail_msg() {
|
---|
59 | stat_fail
|
---|
60 | }
|
---|
61 |
|
---|
62 | succ_msg() {
|
---|
63 | stat_done
|
---|
64 | }
|
---|
65 |
|
---|
66 | begin() {
|
---|
67 | stat_busy "$1"
|
---|
68 | }
|
---|
69 | fi
|
---|
70 |
|
---|
71 | if [ "$system" = "redhat" ]; then
|
---|
72 | . /etc/init.d/functions
|
---|
73 | fail_msg() {
|
---|
74 | echo_failure
|
---|
75 | echo
|
---|
76 | }
|
---|
77 | succ_msg() {
|
---|
78 | echo_success
|
---|
79 | echo
|
---|
80 | }
|
---|
81 | begin() {
|
---|
82 | echo -n "$1"
|
---|
83 | }
|
---|
84 | fi
|
---|
85 |
|
---|
86 | if [ "$system" = "suse" ]; then
|
---|
87 | . /etc/rc.status
|
---|
88 | fail_msg() {
|
---|
89 | rc_failed 1
|
---|
90 | rc_status -v
|
---|
91 | }
|
---|
92 | succ_msg() {
|
---|
93 | rc_reset
|
---|
94 | rc_status -v
|
---|
95 | }
|
---|
96 | begin() {
|
---|
97 | echo -n "$1"
|
---|
98 | }
|
---|
99 | fi
|
---|
100 |
|
---|
101 | if [ "$system" = "gentoo" ]; then
|
---|
102 | if [ -f /sbin/functions.sh ]; then
|
---|
103 | . /sbin/functions.sh
|
---|
104 | elif [ -f /etc/init.d/functions.sh ]; then
|
---|
105 | . /etc/init.d/functions.sh
|
---|
106 | fi
|
---|
107 | fail_msg() {
|
---|
108 | eend 1
|
---|
109 | }
|
---|
110 | succ_msg() {
|
---|
111 | eend $?
|
---|
112 | }
|
---|
113 | begin() {
|
---|
114 | ebegin $1
|
---|
115 | }
|
---|
116 | if [ "`which $0`" = "/sbin/rc" ]; then
|
---|
117 | shift
|
---|
118 | fi
|
---|
119 | fi
|
---|
120 |
|
---|
121 | if [ "$system" = "lfs" ]; then
|
---|
122 | . /etc/rc.d/init.d/functions
|
---|
123 | fail_msg() {
|
---|
124 | echo_failure
|
---|
125 | }
|
---|
126 | succ_msg() {
|
---|
127 | echo_ok
|
---|
128 | }
|
---|
129 | begin() {
|
---|
130 | echo $1
|
---|
131 | }
|
---|
132 | fi
|
---|
133 |
|
---|
134 | if [ "$system" = "other" ]; then
|
---|
135 | fail_msg() {
|
---|
136 | echo " ...fail!"
|
---|
137 | }
|
---|
138 | succ_msg() {
|
---|
139 | echo " ...done."
|
---|
140 | }
|
---|
141 | begin() {
|
---|
142 | echo -n $1
|
---|
143 | }
|
---|
144 | fi
|
---|
145 |
|
---|
146 | dev=/dev/vboxguest
|
---|
147 | userdev=/dev/vboxuser
|
---|
148 | owner=vboxadd
|
---|
149 | group=1
|
---|
150 |
|
---|
151 | fail()
|
---|
152 | {
|
---|
153 | if [ "$system" = "gentoo" ]; then
|
---|
154 | eerror $1
|
---|
155 | exit 1
|
---|
156 | fi
|
---|
157 | fail_msg
|
---|
158 | echo "($1)"
|
---|
159 | exit 1
|
---|
160 | }
|
---|
161 |
|
---|
162 | running_vboxguest()
|
---|
163 | {
|
---|
164 | lsmod | grep -q "vboxguest[^_-]"
|
---|
165 | }
|
---|
166 |
|
---|
167 | running_vboxvfs()
|
---|
168 | {
|
---|
169 | lsmod | grep -q "vboxvfs[^_-]"
|
---|
170 | }
|
---|
171 |
|
---|
172 | start()
|
---|
173 | {
|
---|
174 | begin "Starting VirtualBox Additions ";
|
---|
175 | running_vboxguest || {
|
---|
176 | rm -f $dev || {
|
---|
177 | fail "Cannot remove $dev"
|
---|
178 | }
|
---|
179 |
|
---|
180 | rm -f $userdev || {
|
---|
181 | fail "Cannot remove $userdev"
|
---|
182 | }
|
---|
183 |
|
---|
184 | modprobe vboxguest >/dev/null 2>&1 || {
|
---|
185 | fail "modprobe vboxguest failed"
|
---|
186 | }
|
---|
187 | sleep .5
|
---|
188 | }
|
---|
189 | if [ ! -c $dev ]; then
|
---|
190 | maj=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/devices`
|
---|
191 | if [ ! -z "$maj" ]; then
|
---|
192 | min=0
|
---|
193 | else
|
---|
194 | min=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/misc`
|
---|
195 | if [ ! -z "$min" ]; then
|
---|
196 | maj=10
|
---|
197 | fi
|
---|
198 | fi
|
---|
199 | test -z "$maj" && {
|
---|
200 | rmmod vboxguest 2>/dev/null
|
---|
201 | fail "Cannot locate the VirtualBox device"
|
---|
202 | }
|
---|
203 |
|
---|
204 | mknod -m 0664 $dev c $maj $min || {
|
---|
205 | rmmod vboxguest 2>/dev/null
|
---|
206 | fail "Cannot create device $dev with major $maj and minor $min"
|
---|
207 | }
|
---|
208 | fi
|
---|
209 | chown $owner:$group $dev 2>/dev/null || {
|
---|
210 | rm -f $dev 2>/dev/null
|
---|
211 | rm -f $userdev 2>/dev/null
|
---|
212 | rmmod vboxguest 2>/dev/null
|
---|
213 | fail "Cannot change owner $owner:$group for device $dev"
|
---|
214 | }
|
---|
215 |
|
---|
216 | if [ ! -c $userdev ]; then
|
---|
217 | maj=10
|
---|
218 | min=`sed -n 's;\([0-9]\+\) vboxuser;\1;p' /proc/misc`
|
---|
219 | if [ ! -z "$min" ]; then
|
---|
220 | mknod -m 0666 $userdev c $maj $min || {
|
---|
221 | rm -f $dev 2>/dev/null
|
---|
222 | rmmod vboxguest 2>/dev/null
|
---|
223 | fail "Cannot create device $userdev with major $maj and minor $min"
|
---|
224 | }
|
---|
225 | chown $owner:$group $userdev 2>/dev/null || {
|
---|
226 | rm -f $dev 2>/dev/null
|
---|
227 | rm -f $userdev 2>/dev/null
|
---|
228 | rmmod vboxguest 2>/dev/null
|
---|
229 | fail "Cannot change owner $owner:$group for device $userdev"
|
---|
230 | }
|
---|
231 | fi
|
---|
232 | fi
|
---|
233 |
|
---|
234 | if [ -n "$BUILDVBOXVFS" ]; then
|
---|
235 | running_vboxvfs || {
|
---|
236 | modprobe vboxvfs > /dev/null 2>&1 || {
|
---|
237 | if dmesg | grep "vboxConnect failed" > /dev/null 2>&1; then
|
---|
238 | fail_msg
|
---|
239 | echo "Unable to start shared folders support. Make sure that your VirtualBox build"
|
---|
240 | echo "supports this feature."
|
---|
241 | exit 1
|
---|
242 | fi
|
---|
243 | fail "modprobe vboxvfs failed"
|
---|
244 | }
|
---|
245 | }
|
---|
246 | fi
|
---|
247 |
|
---|
248 | # Mount all shared folders from /etc/fstab. Normally this is done by some
|
---|
249 | # other startup script but this requires the vboxdrv kernel module loaded.
|
---|
250 | mount -a -t vboxsf
|
---|
251 |
|
---|
252 | succ_msg
|
---|
253 | return 0
|
---|
254 | }
|
---|
255 |
|
---|
256 | stop()
|
---|
257 | {
|
---|
258 | begin "Stopping VirtualBox Additions ";
|
---|
259 | if ! umount -a -t vboxsf 2>/dev/null; then
|
---|
260 | fail "Cannot unmount vboxsf folders"
|
---|
261 | fi
|
---|
262 | if [ -n "$BUILDVBOXVFS" ]; then
|
---|
263 | if running_vboxvfs; then
|
---|
264 | rmmod vboxvfs 2>/dev/null || fail "Cannot unload module vboxvfs"
|
---|
265 | fi
|
---|
266 | fi
|
---|
267 | if running_vboxguest; then
|
---|
268 | rmmod vboxguest 2>/dev/null || fail "Cannot unload module vboxguest"
|
---|
269 | rm -f $userdev || fail "Cannot unlink $userdev"
|
---|
270 | rm -f $dev || fail "Cannot unlink $dev"
|
---|
271 | fi
|
---|
272 | succ_msg
|
---|
273 | return 0
|
---|
274 | }
|
---|
275 |
|
---|
276 | restart()
|
---|
277 | {
|
---|
278 | stop && start
|
---|
279 | return 0
|
---|
280 | }
|
---|
281 |
|
---|
282 | # setup_script
|
---|
283 | setup()
|
---|
284 | {
|
---|
285 | # don't stop the old modules here -- they might be in use
|
---|
286 | if find /lib/modules/`uname -r` -name "vboxvfs\.*" 2>/dev/null|grep -q vboxvfs; then
|
---|
287 | begin "Removing old VirtualBox vboxvfs kernel module"
|
---|
288 | find /lib/modules/`uname -r` -name "vboxvfs\.*" 2>/dev/null|xargs rm -f 2>/dev/null
|
---|
289 | succ_msg
|
---|
290 | fi
|
---|
291 | if find /lib/modules/`uname -r` -name "vboxguest\.*" 2>/dev/null|grep -q vboxguest; then
|
---|
292 | begin "Removing old VirtualBox vboxguest kernel module"
|
---|
293 | find /lib/modules/`uname -r` -name "vboxguest\.*" 2>/dev/null|xargs rm -f 2>/dev/null
|
---|
294 | succ_msg
|
---|
295 | fi
|
---|
296 | echo "Building VirtualBox kernel modules"
|
---|
297 | begin "Building the main VirtualBox module"
|
---|
298 | if ! $BUILDVBOXGUEST \
|
---|
299 | --save-module-symvers /tmp/vboxguest-Module.symvers \
|
---|
300 | --no-print-directory install > $LOG 2>&1; then
|
---|
301 | fail "Look at $LOG to find out what went wrong"
|
---|
302 | fi
|
---|
303 | succ_msg
|
---|
304 | if [ -n "$BUILDVBOXVFS" ]; then
|
---|
305 | begin "Building the shared folder support module"
|
---|
306 | if ! $BUILDVBOXVFS \
|
---|
307 | --use-module-symvers /tmp/vboxguest-Module.symvers \
|
---|
308 | --no-print-directory install >> $LOG 2>&1; then
|
---|
309 | fail "Look at $LOG to find out what went wrong"
|
---|
310 | fi
|
---|
311 | succ_msg
|
---|
312 | fi
|
---|
313 | if [ -n "$BUILDVBOXVIDEO" ]; then
|
---|
314 | begin "Building the OpenGL support module"
|
---|
315 | if ! $BUILDVBOXVIDEO \
|
---|
316 | --use-module-symvers /tmp/vboxguest-Module.symvers \
|
---|
317 | --no-print-directory install >> $LOG 2>&1; then
|
---|
318 | fail "Look at $LOG to find out what went wrong"
|
---|
319 | fi
|
---|
320 | succ_msg
|
---|
321 | fi
|
---|
322 | depmod
|
---|
323 |
|
---|
324 | begin "Doing non-kernel setup of the Guest Additions"
|
---|
325 | echo "Creating user for the Guest Additions." >> $LOG
|
---|
326 | # This is the LSB version of useradd and should work on recent
|
---|
327 | # distributions
|
---|
328 | useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
|
---|
329 | # And for the others, we choose a UID ourselves
|
---|
330 | useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
|
---|
331 |
|
---|
332 | # Create udev description file
|
---|
333 | if [ -d /etc/udev/rules.d ]; then
|
---|
334 | echo "Creating udev rule for the Guest Additions kernel module." >> $LOG
|
---|
335 | udev_call=""
|
---|
336 | udev_app=`which udevadm 2> /dev/null`
|
---|
337 | if [ $? -eq 0 ]; then
|
---|
338 | udev_call="${udev_app} version 2> /dev/null"
|
---|
339 | else
|
---|
340 | udev_app=`which udevinfo 2> /dev/null`
|
---|
341 | if [ $? -eq 0 ]; then
|
---|
342 | udev_call="${udev_app} -V 2> /dev/null"
|
---|
343 | fi
|
---|
344 | fi
|
---|
345 | udev_fix="="
|
---|
346 | if [ "${udev_call}" != "" ]; then
|
---|
347 | udev_out=`${udev_call}`
|
---|
348 | udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
|
---|
349 | if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
|
---|
350 | udev_fix=""
|
---|
351 | fi
|
---|
352 | fi
|
---|
353 | ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
|
---|
354 | echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
|
---|
355 | echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
|
---|
356 | fi
|
---|
357 |
|
---|
358 | # Put mount.vboxsf in the right place
|
---|
359 | ln -s /usr/lib/VBoxGuestAdditions/mount.vboxsf /sbin
|
---|
360 |
|
---|
361 | succ_msg
|
---|
362 | start
|
---|
363 | echo
|
---|
364 | echo "You should reboot your guest to make sure the new modules are actually used"
|
---|
365 | }
|
---|
366 |
|
---|
367 | # cleanup_script
|
---|
368 | cleanup()
|
---|
369 | {
|
---|
370 | # Delete old versions of VBox modules.
|
---|
371 | DKMS=`which dkms 2>/dev/null`
|
---|
372 | if [ -n "$DKMS" ]; then
|
---|
373 | info "Attempt to remove old DKMS modules..."
|
---|
374 | for mod in vboxadd vboxguest vboxvfs vboxvideo; do
|
---|
375 | $DKMS status -m $mod | while read line; do
|
---|
376 | if echo "$line" | grep -q added > /dev/null ||
|
---|
377 | echo "$line" | grep -q built > /dev/null ||
|
---|
378 | echo "$line" | grep -q installed > /dev/null; then
|
---|
379 | version=`echo "$line" | sed "s/$mod,\([^,]*\)[,:].*/\1/;t;d"`
|
---|
380 | info " removing module $mod version $version"
|
---|
381 | $DKMS remove -m $mod -v $version --all
|
---|
382 | fi
|
---|
383 | done
|
---|
384 | done
|
---|
385 | info "Done."
|
---|
386 | fi
|
---|
387 |
|
---|
388 | # Remove old installed modules
|
---|
389 | find /lib/modules -name vboxadd\* | xargs rm 2>/dev/null
|
---|
390 | find /lib/modules -name vboxguest\* | xargs rm 2>/dev/null
|
---|
391 | find /lib/modules -name vboxvfs\* | xargs rm 2>/dev/null
|
---|
392 | find /lib/modules -name vboxvideo\* | xargs rm 2>/dev/null
|
---|
393 | depmod
|
---|
394 |
|
---|
395 | # Remove other files
|
---|
396 | rm /sbin/mount.vboxsf 2>/dev/null
|
---|
397 | }
|
---|
398 |
|
---|
399 | dmnstatus()
|
---|
400 | {
|
---|
401 | if running_vboxguest; then
|
---|
402 | echo "The VirtualBox Additions are currently running."
|
---|
403 | else
|
---|
404 | echo "The VirtualBox Additions are not currently running."
|
---|
405 | fi
|
---|
406 | }
|
---|
407 |
|
---|
408 | case "$1" in
|
---|
409 | start)
|
---|
410 | start
|
---|
411 | ;;
|
---|
412 | stop)
|
---|
413 | stop
|
---|
414 | ;;
|
---|
415 | restart)
|
---|
416 | restart
|
---|
417 | ;;
|
---|
418 | setup)
|
---|
419 | setup
|
---|
420 | ;;
|
---|
421 | cleanup)
|
---|
422 | cleanup
|
---|
423 | ;;
|
---|
424 | status)
|
---|
425 | dmnstatus
|
---|
426 | ;;
|
---|
427 | *)
|
---|
428 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
429 | exit 1
|
---|
430 | esac
|
---|
431 |
|
---|
432 | exit
|
---|