VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

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