VirtualBox

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

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

Additions/Linux/installer: LFS support fixes from Arseny Krautsky

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 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`
36LOG="/var/log/vboxadd-install.log"
37
38if [ -f /etc/arch-release ]; then
39 system=arch
40elif [ -f /etc/redhat-release ]; then
41 system=redhat
42elif [ -f /etc/SuSE-release ]; then
43 system=suse
44elif [ -f /etc/gentoo-release ]; then
45 system=gentoo
46elif [ -f /etc/lfs-release -a -d /etc/rc.d/init.d ]; then
47 system=lfs
48else
49 system=other
50fi
51
52if [ "$system" = "arch" ]; then
53 USECOLOR=yes
54 . /etc/rc.d/functions
55 fail_msg() {
56 stat_fail
57 }
58
59 succ_msg() {
60 stat_done
61 }
62
63 begin() {
64 stat_busy "$1"
65 }
66fi
67
68if [ "$system" = "redhat" ]; then
69 . /etc/init.d/functions
70 fail_msg() {
71 echo_failure
72 echo
73 }
74 succ_msg() {
75 echo_success
76 echo
77 }
78 begin() {
79 echo -n "$1"
80 }
81fi
82
83if [ "$system" = "suse" ]; then
84 . /etc/rc.status
85 fail_msg() {
86 rc_failed 1
87 rc_status -v
88 }
89 succ_msg() {
90 rc_reset
91 rc_status -v
92 }
93 begin() {
94 echo -n "$1"
95 }
96fi
97
98if [ "$system" = "gentoo" ]; then
99 if [ -f /sbin/functions.sh ]; then
100 . /sbin/functions.sh
101 elif [ -f /etc/init.d/functions.sh ]; then
102 . /etc/init.d/functions.sh
103 fi
104 fail_msg() {
105 eend 1
106 }
107 succ_msg() {
108 eend $?
109 }
110 begin() {
111 ebegin $1
112 }
113 if [ "`which $0`" = "/sbin/rc" ]; then
114 shift
115 fi
116fi
117
118if [ "$system" = "lfs" ]; then
119 . /etc/rc.d/init.d/functions
120 fail_msg() {
121 echo_failure
122 }
123 succ_msg() {
124 echo_ok
125 }
126 begin() {
127 echo $1
128 }
129fi
130
131if [ "$system" = "other" ]; then
132 fail_msg() {
133 echo " ...fail!"
134 }
135 succ_msg() {
136 echo " ...done."
137 }
138 begin() {
139 echo -n $1
140 }
141fi
142
143dev=/dev/vboxadd
144owner=vboxadd
145group=1
146
147fail()
148{
149 if [ "$system" = "gentoo" ]; then
150 eerror $1
151 exit 1
152 fi
153 fail_msg
154 echo "($1)"
155 exit 1
156}
157
158running_vboxadd()
159{
160 lsmod | grep -q "vboxadd[^_-]"
161}
162
163running_vboxvfs()
164{
165 lsmod | grep -q "vboxvfs[^_-]"
166}
167
168start()
169{
170 begin "Starting VirtualBox Additions ";
171 running_vboxadd || {
172 rm -f $dev || {
173 fail "Cannot remove $dev"
174 }
175
176 modprobe vboxadd >/dev/null 2>&1 || {
177 fail "modprobe vboxadd failed"
178 }
179 sleep .5
180 }
181 if [ ! -c $dev ]; then
182 maj=`sed -n 's;\([0-9]\+\) vboxadd;\1;p' /proc/devices`
183 if [ ! -z "$maj" ]; then
184 min=0
185 else
186 min=`sed -n 's;\([0-9]\+\) vboxadd;\1;p' /proc/misc`
187 if [ ! -z "$min" ]; then
188 maj=10
189 fi
190 fi
191 test -z "$maj" && {
192 rmmod vboxadd 2>/dev/null
193 fail "Cannot locate the VirtualBox device"
194 }
195
196 mknod -m 0664 $dev c $maj $min || {
197 rmmod vboxadd 2>/dev/null
198 fail "Cannot create device $dev with major $maj and minor $min"
199 }
200 fi
201 chown $owner:$group $dev 2>/dev/null || {
202 rmmod vboxadd 2>/dev/null
203 fail "Cannot change owner $owner:$group for device $dev"
204 }
205
206 if [ -n "$BUILDVBOXVFS" ]; then
207 running_vboxvfs || {
208 modprobe vboxvfs > /dev/null 2>&1 || {
209 if dmesg | grep "vboxConnect failed" > /dev/null 2>&1; then
210 fail_msg
211 echo "You may be trying to run Guest Additions from binary release of VirtualBox"
212 echo "in the Open Source Edition."
213 exit 1
214 fi
215 fail "modprobe vboxvfs failed"
216 }
217 }
218 fi
219
220 # Mount all shared folders from /etc/fstab. Normally this is done by some
221 # other startup script but this requires the vboxdrv kernel module loaded.
222 mount -a -t vboxsf
223
224 succ_msg
225 return 0
226}
227
228stop()
229{
230 begin "Stopping VirtualBox Additions ";
231 if !umount -a -t vboxsf 2>/dev/null; then
232 fail "Cannot unmount vboxsf folders"
233 fi
234 if [ -n "$BUILDVBOXVFS" ]; then
235 if running_vboxvfs; then
236 rmmod vboxvfs 2>/dev/null || fail "Cannot unload module vboxvfs"
237 fi
238 fi
239 if running_vboxadd; then
240 rmmod vboxadd 2>/dev/null || fail "Cannot unload module vboxadd"
241 rm -f $dev || fail "Cannot unlink $dev"
242 fi
243 succ_msg
244 return 0
245}
246
247restart()
248{
249 stop && start
250 return 0
251}
252
253setup()
254{
255 # don't stop the old modules here -- they might be in use
256 if find /lib/modules/`uname -r` -name "vboxvfs\.*" 2>/dev/null|grep -q vboxvfs; then
257 begin "Removing old VirtualBox vboxvfs kernel module"
258 find /lib/modules/`uname -r` -name "vboxvfs\.*" 2>/dev/null|xargs rm -f 2>/dev/null
259 succ_msg
260 fi
261 if find /lib/modules/`uname -r` -name "vboxadd\.*" 2>/dev/null|grep -q vboxadd; then
262 begin "Removing old VirtualBox vboxadd kernel module"
263 find /lib/modules/`uname -r` -name "vboxadd\.*" 2>/dev/null|xargs rm -f 2>/dev/null
264 succ_msg
265 fi
266 begin "Recompiling VirtualBox kernel modules"
267 if ! $BUILDVBOXADD \
268 --save-module-symvers /tmp/vboxadd-Module.symvers \
269 --no-print-directory install > $LOG 2>&1; then
270 fail "Look at $LOG to find out what went wrong"
271 fi
272 if [ -n "$BUILDVBOXVFS" ]; then
273 if ! $BUILDVBOXVFS \
274 --use-module-symvers /tmp/vboxadd-Module.symvers \
275 --no-print-directory install >> $LOG 2>&1; then
276 fail "Look at $LOG to find out what went wrong"
277 fi
278 fi
279 succ_msg
280 start
281 echo
282 echo "You should reboot your guest to make sure the new modules are actually used"
283}
284
285dmnstatus()
286{
287 if running_vboxadd; then
288 echo "The VirtualBox Additions are currently running."
289 else
290 echo "The VirtualBox Additions are not currently running."
291 fi
292}
293
294case "$1" in
295start)
296 start
297 ;;
298stop)
299 stop
300 ;;
301restart)
302 restart
303 ;;
304setup)
305 setup
306 ;;
307status)
308 dmnstatus
309 ;;
310*)
311 echo "Usage: $0 {start|stop|restart|status}"
312 exit 1
313esac
314
315exit
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