VirtualBox

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

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

config file cleanup + small copyright year update

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1#! /bin/sh
2# Sun VirtualBox
3# Linux Additions kernel module init script
4#
5# Copyright (C) 2006-2009 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 70
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
145userdev=/dev/vboxuser
146owner=vboxadd
147group=1
148
149fail()
150{
151 if [ "$system" = "gentoo" ]; then
152 eerror $1
153 exit 1
154 fi
155 fail_msg
156 echo "($1)"
157 exit 1
158}
159
160running_vboxadd()
161{
162 lsmod | grep -q "vboxadd[^_-]"
163}
164
165running_vboxvfs()
166{
167 lsmod | grep -q "vboxvfs[^_-]"
168}
169
170start()
171{
172 begin "Starting VirtualBox Additions ";
173 running_vboxadd || {
174 rm -f $dev || {
175 fail "Cannot remove $dev"
176 }
177
178 rm -f $userdev || {
179 fail "Cannot remove $userdev"
180 }
181
182 modprobe vboxadd >/dev/null 2>&1 || {
183 fail "modprobe vboxadd failed"
184 }
185 sleep .5
186 }
187 if [ ! -c $dev ]; then
188 maj=`sed -n 's;\([0-9]\+\) vboxadd;\1;p' /proc/devices`
189 if [ ! -z "$maj" ]; then
190 min=0
191 else
192 min=`sed -n 's;\([0-9]\+\) vboxadd;\1;p' /proc/misc`
193 if [ ! -z "$min" ]; then
194 maj=10
195 fi
196 fi
197 test -z "$maj" && {
198 rmmod vboxadd 2>/dev/null
199 fail "Cannot locate the VirtualBox device"
200 }
201
202 mknod -m 0664 $dev c $maj $min || {
203 rmmod vboxadd 2>/dev/null
204 fail "Cannot create device $dev with major $maj and minor $min"
205 }
206 fi
207 chown $owner:$group $dev 2>/dev/null || {
208 rm -f $dev 2>/dev/null
209 rm -f $userdev 2>/dev/null
210 rmmod vboxadd 2>/dev/null
211 fail "Cannot change owner $owner:$group for device $dev"
212 }
213
214 if [ ! -c $userdev ]; then
215 maj=10
216 min=`sed -n 's;\([0-9]\+\) vboxuser;\1;p' /proc/misc`
217 if [ ! -z "$min" ]; then
218 mknod -m 0666 $userdev c $maj $min || {
219 rm -f $dev 2>/dev/null
220 rmmod vboxadd 2>/dev/null
221 fail "Cannot create device $userdev with major $maj and minor $min"
222 }
223 chown $owner:$group $userdev 2>/dev/null || {
224 rm -f $dev 2>/dev/null
225 rm -f $userdev 2>/dev/null
226 rmmod vboxadd 2>/dev/null
227 fail "Cannot change owner $owner:$group for device $userdev"
228 }
229 fi
230 fi
231
232 if [ -n "$BUILDVBOXVFS" ]; then
233 running_vboxvfs || {
234 modprobe vboxvfs > /dev/null 2>&1 || {
235 if dmesg | grep "vboxConnect failed" > /dev/null 2>&1; then
236 fail_msg
237 echo "Unable to start shared folders support. Make sure that your VirtualBox build"
238 echo "supports this feature."
239 exit 1
240 fi
241 fail "modprobe vboxvfs failed"
242 }
243 }
244 fi
245
246 # Mount all shared folders from /etc/fstab. Normally this is done by some
247 # other startup script but this requires the vboxdrv kernel module loaded.
248 mount -a -t vboxsf
249
250 succ_msg
251 return 0
252}
253
254stop()
255{
256 begin "Stopping VirtualBox Additions ";
257 if !umount -a -t vboxsf 2>/dev/null; then
258 fail "Cannot unmount vboxsf folders"
259 fi
260 if [ -n "$BUILDVBOXVFS" ]; then
261 if running_vboxvfs; then
262 rmmod vboxvfs 2>/dev/null || fail "Cannot unload module vboxvfs"
263 fi
264 fi
265 if running_vboxadd; then
266 rmmod vboxadd 2>/dev/null || fail "Cannot unload module vboxadd"
267 rm -f $userdev || fail "Cannot unlink $userdev"
268 rm -f $dev || fail "Cannot unlink $dev"
269 fi
270 succ_msg
271 return 0
272}
273
274restart()
275{
276 stop && start
277 return 0
278}
279
280setup()
281{
282 # don't stop the old modules here -- they might be in use
283 if find /lib/modules/`uname -r` -name "vboxvfs\.*" 2>/dev/null|grep -q vboxvfs; then
284 begin "Removing old VirtualBox vboxvfs kernel module"
285 find /lib/modules/`uname -r` -name "vboxvfs\.*" 2>/dev/null|xargs rm -f 2>/dev/null
286 succ_msg
287 fi
288 if find /lib/modules/`uname -r` -name "vboxadd\.*" 2>/dev/null|grep -q vboxadd; then
289 begin "Removing old VirtualBox vboxadd kernel module"
290 find /lib/modules/`uname -r` -name "vboxadd\.*" 2>/dev/null|xargs rm -f 2>/dev/null
291 succ_msg
292 fi
293 begin "Recompiling VirtualBox kernel modules"
294 if ! $BUILDVBOXADD \
295 --save-module-symvers /tmp/vboxadd-Module.symvers \
296 --no-print-directory install > $LOG 2>&1; then
297 fail "Look at $LOG to find out what went wrong"
298 fi
299 if [ -n "$BUILDVBOXVFS" ]; then
300 if ! $BUILDVBOXVFS \
301 --use-module-symvers /tmp/vboxadd-Module.symvers \
302 --no-print-directory install >> $LOG 2>&1; then
303 fail "Look at $LOG to find out what went wrong"
304 fi
305 fi
306 if [ -n "$BUILDVBOXVIDEO" ]; then
307 if ! $BUILDVBOXVIDEO \
308 --use-module-symvers /tmp/vboxadd-Module.symvers \
309 --no-print-directory install >> $LOG 2>&1; then
310 fail "Look at $LOG to find out what went wrong"
311 fi
312 fi
313 succ_msg
314 start
315 echo
316 echo "You should reboot your guest to make sure the new modules are actually used"
317}
318
319dmnstatus()
320{
321 if running_vboxadd; then
322 echo "The VirtualBox Additions are currently running."
323 else
324 echo "The VirtualBox Additions are not currently running."
325 fi
326}
327
328case "$1" in
329start)
330 start
331 ;;
332stop)
333 stop
334 ;;
335restart)
336 restart
337 ;;
338setup)
339 setup
340 ;;
341status)
342 dmnstatus
343 ;;
344*)
345 echo "Usage: $0 {start|stop|restart|status}"
346 exit 1
347esac
348
349exit
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