VirtualBox

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

Last change on this file since 423 was 423, checked in by vboxsync, 18 years ago

Made sure that the Linux kernel modules get the right major and minor numbers on systems without udev

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1#! /bin/sh
2# InnoTek VirtualBox
3# Linux Additions kernel module init script
4#
5# Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
11# in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
12# distribution. VirtualBox OSE is distributed in the hope that it will
13# be useful, but WITHOUT ANY WARRANTY of any kind.
14#
15# If you received this file as part of a commercial VirtualBox
16# distribution, then only the terms of your commercial VirtualBox
17# license agreement apply instead of the previous paragraph.
18
19
20# chkconfig: 35 30 60
21# description: VirtualBox Linux Additions kernel module
22#
23### BEGIN INIT INFO
24# Provides: vboxadd
25# Required-Start: $syslog
26# Required-Stop:
27# Default-Start: 3 5
28# Default-Stop:
29# Description: VirtualBox Linux Additions kernel module
30### END INIT INFO
31
32PATH=$PATH:/bin:/sbin:/usr/sbin
33
34system=unknown
35if [ -f /etc/redhat-release ]; then
36 system=redhat
37elif [ -f /etc/SuSE-release ]; then
38 system=suse
39elif [ -f /etc/debian_version ]; then
40 system=debian
41elif [ -f /etc/gentoo-release ]; then
42 system=gentoo
43elif [ -f /etc/slackware-version ]; then
44 system=slackware
45else
46 echo "$0: Unknown system" 1>&2
47fi
48
49if [ "$system" = "redhat" ]; then
50 . /etc/init.d/functions
51 fail_msg() {
52 echo_failure
53 echo
54 }
55
56 succ_msg() {
57 echo_success
58 echo
59 }
60
61 begin() {
62 echo -n $1
63 }
64fi
65
66if [ "$system" = "suse" ]; then
67 . /etc/rc.status
68 fail_msg() {
69 rc_failed 1
70 rc_status -v
71 }
72
73 succ_msg() {
74 rc_reset
75 rc_status -v
76 }
77
78 begin() {
79 echo -n $1
80 }
81fi
82
83if [ "$system" = "debian" ]; then
84 fail_msg() {
85 echo " ...fail!"
86 }
87
88 succ_msg() {
89 echo " ...done."
90 }
91
92 begin() {
93 echo -n $1
94 }
95fi
96
97if [ "$system" = "gentoo" ]; then
98 . /sbin/functions.sh
99 fail_msg() {
100 eend 1
101 }
102
103 succ_msg() {
104 eend $?
105 }
106
107 begin() {
108 ebegin $1
109 }
110
111 if [ "`which $0`" = "/sbin/rc" ]; then
112 shift
113 fi
114fi
115
116if [ "$system" = "slackware" ]; then
117 fail_msg() {
118 echo " ...fail!"
119 }
120
121 succ_msg() {
122 echo " ...done."
123 }
124
125 begin() {
126 echo -n $1
127 }
128fi
129
130kdir=/lib/modules/`uname -r`/misc
131dev=/dev/vboxadd
132modname=vboxadd
133module=$kdir/$modname
134
135file=""
136test -f $module.o && file=$module.o
137test -f $module.ko && file=$module.ko
138
139fail() {
140 if [ "$system" = "gentoo" ]; then
141 eerror $1
142 exit 1
143 fi
144 fail_msg
145 echo "($1)"
146 exit 1
147}
148
149test -z "$file" && {
150 fail "Kernel module not found"
151}
152
153running() {
154 lsmod | grep -q $modname[^_-]
155}
156
157start() {
158 begin "Starting VirtualBox Additions ";
159 running || {
160 rm -f $dev || {
161 fail "Cannot remove $dev"
162 }
163
164 modprobe $modname || {
165 fail "modprobe $modname failed"
166 }
167
168 sleep 1
169 }
170 if [ ! -c $dev ]; then
171 maj=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/devices`
172 if [ ! -z "$maj" ]; then
173 min=0
174 else
175 min=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc`
176 if [ ! -z "$min" ]; then
177 maj=10
178 fi
179 fi
180 test -z "$maj" && {
181 rmmod $modname
182 fail "Cannot locate the VirtualBox device"
183 }
184
185 mknod -m 0664 $dev c $maj $min || {
186 rmmod $modname
187 fail "Cannot create device $dev with major $maj and minor $min"
188 }
189 fi
190
191 succ_msg
192 return 0
193}
194
195stop() {
196 begin "Stopping VirtualBox Additions ";
197 if running; then
198 rmmod $modname || fail "Cannot unload module $modname"
199 rm -f $dev || fail "Cannot unlink $dev"
200 fi
201 succ_msg
202 return 0
203}
204
205restart() {
206 stop && start
207 return 0
208}
209
210dmnstatus() {
211 if running; then
212 echo "The VirtualBox Additions are currently running."
213 else
214 echo "The VirtualBox Additions are not currently running."
215 fi
216}
217
218case "$1" in
219start)
220 start
221 ;;
222stop)
223 stop
224 ;;
225restart)
226 restart
227 ;;
228status)
229 dmnstatus
230 ;;
231*)
232 echo "Usage: $0 {start|stop|restart|status}"
233 exit 1
234esac
235
236exit
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