VirtualBox

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

Last change on this file since 107044 was 106061, checked in by vboxsync, 2 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
Line 
1#!/bin/bash
2# $Id: load.sh 106061 2024-09-16 14:03:52Z vboxsync $
3## @file
4# For development.
5#
6
7#
8# Copyright (C) 2006-2024 Oracle and/or its affiliates.
9#
10# This file is part of VirtualBox base platform packages, as
11# available from https://www.virtualbox.org.
12#
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# The contents of this file may alternatively be used under the terms
27# of the Common Development and Distribution License Version 1.0
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
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#
35# SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
36#
37
38XNU_VERSION=`LC_ALL=C uname -r | LC_ALL=C cut -d . -f 1`
39DRVNAME="VBoxDrv.kext"
40BUNDLE="org.virtualbox.kext.VBoxDrv"
41
42DIR=`dirname "$0"`
43DIR=`cd "$DIR" && pwd`
44DIR="$DIR/$DRVNAME"
45if [ ! -d "$DIR" ]; then
46 echo "Cannot find $DIR or it's not a directory..."
47 exit 1;
48fi
49if [ -n "$*" ]; then
50 OPTS="$*"
51else
52 OPTS="-t"
53fi
54
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
67
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
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
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
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
119trap "sudo chown -R `whoami` $DIR; exit 1" INT
120trap "sudo chown -R `whoami` $DIR; exit 1" ERR
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.
123if sudo chown -R root:wheel "$DIR"; then
124 OWNER=`/usr/bin/stat -f "%u" "$DIR"`
125else
126 OWNER=1000
127fi
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/"
140 sudo cp -Rp "$DIR" "$TMP_DIR/"
141 DIR="$TMP_DIR/$DRVNAME"
142
143 # retry
144 sudo chown -R root:wheel "$DIR"
145fi
146sudo chmod -R o-rwx "$DIR"
147sync
148echo "load.sh: loading $DIR..."
149
150if [ "$XNU_VERSION" -ge "10" ]; then
151 echo "${SCRIPT_NAME}.sh: loading $DIR... (kextutil $OPTS \"$DIR\")"
152 sudo kextutil $OPTS "$DIR"
153else
154 sudo kextload $OPTS "$DIR"
155fi
156sync
157sudo chown -R `whoami` "$DIR"
158#sudo chmod 666 /dev/vboxdrv
159kextstat | grep org.virtualbox.kext
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
164
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