VirtualBox

Ticket #758: vboxadd

File vboxadd, 4.1 KB (added by John Gnew, 17 years ago)

vboxadd

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy