VirtualBox

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

Last change on this file since 17409 was 17409, checked in by vboxsync, 16 years ago

Additions/Linux/installer: correct the error message if shared folders are not available

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1#! /bin/sh
2# Sun xVM VirtualBox
3# Linux Additions kernel module init script
4#
5# Copyright (C) 2006-2007 Sun Microsystems, Inc.
6#
7# This file is part of VirtualBox Open Source Edition (OSE), as
8# available from http://www.virtualbox.org. This file is free software;
9# you can redistribute it and/or modify it under the terms of the GNU
10# General Public License (GPL) as published by the Free Software
11# Foundation, in version 2 as it comes in the "COPYING" file of the
12# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
14#
15# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
16# Clara, CA 95054 USA or visit http://www.sun.com if you need
17# additional information or have any questions.
18#
19
20
21# chkconfig: 35 30 60
22# description: VirtualBox Linux Additions kernel modules
23#
24### BEGIN INIT INFO
25# Provides: vboxadd
26# Required-Start:
27# Required-Stop:
28# Default-Start: 2 3 4 5
29# Default-Stop: 0 1 6
30# Description: VirtualBox Linux Additions kernel modules
31### END INIT INFO
32
33PATH=$PATH:/bin:/sbin:/usr/sbin
34BUILDVBOXADD=`/bin/ls /usr/src/vboxadd*/build_in_tmp 2>/dev/null|cut -d' ' -f1`
35BUILDVBOXVFS=`/bin/ls /usr/src/vboxvfs*/build_in_tmp 2>/dev/null|cut -d' ' -f1`
36BUILDVBOXVIDEO=`/bin/ls /usr/src/vboxvideo*/build_in_tmp 2>/dev/null|cut -d' ' -f1`
37LOG="/var/log/vboxadd-install.log"
38
39if [ -f /etc/arch-release ]; then
40 system=arch
41elif [ -f /etc/redhat-release ]; then
42 system=redhat
43elif [ -f /etc/SuSE-release ]; then
44 system=suse
45elif [ -f /etc/gentoo-release ]; then
46 system=gentoo
47elif [ -f /etc/lfs-release -a -d /etc/rc.d/init.d ]; then
48 system=lfs
49else
50 system=other
51fi
52
53if [ "$system" = "arch" ]; then
54 USECOLOR=yes
55 . /etc/rc.d/functions
56 fail_msg() {
57 stat_fail
58 }
59
60 succ_msg() {
61 stat_done
62 }
63
64 begin() {
65 stat_busy "$1"
66 }
67fi
68
69if [ "$system" = "redhat" ]; then
70 . /etc/init.d/functions
71 fail_msg() {
72 echo_failure
73 echo
74 }
75 succ_msg() {
76 echo_success
77 echo
78 }
79 begin() {
80 echo -n "$1"
81 }
82fi
83
84if [ "$system" = "suse" ]; then
85 . /etc/rc.status
86 fail_msg() {
87 rc_failed 1
88 rc_status -v
89 }
90 succ_msg() {
91 rc_reset
92 rc_status -v
93 }
94 begin() {
95 echo -n "$1"
96 }
97fi
98
99if [ "$system" = "gentoo" ]; then
100 if [ -f /sbin/functions.sh ]; then
101 . /sbin/functions.sh
102 elif [ -f /etc/init.d/functions.sh ]; then
103 . /etc/init.d/functions.sh
104 fi
105 fail_msg() {
106 eend 1
107 }
108 succ_msg() {
109 eend $?
110 }
111 begin() {
112 ebegin $1
113 }
114 if [ "`which $0`" = "/sbin/rc" ]; then
115 shift
116 fi
117fi
118
119if [ "$system" = "lfs" ]; then
120 . /etc/rc.d/init.d/functions
121 fail_msg() {
122 echo_failure
123 }
124 succ_msg() {
125 echo_ok
126 }
127 begin() {
128 echo $1
129 }
130fi
131
132if [ "$system" = "other" ]; then
133 fail_msg() {
134 echo " ...fail!"
135 }
136 succ_msg() {
137 echo " ...done."
138 }
139 begin() {
140 echo -n $1
141 }
142fi
143
144dev=/dev/vboxadd
145owner=vboxadd
146group=1
147
148fail()
149{
150 if [ "$system" = "gentoo" ]; then
151 eerror $1
152 exit 1
153 fi
154 fail_msg
155 echo "($1)"
156 exit 1
157}
158
159running_vboxadd()
160{
161 lsmod | grep -q "vboxadd[^_-]"
162}
163
164running_vboxvfs()
165{
166 lsmod | grep -q "vboxvfs[^_-]"
167}
168
169start()
170{
171 begin "Starting VirtualBox Additions ";
172 running_vboxadd || {
173 rm -f $dev || {
174 fail "Cannot remove $dev"
175 }
176
177 modprobe vboxadd >/dev/null 2>&1 || {
178 fail "modprobe vboxadd failed"
179 }
180 sleep .5
181 }
182 if [ ! -c $dev ]; then
183 maj=`sed -n 's;\([0-9]\+\) vboxadd;\1;p' /proc/devices`
184 if [ ! -z "$maj" ]; then
185 min=0
186 else
187 min=`sed -n 's;\([0-9]\+\) vboxadd;\1;p' /proc/misc`
188 if [ ! -z "$min" ]; then
189 maj=10
190 fi
191 fi
192 test -z "$maj" && {
193 rmmod vboxadd 2>/dev/null
194 fail "Cannot locate the VirtualBox device"
195 }
196
197 mknod -m 0664 $dev c $maj $min || {
198 rmmod vboxadd 2>/dev/null
199 fail "Cannot create device $dev with major $maj and minor $min"
200 }
201 fi
202 chown $owner:$group $dev 2>/dev/null || {
203 rmmod vboxadd 2>/dev/null
204 fail "Cannot change owner $owner:$group for device $dev"
205 }
206
207 if [ -n "$BUILDVBOXVFS" ]; then
208 running_vboxvfs || {
209 modprobe vboxvfs > /dev/null 2>&1 || {
210 if dmesg | grep "vboxConnect failed" > /dev/null 2>&1; then
211 fail_msg
212 echo "Unable to start shared folders support. Make sure that your VirtualBox build"
213 echo "supports this feature."
214 exit 1
215 fi
216 fail "modprobe vboxvfs failed"
217 }
218 }
219 fi
220
221 # Mount all shared folders from /etc/fstab. Normally this is done by some
222 # other startup script but this requires the vboxdrv kernel module loaded.
223 mount -a -t vboxsf
224
225 succ_msg
226 return 0
227}
228
229stop()
230{
231 begin "Stopping VirtualBox Additions ";
232 if !umount -a -t vboxsf 2>/dev/null; then
233 fail "Cannot unmount vboxsf folders"
234 fi
235 if [ -n "$BUILDVBOXVFS" ]; then
236 if running_vboxvfs; then
237 rmmod vboxvfs 2>/dev/null || fail "Cannot unload module vboxvfs"
238 fi
239 fi
240 if running_vboxadd; then
241 rmmod vboxadd 2>/dev/null || fail "Cannot unload module vboxadd"
242 rm -f $dev || fail "Cannot unlink $dev"
243 fi
244 succ_msg
245 return 0
246}
247
248restart()
249{
250 stop && start
251 return 0
252}
253
254setup()
255{
256 # don't stop the old modules here -- they might be in use
257 if find /lib/modules/`uname -r` -name "vboxvfs\.*" 2>/dev/null|grep -q vboxvfs; then
258 begin "Removing old VirtualBox vboxvfs kernel module"
259 find /lib/modules/`uname -r` -name "vboxvfs\.*" 2>/dev/null|xargs rm -f 2>/dev/null
260 succ_msg
261 fi
262 if find /lib/modules/`uname -r` -name "vboxadd\.*" 2>/dev/null|grep -q vboxadd; then
263 begin "Removing old VirtualBox vboxadd kernel module"
264 find /lib/modules/`uname -r` -name "vboxadd\.*" 2>/dev/null|xargs rm -f 2>/dev/null
265 succ_msg
266 fi
267 begin "Recompiling VirtualBox kernel modules"
268 if ! $BUILDVBOXADD \
269 --save-module-symvers /tmp/vboxadd-Module.symvers \
270 --no-print-directory install > $LOG 2>&1; then
271 fail "Look at $LOG to find out what went wrong"
272 fi
273 if [ -n "$BUILDVBOXVFS" ]; then
274 if ! $BUILDVBOXVFS \
275 --use-module-symvers /tmp/vboxadd-Module.symvers \
276 --no-print-directory install >> $LOG 2>&1; then
277 fail "Look at $LOG to find out what went wrong"
278 fi
279 fi
280 if [ -n "$BUILDVBOXVIDEO" ]; then
281 if ! $BUILDVBOXVIDEO \
282 --use-module-symvers /tmp/vboxadd-Module.symvers \
283 --no-print-directory install >> $LOG 2>&1; then
284 fail "Look at $LOG to find out what went wrong"
285 fi
286 fi
287 succ_msg
288 start
289 echo
290 echo "You should reboot your guest to make sure the new modules are actually used"
291}
292
293dmnstatus()
294{
295 if running_vboxadd; then
296 echo "The VirtualBox Additions are currently running."
297 else
298 echo "The VirtualBox Additions are not currently running."
299 fi
300}
301
302case "$1" in
303start)
304 start
305 ;;
306stop)
307 stop
308 ;;
309restart)
310 restart
311 ;;
312setup)
313 setup
314 ;;
315status)
316 dmnstatus
317 ;;
318*)
319 echo "Usage: $0 {start|stop|restart|status}"
320 exit 1
321esac
322
323exit
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