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