VirtualBox

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

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

Additions/linux/installer: message fixes

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette