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