VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/installer/vboxadd.sh@ 8155

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

The Big Sun Rebranding Header Change

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