VirtualBox

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

Last change on this file since 24544 was 24544, 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.3 KB
Line 
1#! /bin/sh
2# Sun VirtualBox
3# Linux Additions kernel module init script ($Revision: 24544 $)
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_vboxvfs()
169{
170 lsmod | grep -q "vboxvfs[^_-]"
171}
172
173start()
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
257stop()
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
277restart()
278{
279 stop && start
280 return 0
281}
282
283# setup_script
284setup()
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 echo
379 echo "You should reboot your guest to make sure the new modules are actually used"
380}
381
382# cleanup_script
383cleanup()
384{
385 # Delete old versions of VBox modules.
386 DKMS=`which dkms 2>/dev/null`
387 if [ -n "$DKMS" ]; then
388 echo "Attempt to remove old DKMS modules..."
389 for mod in vboxadd vboxguest vboxvfs vboxvideo; do
390 $DKMS status -m $mod | while read line; do
391 if echo "$line" | grep -q added > /dev/null ||
392 echo "$line" | grep -q built > /dev/null ||
393 echo "$line" | grep -q installed > /dev/null; then
394 version=`echo "$line" | sed "s/$mod,\([^,]*\)[,:].*/\1/;t;d"`
395 echo " removing module $mod version $version"
396 $DKMS remove -m $mod -v $version --all 1>&2
397 fi
398 done
399 done
400 echo "Done."
401 fi
402
403 # Remove old installed modules
404 find /lib/modules -name vboxadd\* | xargs rm 2>/dev/null
405 find /lib/modules -name vboxguest\* | xargs rm 2>/dev/null
406 find /lib/modules -name vboxvfs\* | xargs rm 2>/dev/null
407 find /lib/modules -name vboxvideo\* | xargs rm 2>/dev/null
408 depmod
409
410 # Remove old module sources
411 rm -rf /usr/src/vboxadd-* /usr/src/vboxguest-* /usr/src/vboxvfs-* /usr/src/vboxvideo-*
412
413 # Remove other files
414 rm /sbin/mount.vboxsf 2>/dev/null
415 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
416}
417
418dmnstatus()
419{
420 if running_vboxguest; then
421 echo "The VirtualBox Additions are currently running."
422 else
423 echo "The VirtualBox Additions are not currently running."
424 fi
425}
426
427case "$1" in
428start)
429 start
430 ;;
431stop)
432 stop
433 ;;
434restart)
435 restart
436 ;;
437setup)
438 setup
439 ;;
440cleanup)
441 cleanup
442 ;;
443status)
444 dmnstatus
445 ;;
446*)
447 echo "Usage: $0 {start|stop|restart|status}"
448 exit 1
449esac
450
451exit
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