VirtualBox

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

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

Installers/Linux: cosmetic patch for init scripts for ArchLinux, contributed by ColdShine

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