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