| 1 | #! /bin/sh
|
|---|
| 2 | # $Id: vboxadd.sh 118913 2017-11-03 14:36:26Z michael $
|
|---|
| 3 | ## @file
|
|---|
| 4 | # Linux Additions kernel module init script ($Revision: 118913 $)
|
|---|
| 5 | #
|
|---|
| 6 |
|
|---|
| 7 | #
|
|---|
| 8 | # Copyright (C) 2006-2017 Oracle Corporation
|
|---|
| 9 | #
|
|---|
| 10 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
|---|
| 11 | # available from http://www.virtualbox.org. This file is free software;
|
|---|
| 12 | # you can redistribute it and/or modify it under the terms of the GNU
|
|---|
| 13 | # General Public License (GPL) as published by the Free Software
|
|---|
| 14 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
|---|
| 15 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
|---|
| 16 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
|---|
| 17 | #
|
|---|
| 18 |
|
|---|
| 19 | # X-Start-Before is a Debian Addition which we use when converting to
|
|---|
| 20 | # a systemd unit. X-Service-Type is our own invention, also for systemd.
|
|---|
| 21 |
|
|---|
| 22 | # chkconfig: 345 10 90
|
|---|
| 23 | # description: VirtualBox Linux Additions kernel modules
|
|---|
| 24 | #
|
|---|
| 25 | ### BEGIN INIT INFO
|
|---|
| 26 | # Provides: vboxadd
|
|---|
| 27 | # Required-Start:
|
|---|
| 28 | # Required-Stop:
|
|---|
| 29 | # Default-Start: 2 3 4 5
|
|---|
| 30 | # Default-Stop: 0 1 6
|
|---|
| 31 | # X-Start-Before: display-manager
|
|---|
| 32 | # X-Service-Type: oneshot
|
|---|
| 33 | # Description: VirtualBox Linux Additions kernel modules
|
|---|
| 34 | ### END INIT INFO
|
|---|
| 35 |
|
|---|
| 36 | ## @todo This file duplicates a lot of script with vboxdrv.sh. When making
|
|---|
| 37 | # changes please try to reduce differences between the two wherever possible.
|
|---|
| 38 |
|
|---|
| 39 | # Testing:
|
|---|
| 40 | # * Should fail if the configuration file is missing or missing INSTALL_DIR or
|
|---|
| 41 | # INSTALL_VER entries.
|
|---|
| 42 | # * vboxadd user and vboxsf groups should be created if they do not exist - test
|
|---|
| 43 | # by removing them before installing.
|
|---|
| 44 | # * Shared folders can be mounted and auto-mounts accessible to vboxsf group,
|
|---|
| 45 | # including on recent Fedoras with SELinux.
|
|---|
| 46 | # * Setting INSTALL_NO_MODULE_BUILDS inhibits modules and module automatic
|
|---|
| 47 | # rebuild script creation; otherwise modules, user, group, rebuild script,
|
|---|
| 48 | # udev rule and shared folder mount helper should be created/set up.
|
|---|
| 49 | # * Setting INSTALL_NO_MODULE_BUILDS inhibits module load and unload on start
|
|---|
| 50 | # and stop.
|
|---|
| 51 | # * Uninstalling the Additions and re-installing them does not trigger warnings.
|
|---|
| 52 |
|
|---|
| 53 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
|---|
| 54 | PACKAGE=VBoxGuestAdditions
|
|---|
| 55 | MODPROBE=/sbin/modprobe
|
|---|
| 56 | OLDMODULES="vboxguest vboxadd vboxsf vboxvfs vboxvideo"
|
|---|
| 57 | SERVICE="VirtualBox Guest Additions"
|
|---|
| 58 | QUICKSETUP=
|
|---|
| 59 | ## systemd logs information about service status, otherwise do that ourselves.
|
|---|
| 60 | QUIET=
|
|---|
| 61 |
|
|---|
| 62 | setup_log()
|
|---|
| 63 | {
|
|---|
| 64 | test -n "${LOG}" && return 0
|
|---|
| 65 | # Rotate log files
|
|---|
| 66 | LOG="/var/log/vboxadd-setup.log"
|
|---|
| 67 | mv "${LOG}.3" "${LOG}.4" 2>/dev/null
|
|---|
| 68 | mv "${LOG}.2" "${LOG}.3" 2>/dev/null
|
|---|
| 69 | mv "${LOG}.1" "${LOG}.2" 2>/dev/null
|
|---|
| 70 | mv "${LOG}" "${LOG}.1" 2>/dev/null
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | if $MODPROBE -c 2>/dev/null | grep -q '^allow_unsupported_modules *0'; then
|
|---|
| 74 | MODPROBE="$MODPROBE --allow-unsupported-modules"
|
|---|
| 75 | fi
|
|---|
| 76 |
|
|---|
| 77 | # Check architecture
|
|---|
| 78 | cpu=`uname -m`;
|
|---|
| 79 | case "$cpu" in
|
|---|
| 80 | i[3456789]86|x86)
|
|---|
| 81 | cpu="x86"
|
|---|
| 82 | ldconfig_arch="(libc6)"
|
|---|
| 83 | lib_candidates="/usr/lib/i386-linux-gnu /usr/lib /lib"
|
|---|
| 84 | ;;
|
|---|
| 85 | x86_64|amd64)
|
|---|
| 86 | cpu="amd64"
|
|---|
| 87 | ldconfig_arch="(libc6,x86-64)"
|
|---|
| 88 | lib_candidates="/usr/lib/x86_64-linux-gnu /usr/lib64 /usr/lib /lib64 /lib"
|
|---|
| 89 | ;;
|
|---|
| 90 | esac
|
|---|
| 91 | for i in $lib_candidates; do
|
|---|
| 92 | if test -d "$i/VBoxGuestAdditions"; then
|
|---|
| 93 | lib_path=$i
|
|---|
| 94 | break
|
|---|
| 95 | fi
|
|---|
| 96 | done
|
|---|
| 97 |
|
|---|
| 98 | # Preamble for Gentoo
|
|---|
| 99 | if [ "`which $0`" = "/sbin/rc" ]; then
|
|---|
| 100 | shift
|
|---|
| 101 | fi
|
|---|
| 102 |
|
|---|
| 103 | begin()
|
|---|
| 104 | {
|
|---|
| 105 | test -z "${QUIET}" && echo "${SERVICE}: ${1}"
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | info()
|
|---|
| 109 | {
|
|---|
| 110 | if test -z "${QUIET}"; then
|
|---|
| 111 | echo "${SERVICE}: $1"
|
|---|
| 112 | else
|
|---|
| 113 | echo "$1"
|
|---|
| 114 | fi
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | fail()
|
|---|
| 118 | {
|
|---|
| 119 | log "${1}"
|
|---|
| 120 | echo "$1" >&2
|
|---|
| 121 | echo "The log file $LOG may contain further information." >&2
|
|---|
| 122 | exit 1
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | log()
|
|---|
| 126 | {
|
|---|
| 127 | setup_log
|
|---|
| 128 | echo "${1}" >> "${LOG}"
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | dev=/dev/vboxguest
|
|---|
| 132 | userdev=/dev/vboxuser
|
|---|
| 133 | config=/var/lib/VBoxGuestAdditions/config
|
|---|
| 134 | owner=vboxadd
|
|---|
| 135 | group=1
|
|---|
| 136 |
|
|---|
| 137 | if test -r $config; then
|
|---|
| 138 | . $config
|
|---|
| 139 | else
|
|---|
| 140 | fail "Configuration file $config not found"
|
|---|
| 141 | fi
|
|---|
| 142 | test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
|
|---|
| 143 | fail "Configuration file $config not complete"
|
|---|
| 144 |
|
|---|
| 145 | running_vboxguest()
|
|---|
| 146 | {
|
|---|
| 147 | lsmod | grep -q "vboxguest[^_-]"
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | running_vboxadd()
|
|---|
| 151 | {
|
|---|
| 152 | lsmod | grep -q "vboxadd[^_-]"
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | running_vboxsf()
|
|---|
| 156 | {
|
|---|
| 157 | lsmod | grep -q "vboxsf[^_-]"
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | running_vboxvideo()
|
|---|
| 161 | {
|
|---|
| 162 | lsmod | grep -q "vboxvideo[^_-]"
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | do_vboxguest_non_udev()
|
|---|
| 166 | {
|
|---|
| 167 | if [ ! -c $dev ]; then
|
|---|
| 168 | maj=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/devices`
|
|---|
| 169 | if [ ! -z "$maj" ]; then
|
|---|
| 170 | min=0
|
|---|
| 171 | else
|
|---|
| 172 | min=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/misc`
|
|---|
| 173 | if [ ! -z "$min" ]; then
|
|---|
| 174 | maj=10
|
|---|
| 175 | fi
|
|---|
| 176 | fi
|
|---|
| 177 | test -z "$maj" && {
|
|---|
| 178 | rmmod vboxguest 2>/dev/null
|
|---|
| 179 | fail "Cannot locate the VirtualBox device"
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | mknod -m 0664 $dev c $maj $min || {
|
|---|
| 183 | rmmod vboxguest 2>/dev/null
|
|---|
| 184 | fail "Cannot create device $dev with major $maj and minor $min"
|
|---|
| 185 | }
|
|---|
| 186 | fi
|
|---|
| 187 | chown $owner:$group $dev 2>/dev/null || {
|
|---|
| 188 | rm -f $dev 2>/dev/null
|
|---|
| 189 | rm -f $userdev 2>/dev/null
|
|---|
| 190 | rmmod vboxguest 2>/dev/null
|
|---|
| 191 | fail "Cannot change owner $owner:$group for device $dev"
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | if [ ! -c $userdev ]; then
|
|---|
| 195 | maj=10
|
|---|
| 196 | min=`sed -n 's;\([0-9]\+\) vboxuser;\1;p' /proc/misc`
|
|---|
| 197 | if [ ! -z "$min" ]; then
|
|---|
| 198 | mknod -m 0666 $userdev c $maj $min || {
|
|---|
| 199 | rm -f $dev 2>/dev/null
|
|---|
| 200 | rmmod vboxguest 2>/dev/null
|
|---|
| 201 | fail "Cannot create device $userdev with major $maj and minor $min"
|
|---|
| 202 | }
|
|---|
| 203 | chown $owner:$group $userdev 2>/dev/null || {
|
|---|
| 204 | rm -f $dev 2>/dev/null
|
|---|
| 205 | rm -f $userdev 2>/dev/null
|
|---|
| 206 | rmmod vboxguest 2>/dev/null
|
|---|
| 207 | fail "Cannot change owner $owner:$group for device $userdev"
|
|---|
| 208 | }
|
|---|
| 209 | fi
|
|---|
| 210 | fi
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | start()
|
|---|
| 214 | {
|
|---|
| 215 | begin "Starting."
|
|---|
| 216 | # If we got this far assume that the slow set-up has been done.
|
|---|
| 217 | QUICKSETUP=yes
|
|---|
| 218 | if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
|
|---|
| 219 | uname -r | grep -q -E '^2\.6|^3|^4' 2>/dev/null &&
|
|---|
| 220 | ps -A -o comm | grep -q '/*udevd$' 2>/dev/null ||
|
|---|
| 221 | no_udev=1
|
|---|
| 222 | running_vboxguest || {
|
|---|
| 223 | rm -f $dev || {
|
|---|
| 224 | fail "Cannot remove $dev"
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | rm -f $userdev || {
|
|---|
| 228 | fail "Cannot remove $userdev"
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | $MODPROBE vboxguest >/dev/null 2>&1 || {
|
|---|
| 232 | setup
|
|---|
| 233 | $MODPROBE vboxguest >/dev/null 2>&1 ||
|
|---|
| 234 | fail "modprobe vboxguest failed"
|
|---|
| 235 | }
|
|---|
| 236 | case "$no_udev" in 1)
|
|---|
| 237 | sleep .5;;
|
|---|
| 238 | esac
|
|---|
| 239 | }
|
|---|
| 240 | case "$no_udev" in 1)
|
|---|
| 241 | do_vboxguest_non_udev;;
|
|---|
| 242 | esac
|
|---|
| 243 |
|
|---|
| 244 | running_vboxsf || {
|
|---|
| 245 | $MODPROBE vboxsf > /dev/null 2>&1 || {
|
|---|
| 246 | if dmesg | grep "VbglR0SfConnect failed" > /dev/null 2>&1; then
|
|---|
| 247 | info "Unable to start shared folders support. Make sure that your VirtualBox build supports this feature."
|
|---|
| 248 | else
|
|---|
| 249 | info "modprobe vboxsf failed"
|
|---|
| 250 | fi
|
|---|
| 251 | }
|
|---|
| 252 | }
|
|---|
| 253 | fi # INSTALL_NO_MODULE_BUILDS
|
|---|
| 254 |
|
|---|
| 255 | # Put the X.Org driver in place. This is harmless if it is not needed.
|
|---|
| 256 | log "Dons fix."
|
|---|
| 257 | "${INSTALL_DIR}/init/vboxadd-x11" setup 2>> "${LOG}"
|
|---|
| 258 | # Install the guest OpenGL drivers. For now we don't support
|
|---|
| 259 | # multi-architecture installations
|
|---|
| 260 | rm -f /etc/ld.so.conf.d/00vboxvideo.conf
|
|---|
| 261 | rm -Rf /var/lib/VBoxGuestAdditions/lib
|
|---|
| 262 | if /usr/bin/VBoxClient --check3d 2>/dev/null; then
|
|---|
| 263 | mkdir -p /var/lib/VBoxGuestAdditions/lib
|
|---|
| 264 | ln -sf "${INSTALL_DIR}/lib/VBoxOGL.so" /var/lib/VBoxGuestAdditions/lib/libGL.so.1
|
|---|
| 265 | # SELinux for the OpenGL libraries, so that gdm can load them during the
|
|---|
| 266 | # acceleration support check. This prevents an "Oh no, something has gone
|
|---|
| 267 | # wrong!" error when starting EL7 guests.
|
|---|
| 268 | if test -e /etc/selinux/config; then
|
|---|
| 269 | if command -v semanage > /dev/null; then
|
|---|
| 270 | semanage fcontext -a -t lib_t "/var/lib/VBoxGuestAdditions/lib/libGL.so.1"
|
|---|
| 271 | fi
|
|---|
| 272 | chcon -h -t lib_t "/var/lib/VBoxGuestAdditions/lib/libGL.so.1"
|
|---|
| 273 | fi
|
|---|
| 274 | echo "/var/lib/VBoxGuestAdditions/lib" > /etc/ld.so.conf.d/00vboxvideo.conf
|
|---|
| 275 | fi
|
|---|
| 276 | ldconfig
|
|---|
| 277 |
|
|---|
| 278 | # Mount all shared folders from /etc/fstab. Normally this is done by some
|
|---|
| 279 | # other startup script but this requires the vboxdrv kernel module loaded.
|
|---|
| 280 | # This isn't necessary anymore as the vboxsf module is autoloaded.
|
|---|
| 281 | # mount -a -t vboxsf
|
|---|
| 282 |
|
|---|
| 283 | return 0
|
|---|
| 284 | }
|
|---|
| 285 |
|
|---|
| 286 | stop()
|
|---|
| 287 | {
|
|---|
| 288 | begin "Stopping."
|
|---|
| 289 | if test -r /etc/ld.so.conf.d/00vboxvideo.conf; then
|
|---|
| 290 | rm /etc/ld.so.conf.d/00vboxvideo.conf
|
|---|
| 291 | ldconfig
|
|---|
| 292 | fi
|
|---|
| 293 | if ! umount -a -t vboxsf 2>/dev/null; then
|
|---|
| 294 | fail "Cannot unmount vboxsf folders"
|
|---|
| 295 | fi
|
|---|
| 296 | test -n "${INSTALL_NO_MODULE_BUILDS}" ||
|
|---|
| 297 | info "You may need to restart your guest system to finish removing the guest drivers."
|
|---|
| 298 | return 0
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | restart()
|
|---|
| 302 | {
|
|---|
| 303 | stop && start
|
|---|
| 304 | return 0
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | # Remove any existing VirtualBox guest kernel modules from the disk, but not
|
|---|
| 308 | # from the kernel as they may still be in use
|
|---|
| 309 | cleanup_modules()
|
|---|
| 310 | {
|
|---|
| 311 | log "Removing existing VirtualBox kernel modules."
|
|---|
| 312 | for i in ${OLDMODULES}; do
|
|---|
| 313 | # We no longer support DKMS, remove any leftovers.
|
|---|
| 314 | rm -rf "/var/lib/dkms/${i}"*
|
|---|
| 315 | # And remove old modules.
|
|---|
| 316 | rm -f /lib/modules/*/misc/"${i}"*
|
|---|
| 317 | done
|
|---|
| 318 | # Remove leftover module folders.
|
|---|
| 319 | for i in /lib/modules/*/misc; do
|
|---|
| 320 | test -d "${i}" && rmdir -p "${i}" 2>/dev/null
|
|---|
| 321 | done
|
|---|
| 322 | rm -f /etc/depmod.d/vboxvideo-upstream.conf
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | # Build and install the VirtualBox guest kernel modules
|
|---|
| 326 | setup_modules()
|
|---|
| 327 | {
|
|---|
| 328 | # don't stop the old modules here -- they might be in use
|
|---|
| 329 | test -z "${QUICKSETUP}" && cleanup_modules
|
|---|
| 330 | # This does not work for 2.4 series kernels. How sad.
|
|---|
| 331 | test -n "${QUICKSETUP}" && test -f "${MODULE_DIR}/vboxguest.ko" && return 0
|
|---|
| 332 | info "Building the VirtualBox Guest Additions kernel modules."
|
|---|
| 333 |
|
|---|
| 334 | # We are allowed to do ">> $LOG" after we have called "log()" once.
|
|---|
| 335 | log "Building the main Guest Additions module."
|
|---|
| 336 | if ! $BUILDINTMP \
|
|---|
| 337 | --save-module-symvers /tmp/vboxguest-Module.symvers \
|
|---|
| 338 | --module-source $MODULE_SRC/vboxguest \
|
|---|
| 339 | --no-print-directory install >> $LOG 2>&1; then
|
|---|
| 340 | # If check_module_dependencies.sh fails it prints a message itself.
|
|---|
| 341 | "${INSTALL_DIR}"/other/check_module_dependencies.sh 2>&1 &&
|
|---|
| 342 | info "Look at $LOG to find out what went wrong"
|
|---|
| 343 | return 0
|
|---|
| 344 | fi
|
|---|
| 345 | log "Building the shared folder support module"
|
|---|
| 346 | if ! $BUILDINTMP \
|
|---|
| 347 | --use-module-symvers /tmp/vboxguest-Module.symvers \
|
|---|
| 348 | --module-source $MODULE_SRC/vboxsf \
|
|---|
| 349 | --no-print-directory install >> $LOG 2>&1; then
|
|---|
| 350 | info "Look at $LOG to find out what went wrong"
|
|---|
| 351 | return 0
|
|---|
| 352 | fi
|
|---|
| 353 | log "Building the graphics driver module"
|
|---|
| 354 | if ! $BUILDINTMP \
|
|---|
| 355 | --use-module-symvers /tmp/vboxguest-Module.symvers \
|
|---|
| 356 | --module-source $MODULE_SRC/vboxvideo \
|
|---|
| 357 | --no-print-directory install >> $LOG 2>&1; then
|
|---|
| 358 | info "Look at $LOG to find out what went wrong"
|
|---|
| 359 | fi
|
|---|
| 360 | [ -d /etc/depmod.d ] || mkdir /etc/depmod.d
|
|---|
| 361 | echo "override vboxguest * misc" > /etc/depmod.d/vboxvideo-upstream.conf
|
|---|
| 362 | echo "override vboxsf * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
|
|---|
| 363 | echo "override vboxvideo * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
|
|---|
| 364 | depmod
|
|---|
| 365 | return 0
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | create_vbox_user()
|
|---|
| 369 | {
|
|---|
| 370 | log "Creating user for the Guest Additions."
|
|---|
| 371 | # This is the LSB version of useradd and should work on recent
|
|---|
| 372 | # distributions
|
|---|
| 373 | useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
|
|---|
| 374 | # And for the others, we choose a UID ourselves
|
|---|
| 375 | useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
|
|---|
| 376 |
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | create_udev_rule()
|
|---|
| 380 | {
|
|---|
| 381 | # Create udev description file
|
|---|
| 382 | if [ -d /etc/udev/rules.d ]; then
|
|---|
| 383 | log "Creating udev rule for the Guest Additions kernel module."
|
|---|
| 384 | udev_call=""
|
|---|
| 385 | udev_app=`which udevadm 2> /dev/null`
|
|---|
| 386 | if [ $? -eq 0 ]; then
|
|---|
| 387 | udev_call="${udev_app} version 2> /dev/null"
|
|---|
| 388 | else
|
|---|
| 389 | udev_app=`which udevinfo 2> /dev/null`
|
|---|
| 390 | if [ $? -eq 0 ]; then
|
|---|
| 391 | udev_call="${udev_app} -V 2> /dev/null"
|
|---|
| 392 | fi
|
|---|
| 393 | fi
|
|---|
| 394 | udev_fix="="
|
|---|
| 395 | if [ "${udev_call}" != "" ]; then
|
|---|
| 396 | udev_out=`${udev_call}`
|
|---|
| 397 | udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
|
|---|
| 398 | if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
|
|---|
| 399 | udev_fix=""
|
|---|
| 400 | fi
|
|---|
| 401 | fi
|
|---|
| 402 | ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
|
|---|
| 403 | echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
|
|---|
| 404 | echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
|
|---|
| 405 | fi
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | create_module_rebuild_script()
|
|---|
| 409 | {
|
|---|
| 410 | # And a post-installation script for rebuilding modules when a new kernel
|
|---|
| 411 | # is installed.
|
|---|
| 412 | mkdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d
|
|---|
| 413 | cat << EOF > /etc/kernel/postinst.d/vboxadd
|
|---|
| 414 | #!/bin/sh
|
|---|
| 415 | test -d "/lib/modules/\${1}/build" || exit 0
|
|---|
| 416 | KERN_VER="\${1}" /sbin/rcvboxadd quicksetup
|
|---|
| 417 | exit 0
|
|---|
| 418 | EOF
|
|---|
| 419 | cat << EOF > /etc/kernel/prerm.d/vboxadd
|
|---|
| 420 | #!/bin/sh
|
|---|
| 421 | for i in ${OLDMODULES}; do rm -f /lib/modules/"\${1}"/misc/"\${i}".ko; done
|
|---|
| 422 | rmdir -p /lib/modules/"\$1"/misc 2>/dev/null
|
|---|
| 423 | exit 0
|
|---|
| 424 | EOF
|
|---|
| 425 | chmod 0755 /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
|
|---|
| 426 | }
|
|---|
| 427 |
|
|---|
| 428 | shared_folder_setup()
|
|---|
| 429 | {
|
|---|
| 430 | # Add a group "vboxsf" for Shared Folders access
|
|---|
| 431 | # All users which want to access the auto-mounted Shared Folders have to
|
|---|
| 432 | # be added to this group.
|
|---|
| 433 | groupadd -r -f vboxsf >/dev/null 2>&1
|
|---|
| 434 |
|
|---|
| 435 | # Put the mount.vboxsf mount helper in the right place.
|
|---|
| 436 | ## @todo It would be nicer if the kernel module just parsed parameters
|
|---|
| 437 | # itself instead of needing a separate binary to do that.
|
|---|
| 438 | ln -sf "${INSTALL_DIR}/other/mount.vboxsf" /sbin
|
|---|
| 439 | # SELinux security context for the mount helper.
|
|---|
| 440 | if test -e /etc/selinux/config; then
|
|---|
| 441 | # This is correct. semanage maps this to the real path, and it aborts
|
|---|
| 442 | # with an error, telling you what you should have typed, if you specify
|
|---|
| 443 | # the real path. The "chcon" is there as a back-up for old guests.
|
|---|
| 444 | command -v semanage > /dev/null &&
|
|---|
| 445 | semanage fcontext -a -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
|
|---|
| 446 | chcon -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
|
|---|
| 447 | fi
|
|---|
| 448 | }
|
|---|
| 449 |
|
|---|
| 450 | # setup_script
|
|---|
| 451 | setup()
|
|---|
| 452 | {
|
|---|
| 453 | export BUILD_TYPE
|
|---|
| 454 | export USERNAME
|
|---|
| 455 |
|
|---|
| 456 | MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
|
|---|
| 457 | BUILDINTMP="$MODULE_SRC/build_in_tmp"
|
|---|
| 458 | chcon -t bin_t "$BUILDINTMP" > /dev/null 2>&1
|
|---|
| 459 |
|
|---|
| 460 | test -z "${INSTALL_NO_MODULE_BUILDS}" && setup_modules
|
|---|
| 461 | create_vbox_user
|
|---|
| 462 | create_udev_rule
|
|---|
| 463 | test -z "${INSTALL_NO_MODULE_BUILDS}" && create_module_rebuild_script
|
|---|
| 464 | test -n "${QUICKSETUP}" && return 0
|
|---|
| 465 | shared_folder_setup
|
|---|
| 466 | if running_vboxguest || running_vboxadd; then
|
|---|
| 467 | info "Running kernel modules will not be replaced until the system is restarted"
|
|---|
| 468 | fi
|
|---|
| 469 | return 0
|
|---|
| 470 | }
|
|---|
| 471 |
|
|---|
| 472 | # cleanup_script
|
|---|
| 473 | cleanup()
|
|---|
| 474 | {
|
|---|
| 475 | if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
|
|---|
| 476 | # Delete old versions of VBox modules.
|
|---|
| 477 | cleanup_modules
|
|---|
| 478 | depmod
|
|---|
| 479 |
|
|---|
| 480 | # Remove old module sources
|
|---|
| 481 | for i in $OLDMODULES; do
|
|---|
| 482 | rm -rf /usr/src/$i-*
|
|---|
| 483 | done
|
|---|
| 484 | fi
|
|---|
| 485 |
|
|---|
| 486 | # Clean-up X11-related bits
|
|---|
| 487 | "${INSTALL_DIR}/init/vboxadd-x11" cleanup 2>> "${LOG}"
|
|---|
| 488 |
|
|---|
| 489 | # Remove other files
|
|---|
| 490 | rm /sbin/mount.vboxsf 2>/dev/null
|
|---|
| 491 | if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
|
|---|
| 492 | rm -f /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
|
|---|
| 493 | rmdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d 2>/dev/null
|
|---|
| 494 | fi
|
|---|
| 495 | rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
|
|---|
| 496 | }
|
|---|
| 497 |
|
|---|
| 498 | dmnstatus()
|
|---|
| 499 | {
|
|---|
| 500 | if running_vboxguest; then
|
|---|
| 501 | echo "The VirtualBox Additions are currently running."
|
|---|
| 502 | else
|
|---|
| 503 | echo "The VirtualBox Additions are not currently running."
|
|---|
| 504 | fi
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 | case "$2" in quiet)
|
|---|
| 508 | QUIET=yes;;
|
|---|
| 509 | esac
|
|---|
| 510 | case "$1" in
|
|---|
| 511 | start)
|
|---|
| 512 | start
|
|---|
| 513 | ;;
|
|---|
| 514 | stop)
|
|---|
| 515 | stop
|
|---|
| 516 | ;;
|
|---|
| 517 | restart)
|
|---|
| 518 | restart
|
|---|
| 519 | ;;
|
|---|
| 520 | setup)
|
|---|
| 521 | setup
|
|---|
| 522 | start
|
|---|
| 523 | ;;
|
|---|
| 524 | quicksetup)
|
|---|
| 525 | QUICKSETUP=yes
|
|---|
| 526 | setup
|
|---|
| 527 | ;;
|
|---|
| 528 | cleanup)
|
|---|
| 529 | cleanup
|
|---|
| 530 | ;;
|
|---|
| 531 | status)
|
|---|
| 532 | dmnstatus
|
|---|
| 533 | ;;
|
|---|
| 534 | *)
|
|---|
| 535 | echo "Usage: $0 {start|stop|restart|status|setup|quicksetup|cleanup} [quiet]"
|
|---|
| 536 | exit 1
|
|---|
| 537 | esac
|
|---|
| 538 |
|
|---|
| 539 | exit
|
|---|