VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/darwin/load.sh

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
RevLine 
[195]1#!/bin/bash
[22077]2# $Id: load.sh 98103 2023-01-17 14:15:46Z vboxsync $
[8092]3## @file
4# For development.
5#
[195]6
7#
[98103]8# Copyright (C) 2006-2023 Oracle and/or its affiliates.
[5999]9#
[96407]10# This file is part of VirtualBox base platform packages, as
11# available from https://www.virtualbox.org.
[5999]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#
[5999]26# The contents of this file may alternatively be used under the terms
27# of the Common Development and Distribution License Version 1.0
[96407]28# (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
29# in the VirtualBox distribution, in which case the provisions of the
[5999]30# CDDL are applicable instead of those of the GPL.
31#
32# You may elect to license modified versions of this file under the
33# terms and conditions of either the GPL or the CDDL or both.
34#
[96407]35# SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
36#
[195]37
[15130]38XNU_VERSION=`LC_ALL=C uname -r | LC_ALL=C cut -d . -f 1`
[29844]39DRVNAME="VBoxDrv.kext"
[8092]40BUNDLE="org.virtualbox.kext.VBoxDrv"
[4480]41
[8092]42DIR=`dirname "$0"`
43DIR=`cd "$DIR" && pwd`
44DIR="$DIR/$DRVNAME"
[195]45if [ ! -d "$DIR" ]; then
46 echo "Cannot find $DIR or it's not a directory..."
47 exit 1;
48fi
[216]49if [ -n "$*" ]; then
50 OPTS="$*"
51else
52 OPTS="-t"
53fi
[195]54
[8102]55# Make sure VBoxUSB is unloaded as it might be using symbols from us.
56LOADED=`kextstat -b org.virtualbox.kext.VBoxUSB -l`
57if test -n "$LOADED"; then
58 echo "load.sh: Unloading org.virtualbox.kext.VBoxUSB..."
59 sudo kextunload -v 6 -b org.virtualbox.kext.VBoxUSB
60 LOADED=`kextstat -b org.virtualbox.kext.VBoxUSB -l`
61 if test -n "$LOADED"; then
62 echo "load.sh: failed to unload org.virtualbox.kext.VBoxUSB, see above..."
63 exit 1;
64 fi
65 echo "load.sh: Successfully unloaded org.virtualbox.kext.VBoxUSB"
66fi
[8092]67
[14495]68# Make sure VBoxNetFlt is unloaded as it might be using symbols from us.
69LOADED=`kextstat -b org.virtualbox.kext.VBoxNetFlt -l`
70if test -n "$LOADED"; then
71 echo "load.sh: Unloading org.virtualbox.kext.VBoxNetFlt..."
72 sudo kextunload -v 6 -b org.virtualbox.kext.VBoxNetFlt
73 LOADED=`kextstat -b org.virtualbox.kext.VBoxNetFlt -l`
74 if test -n "$LOADED"; then
75 echo "load.sh: failed to unload org.virtualbox.kext.VBoxNetFlt, see above..."
76 exit 1;
77 fi
78 echo "load.sh: Successfully unloaded org.virtualbox.kext.VBoxNetFlt"
79fi
80
[18182]81# Make sure VBoxNetAdp is unloaded as it might be using symbols from us.
82LOADED=`kextstat -b org.virtualbox.kext.VBoxNetAdp -l`
83if test -n "$LOADED"; then
84 echo "load.sh: Unloading org.virtualbox.kext.VBoxNetAdp..."
85 sudo kextunload -v 6 -b org.virtualbox.kext.VBoxNetAdp
86 LOADED=`kextstat -b org.virtualbox.kext.VBoxNetAdp -l`
87 if test -n "$LOADED"; then
88 echo "load.sh: failed to unload org.virtualbox.kext.VBoxNetAdp, see above..."
89 exit 1;
90 fi
91 echo "load.sh: Successfully unloaded org.virtualbox.kext.VBoxNetAdp"
92fi
93
[8092]94# Try unload any existing instance first.
95LOADED=`kextstat -b $BUNDLE -l`
96if test -n "$LOADED"; then
97 echo "load.sh: Unloading $BUNDLE..."
98 sudo kextunload -v 6 -b $BUNDLE
99 LOADED=`kextstat -b $BUNDLE -l`
100 if test -n "$LOADED"; then
101 echo "load.sh: failed to unload $BUNDLE, see above..."
102 exit 1;
103 fi
104 echo "load.sh: Successfully unloaded $BUNDLE"
105fi
106
107set -e
[10712]108
109# Copy the .kext to the symbols directory and tweak the kextload options.
110if test -n "$VBOX_DARWIN_SYMS"; then
111 echo "load.sh: copying the extension the symbol area..."
112 rm -Rf "$VBOX_DARWIN_SYMS/$DRVNAME"
113 mkdir -p "$VBOX_DARWIN_SYMS"
114 cp -R "$DIR" "$VBOX_DARWIN_SYMS/"
115 OPTS="$OPTS -s $VBOX_DARWIN_SYMS/ "
116 sync
117fi
118
[8102]119trap "sudo chown -R `whoami` $DIR; exit 1" INT
[22066]120trap "sudo chown -R `whoami` $DIR; exit 1" ERR
[8092]121# On smbfs, this might succeed just fine but make no actual changes,
122# so we might have to temporarily copy the driver to a local directory.
[20527]123if sudo chown -R root:wheel "$DIR"; then
124 OWNER=`/usr/bin/stat -f "%u" "$DIR"`
125else
126 OWNER=1000
127fi
[8092]128if test "$OWNER" -ne 0; then
129 TMP_DIR=/tmp/loaddrv.tmp
130 echo "load.sh: chown didn't work on $DIR, using temp location $TMP_DIR/$DRVNAME"
131
132 # clean up first (no sudo rm)
133 if test -e "$TMP_DIR"; then
134 sudo chown -R `whoami` "$TMP_DIR"
135 rm -Rf "$TMP_DIR"
136 fi
137
138 # make a copy and switch over DIR
139 mkdir -p "$TMP_DIR/"
[14745]140 sudo cp -Rp "$DIR" "$TMP_DIR/"
[8092]141 DIR="$TMP_DIR/$DRVNAME"
142
143 # retry
144 sudo chown -R root:wheel "$DIR"
145fi
[195]146sudo chmod -R o-rwx "$DIR"
[216]147sync
[8092]148echo "load.sh: loading $DIR..."
[16719]149
150if [ "$XNU_VERSION" -ge "10" ]; then
[16754]151 echo "${SCRIPT_NAME}.sh: loading $DIR... (kextutil $OPTS \"$DIR\")"
[16719]152 sudo kextutil $OPTS "$DIR"
153else
154 sudo kextload $OPTS "$DIR"
155fi
[8092]156sync
[195]157sudo chown -R `whoami` "$DIR"
[8092]158#sudo chmod 666 /dev/vboxdrv
159kextstat | grep org.virtualbox.kext
[22066]160if [ -n "${VBOX_DARWIN_SYMS}" -a "$XNU_VERSION" -ge "10" ]; then
161 dsymutil -o "${VBOX_DARWIN_SYMS}/${DRVNAME}.dSYM" "${DIR}/Contents/MacOS/`basename -s .kext ${DRVNAME}`"
162 sync
163fi
[8092]164
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use