VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/vboxdrv.sh@ 5574

Last change on this file since 5574 was 5498, checked in by vboxsync, 17 years ago

small consistency fix: ensure /dev/vboxdrv permissions as 660 not 664

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1#! /bin/sh
2# innotek VirtualBox
3# Linux kernel module init script
4
5#
6# Copyright (C) 2006-2007 innotek GmbH
7#
8# This file is part of VirtualBox Open Source Edition (OSE), as
9# available from http://www.virtualbox.org. This file is free software;
10# you can redistribute it and/or modify it under the terms of the GNU
11# General Public License as published by the Free Software Foundation,
12# in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13# distribution. VirtualBox OSE is distributed in the hope that it will
14# be useful, but WITHOUT ANY WARRANTY of any kind.
15
16# chkconfig: 35 30 60
17# description: VirtualBox Linux kernel module
18#
19### BEGIN INIT INFO
20# Provides: vboxdrv
21# Required-Start: $syslog
22# Required-Stop:
23# Default-Start: 3 5
24# Default-Stop:
25# Description: VirtualBox Linux kernel module
26### END INIT INFO
27
28PATH=$PATH:/bin:/sbin:/usr/sbin
29CONFIG="/etc/vbox/vbox.cfg"
30
31if [ -f /etc/redhat-release ]; then
32 system=redhat
33elif [ -f /etc/SuSE-release ]; then
34 system=suse
35elif [ -f /etc/gentoo-release ]; then
36 system=gentoo
37else
38 system=other
39fi
40
41if [ "$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 }
56fi
57
58if [ "$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 }
73fi
74
75if [ "$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
92fi
93
94if [ "$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 }
106fi
107
108
109kdir=/lib/modules/`uname -r`/misc
110dev=/dev/vboxdrv
111modname=vboxdrv
112groupname=vboxusers
113
114fail() {
115 if [ "$system" = "gentoo" ]; then
116 eerror $1
117 exit 1
118 fi
119 fail_msg
120 echo "($1)"
121 exit 1
122}
123
124running() {
125 lsmod | grep -q $modname[^_-]
126}
127
128start() {
129 begin "Starting VirtualBox kernel module "
130 test -f "$kdir/$modname.o" -o -f "$kdir/$modname.ko" || {
131 fail "Kernel module not found"
132 }
133 running || {
134 rm -f $dev || {
135 fail "Cannot remove $dev"
136 }
137
138 modprobe $modname || {
139 fail "modprobe $modname failed"
140 }
141
142 sleep 1
143 }
144 if [ ! -c $dev ]; then
145 maj=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/devices`
146 if [ ! -z "$maj" ]; then
147 min=0
148 else
149 min=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc`
150 if [ ! -z "$min" ]; then
151 maj=10
152 fi
153 fi
154 test -z "$maj" && {
155 rmmod $modname
156 fail "Cannot locate the VirtualBox device"
157 }
158
159 mknod -m 0660 $dev c $maj $min || {
160 rmmod $modname
161 fail "Cannot create device $dev with major $maj and minor $min"
162 }
163 fi
164
165 chown :$groupname $dev || {
166 rmmod $modname
167 fail "Cannot change owner $groupname for device $dev"
168 }
169
170 succ_msg
171 return 0
172}
173
174stop() {
175 begin "Stopping VirtualBox kernel module "
176 if running; then
177 rmmod $modname || fail "Cannot unload module $modname"
178 rm -f $dev || fail "Cannot unlink $dev"
179 fi
180 succ_msg
181 return 0
182}
183
184restart() {
185 stop && start
186 return 0
187}
188
189setup() {
190 . "$CONFIG"
191 stop
192 begin "Recompiling VirtualBox kernel module "
193 if ! $INSTALL_DIR/src/build_in_tmp install > /var/log/vbox-install.log 2>&1; then
194 fail "Look at /var/log/vbox-install.log to find out what went wrong"
195 fi
196 succ_msg
197 start
198}
199
200dmnstatus() {
201 if running; then
202 echo "VirtualBox kernel module is loaded."
203 else
204 echo "VirtualBox kernel module is not loaded."
205 fi
206}
207
208case "$1" in
209start)
210 start
211 ;;
212stop)
213 stop
214 ;;
215restart)
216 restart
217 ;;
218setup)
219 setup
220 ;;
221status)
222 dmnstatus
223 ;;
224*)
225 echo "Usage: $0 {start|stop|restart|status|setup}"
226 exit 1
227esac
228
229exit
Note: See TracBrowser for help on using the repository browser.

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