[31655] | 1 | #!/bin/sh
|
---|
[48924] | 2 | # $Id$
|
---|
| 3 | ## @file
|
---|
| 4 | # Reloads the new kernel extension at the end of installation.
|
---|
| 5 | #
|
---|
[31655] | 6 |
|
---|
| 7 | #
|
---|
[98103] | 8 | # Copyright (C) 2007-2023 Oracle and/or its affiliates.
|
---|
[31655] | 9 | #
|
---|
[96407] | 10 | # This file is part of VirtualBox base platform packages, as
|
---|
| 11 | # available from https://www.virtualbox.org.
|
---|
[31655] | 12 | #
|
---|
[96407] | 13 | # This program is free software; you can redistribute it and/or
|
---|
| 14 | # modify it under the terms of the GNU General Public License
|
---|
| 15 | # as published by the Free Software Foundation, in version 3 of the
|
---|
| 16 | # License.
|
---|
| 17 | #
|
---|
| 18 | # This program is distributed in the hope that it will be useful, but
|
---|
| 19 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 21 | # General Public License for more details.
|
---|
| 22 | #
|
---|
| 23 | # You should have received a copy of the GNU General Public License
|
---|
| 24 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 25 | #
|
---|
| 26 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
| 27 | #
|
---|
[31655] | 28 |
|
---|
| 29 | #
|
---|
[48928] | 30 | # Make sure the old startup items are gone.
|
---|
| 31 | #
|
---|
[69396] | 32 | if [ -d /Library/StartupItems/VirtualBox/ ]; then
|
---|
[48928] | 33 | rm -vf "/Library/StartupItems/VirtualBox/StartupParameters.plist"
|
---|
| 34 | rm -vf "/Library/StartupItems/VirtualBox/VirtualBox"
|
---|
| 35 | rm -vf "/Library/StartupItems/VirtualBox/Resources/English.lproj/Localizable.strings"
|
---|
| 36 | test -d "/Library/StartupItems/VirtualBox/Resources/English.lproj/" && rmdir "/Library/StartupItems/VirtualBox/Resources/English.lproj/"
|
---|
| 37 | test -d "/Library/StartupItems/VirtualBox/Resources/" && rmdir "/Library/StartupItems/VirtualBox/Resources/"
|
---|
| 38 | test -d "/Library/StartupItems/VirtualBox/" && rmdir "/Library/StartupItems/VirtualBox/"
|
---|
| 39 | fi
|
---|
| 40 |
|
---|
| 41 | #
|
---|
[49334] | 42 | # Make sure old kernel extensions are gone (moved to "/Library/Application Support/VirtualBox/" with 4.3).
|
---|
| 43 | #
|
---|
| 44 | rm -Rfv \
|
---|
| 45 | "/Library/Extensions/VBoxDrv.kext/" \
|
---|
| 46 | "/Library/Extensions/VBoxNetFlt.kext/" \
|
---|
| 47 | "/Library/Extensions/VBoxNetAdp.kext/" \
|
---|
| 48 | "/Library/Extensions/VBoxUSB.kext/" \
|
---|
| 49 | "/Library/Extensions/VBoxDrvTiger.kext/" \
|
---|
| 50 | "/Library/Extensions/VBoxUSBTiger.kext/"
|
---|
| 51 |
|
---|
| 52 | #
|
---|
[48928] | 53 | # Install the launchd script.
|
---|
| 54 | #
|
---|
[58281] | 55 | # Make sure "/Library/LaunchDaemons/ exists first as some uninstallers/users
|
---|
| 56 | # may be silly enough to remove it. We assume that /Library exists and will
|
---|
| 57 | # not try create it because it normally has extra ACLs.
|
---|
| 58 | #
|
---|
| 59 | if [ ! -e "/Library/LaunchDaemons/" ]; then
|
---|
| 60 | set -e
|
---|
| 61 | mkdir "/Library/LaunchDaemons"
|
---|
| 62 | chmod 755 "/Library/LaunchDaemons"
|
---|
| 63 | chown root:wheel "/Library/LaunchDaemons"
|
---|
| 64 | set +e
|
---|
| 65 | fi
|
---|
[48928] | 66 | rm -vf "/Library/LaunchDaemons/org.virtualbox.startup.plist"
|
---|
| 67 | set -e
|
---|
| 68 | ln -s "../Application Support/VirtualBox/LaunchDaemons/org.virtualbox.startup.plist" \
|
---|
| 69 | "/Library/LaunchDaemons/org.virtualbox.startup.plist"
|
---|
| 70 | set +e
|
---|
| 71 |
|
---|
| 72 | #
|
---|
[31655] | 73 | # Unload any old extension that might be loaded already (ignore failures).
|
---|
| 74 | #
|
---|
| 75 | sync
|
---|
| 76 | if kextstat -lb org.virtualbox.kext.VBoxNetAdp 2>&1 | grep -q org.virtualbox.kext.VBoxNetAdp; then
|
---|
| 77 | kextunload -m org.virtualbox.kext.VBoxNetAdp
|
---|
| 78 | fi
|
---|
| 79 | if kextstat -lb org.virtualbox.kext.VBoxNetFlt 2>&1 | grep -q org.virtualbox.kext.VBoxNetFlt; then
|
---|
| 80 | kextunload -m org.virtualbox.kext.VBoxNetFlt
|
---|
| 81 | fi
|
---|
| 82 | if kextstat -lb org.virtualbox.kext.VBoxUSB 2>&1 | grep -q org.virtualbox.kext.VBoxUSB; then
|
---|
| 83 | kextunload -m org.virtualbox.kext.VBoxUSB
|
---|
| 84 | fi
|
---|
| 85 | if kextstat -lb org.virtualbox.kext.VBoxDrv 2>&1 | grep -q org.virtualbox.kext.VBoxDrv; then
|
---|
| 86 | kextunload -m org.virtualbox.kext.VBoxDrv
|
---|
| 87 | fi
|
---|
| 88 |
|
---|
| 89 | #
|
---|
[86291] | 90 | # Load the extension, exit on first error except on BigSur onwards as an error
|
---|
| 91 | # is expected there and the user has to reboot.
|
---|
[31655] | 92 | #
|
---|
[92346] | 93 | MACOS_VERSION_MAJOR=$(sw_vers -productVersion | /usr/bin/sed -e 's/^\([0-9]*\).*$/\1/')
|
---|
[31655] | 94 | sync
|
---|
[92346] | 95 | if [[ ${MACOS_VERSION_MAJOR} -lt 11 ]]; then
|
---|
[86291] | 96 | set -e
|
---|
[86449] | 97 | kextload '/Library/Application Support/VirtualBox/VBoxDrv.kext'
|
---|
| 98 | kextload -d '/Library/Application Support/VirtualBox/VBoxDrv.kext' '/Library/Application Support/VirtualBox/VBoxNetFlt.kext'
|
---|
| 99 | kextload -d '/Library/Application Support/VirtualBox/VBoxDrv.kext' '/Library/Application Support/VirtualBox/VBoxNetAdp.kext'
|
---|
| 100 | else
|
---|
| 101 | VBOX_RC=0
|
---|
[86474] | 102 | if ! kmutil load -p '/Library/Application Support/VirtualBox/VBoxDrv.kext'; then
|
---|
[86449] | 103 | VBOX_RC=1
|
---|
| 104 | fi
|
---|
| 105 |
|
---|
[86474] | 106 | if ! kmutil load -p '/Library/Application Support/VirtualBox/VBoxNetFlt.kext'; then
|
---|
[86449] | 107 | VBOX_RC=1
|
---|
| 108 | fi
|
---|
| 109 |
|
---|
[86474] | 110 | if ! kmutil load -p '/Library/Application Support/VirtualBox/VBoxNetAdp.kext'; then
|
---|
[86449] | 111 | VBOX_RC=1
|
---|
| 112 | fi
|
---|
| 113 |
|
---|
| 114 | if [ $VBOX_RC -ne 1 ]; then
|
---|
| 115 | osascript -e 'display dialog "A reboot is required on macOS BigSur and onwards in order to be able to load the installed kernel extensions" buttons { "Ok" } with icon caution'
|
---|
| 116 | fi
|
---|
[86291] | 117 | fi
|
---|