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 |
|
---|
32 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
33 |
|
---|
34 | system=unknown
|
---|
35 | if [ -f /etc/redhat-release ]; then
|
---|
36 | system=redhat
|
---|
37 | elif [ -f /etc/SuSE-release ]; then
|
---|
38 | system=suse
|
---|
39 | elif [ -f /etc/debian_version ]; then
|
---|
40 | system=debian
|
---|
41 | elif [ -f /etc/gentoo-release ]; then
|
---|
42 | system=gentoo
|
---|
43 | elif [ -f /etc/slackware-version ]; then
|
---|
44 | system=slackware
|
---|
45 | else
|
---|
46 | echo "$0: Unknown system" 1>&2
|
---|
47 | fi
|
---|
48 |
|
---|
49 | if [ "$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 | }
|
---|
64 | fi
|
---|
65 |
|
---|
66 | if [ "$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 | }
|
---|
81 | fi
|
---|
82 |
|
---|
83 | if [ "$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 | }
|
---|
95 | fi
|
---|
96 |
|
---|
97 | if [ "$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
|
---|
114 | fi
|
---|
115 |
|
---|
116 | if [ "$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 | }
|
---|
128 | fi
|
---|
129 |
|
---|
130 | kdir=/lib/modules/`uname -r`/misc
|
---|
131 | dev=/dev/vboxadd
|
---|
132 | modname=vboxadd
|
---|
133 | module=$kdir/$modname
|
---|
134 |
|
---|
135 | file=""
|
---|
136 | test -f $module.o && file=$module.o
|
---|
137 | test -f $module.ko && file=$module.ko
|
---|
138 |
|
---|
139 | fail() {
|
---|
140 | if [ "$system" = "gentoo" ]; then
|
---|
141 | eerror $1
|
---|
142 | exit 1
|
---|
143 | fi
|
---|
144 | fail_msg
|
---|
145 | echo "($1)"
|
---|
146 | exit 1
|
---|
147 | }
|
---|
148 |
|
---|
149 | test -z "$file" && {
|
---|
150 | fail "Kernel module not found"
|
---|
151 | }
|
---|
152 |
|
---|
153 | running() {
|
---|
154 | lsmod | grep -q $modname[^_-]
|
---|
155 | }
|
---|
156 |
|
---|
157 | start() {
|
---|
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]\+\) vboxadd;\1;p' /proc/devices`
|
---|
172 | if [ ! -z "$maj" ]; then
|
---|
173 | min=0
|
---|
174 | else
|
---|
175 | min=`sed -n 's;\([0-9]\+\) vboxadd;\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 |
|
---|
195 | stop() {
|
---|
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 |
|
---|
205 | restart() {
|
---|
206 | stop && start
|
---|
207 | return 0
|
---|
208 | }
|
---|
209 |
|
---|
210 | dmnstatus() {
|
---|
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 |
|
---|
218 | case "$1" in
|
---|
219 | start)
|
---|
220 | start
|
---|
221 | ;;
|
---|
222 | stop)
|
---|
223 | stop
|
---|
224 | ;;
|
---|
225 | restart)
|
---|
226 | restart
|
---|
227 | ;;
|
---|
228 | status)
|
---|
229 | dmnstatus
|
---|
230 | ;;
|
---|
231 | *)
|
---|
232 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
233 | exit 1
|
---|
234 | esac
|
---|
235 |
|
---|
236 | exit
|
---|