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