VirtualBox

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

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

Additions/X11: weakened SUID root permissions on VBoxClient on Linux. This may need some additional corrections for Solaris.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
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 (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
29PATH=$PATH:/bin:/sbin:/usr/sbin
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
108kdir=/lib/modules/`uname -r`/misc
109dev=/dev/vboxadd
110modname=vboxadd
111module=$kdir/$modname
112owner=vboxadd
113group=1
114
115file=""
116test -f $module.o && file=$module.o
117test -f $module.ko && file=$module.ko
118
119fail() {
120 if [ "$system" = "gentoo" ]; then
121 eerror $1
122 exit 1
123 fi
124 fail_msg
125 echo "($1)"
126 exit 1
127}
128
129test -z "$file" && {
130 fail "Kernel module not found"
131}
132
133running() {
134 lsmod | grep -q $modname[^_-]
135}
136
137start() {
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
180stop() {
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
190restart() {
191 stop && start
192 return 0
193}
194
195dmnstatus() {
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
203case "$1" in
204start)
205 start
206 ;;
207stop)
208 stop
209 ;;
210restart)
211 restart
212 ;;
213status)
214 dmnstatus
215 ;;
216*)
217 echo "Usage: $0 {start|stop|restart|status}"
218 exit 1
219esac
220
221exit
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