VirtualBox

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

最後變更 在這個檔案從15784是 15784,由 vboxsync 提交於 16 年 前

Linux Gentoo scripts fix

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette