VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/installer/vboxadd.sh@ 27343

Last change on this file since 27343 was 27343, checked in by vboxsync, 15 years ago

Additions/linux/installer: support the Mandriva speedboot runlevel

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