| 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 |
|
|---|
| 28 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
|---|
| 29 |
|
|---|
| 30 | if [ -f /etc/lfs-release ]; then
|
|---|
| 31 | system=lfs
|
|---|
| 32 | elif [ -f /etc/redhat-release ]; then
|
|---|
| 33 | system=redhat
|
|---|
| 34 | elif [ -f /etc/SuSE-release ]; then
|
|---|
| 35 | system=suse
|
|---|
| 36 | elif [ -f /etc/gentoo-release ]; then
|
|---|
| 37 | system=gentoo
|
|---|
| 38 | else
|
|---|
| 39 | system=other
|
|---|
| 40 | fi
|
|---|
| 41 |
|
|---|
| 42 | if [ "$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 | }
|
|---|
| 57 | fi
|
|---|
| 58 |
|
|---|
| 59 | if [ "$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 | }
|
|---|
| 74 | fi
|
|---|
| 75 |
|
|---|
| 76 | if [ "$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 | }
|
|---|
| 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 | if [ "$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 | }
|
|---|
| 124 | fi
|
|---|
| 125 |
|
|---|
| 126 | kdir=/lib/modules/`uname -r`/misc
|
|---|
| 127 | dev=/dev/vboxadd
|
|---|
| 128 | modname=vboxadd
|
|---|
| 129 | module=$kdir/$modname
|
|---|
| 130 |
|
|---|
| 131 | file=""
|
|---|
| 132 | test -f $module.o && file=$module.o
|
|---|
| 133 | test -f $module.ko && file=$module.ko
|
|---|
| 134 |
|
|---|
| 135 | fail() {
|
|---|
| 136 | if [ "$system" = "gentoo" ]; then
|
|---|
| 137 | eerror $1
|
|---|
| 138 | exit 1
|
|---|
| 139 | fi
|
|---|
| 140 | fail_msg
|
|---|
| 141 | echo "($1)"
|
|---|
| 142 | exit 1
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | test -z "$file" && {
|
|---|
| 146 | fail "Kernel module not found"
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | running() {
|
|---|
| 150 | lsmod | grep -q $modname[^_-]
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | start() {
|
|---|
| 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 |
|
|---|
| 191 | stop() {
|
|---|
| 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 |
|
|---|
| 201 | restart() {
|
|---|
| 202 | stop && start
|
|---|
| 203 | return 0
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | dmnstatus() {
|
|---|
| 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 |
|
|---|
| 214 | case "$1" in
|
|---|
| 215 | start)
|
|---|
| 216 | start
|
|---|
| 217 | ;;
|
|---|
| 218 | stop)
|
|---|
| 219 | stop
|
|---|
| 220 | ;;
|
|---|
| 221 | restart)
|
|---|
| 222 | restart
|
|---|
| 223 | ;;
|
|---|
| 224 | status)
|
|---|
| 225 | dmnstatus
|
|---|
| 226 | ;;
|
|---|
| 227 | *)
|
|---|
| 228 | echo "Usage: $0 {start|stop|restart|status}"
|
|---|
| 229 | exit 1
|
|---|
| 230 | esac
|
|---|
| 231 |
|
|---|
| 232 | exit
|
|---|