1 | #!/bin/bash
|
---|
2 | # $Id: load.sh 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # For development.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2006-2023 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 |
|
---|
38 | XNU_VERSION=`LC_ALL=C uname -r | LC_ALL=C cut -d . -f 1`
|
---|
39 | DRVNAME="VBoxDrv.kext"
|
---|
40 | BUNDLE="org.virtualbox.kext.VBoxDrv"
|
---|
41 |
|
---|
42 | DIR=`dirname "$0"`
|
---|
43 | DIR=`cd "$DIR" && pwd`
|
---|
44 | DIR="$DIR/$DRVNAME"
|
---|
45 | if [ ! -d "$DIR" ]; then
|
---|
46 | echo "Cannot find $DIR or it's not a directory..."
|
---|
47 | exit 1;
|
---|
48 | fi
|
---|
49 | if [ -n "$*" ]; then
|
---|
50 | OPTS="$*"
|
---|
51 | else
|
---|
52 | OPTS="-t"
|
---|
53 | fi
|
---|
54 |
|
---|
55 | # Make sure VBoxUSB is unloaded as it might be using symbols from us.
|
---|
56 | LOADED=`kextstat -b org.virtualbox.kext.VBoxUSB -l`
|
---|
57 | if 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"
|
---|
66 | fi
|
---|
67 |
|
---|
68 | # Make sure VBoxNetFlt is unloaded as it might be using symbols from us.
|
---|
69 | LOADED=`kextstat -b org.virtualbox.kext.VBoxNetFlt -l`
|
---|
70 | if 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"
|
---|
79 | fi
|
---|
80 |
|
---|
81 | # Make sure VBoxNetAdp is unloaded as it might be using symbols from us.
|
---|
82 | LOADED=`kextstat -b org.virtualbox.kext.VBoxNetAdp -l`
|
---|
83 | if 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"
|
---|
92 | fi
|
---|
93 |
|
---|
94 | # Try unload any existing instance first.
|
---|
95 | LOADED=`kextstat -b $BUNDLE -l`
|
---|
96 | if 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"
|
---|
105 | fi
|
---|
106 |
|
---|
107 | set -e
|
---|
108 |
|
---|
109 | # Copy the .kext to the symbols directory and tweak the kextload options.
|
---|
110 | if 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
|
---|
117 | fi
|
---|
118 |
|
---|
119 | trap "sudo chown -R `whoami` $DIR; exit 1" INT
|
---|
120 | trap "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.
|
---|
123 | if sudo chown -R root:wheel "$DIR"; then
|
---|
124 | OWNER=`/usr/bin/stat -f "%u" "$DIR"`
|
---|
125 | else
|
---|
126 | OWNER=1000
|
---|
127 | fi
|
---|
128 | if 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"
|
---|
145 | fi
|
---|
146 | sudo chmod -R o-rwx "$DIR"
|
---|
147 | sync
|
---|
148 | echo "load.sh: loading $DIR..."
|
---|
149 |
|
---|
150 | if [ "$XNU_VERSION" -ge "10" ]; then
|
---|
151 | echo "${SCRIPT_NAME}.sh: loading $DIR... (kextutil $OPTS \"$DIR\")"
|
---|
152 | sudo kextutil $OPTS "$DIR"
|
---|
153 | else
|
---|
154 | sudo kextload $OPTS "$DIR"
|
---|
155 | fi
|
---|
156 | sync
|
---|
157 | sudo chown -R `whoami` "$DIR"
|
---|
158 | #sudo chmod 666 /dev/vboxdrv
|
---|
159 | kextstat | grep org.virtualbox.kext
|
---|
160 | if [ -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
|
---|
163 | fi
|
---|
164 |
|
---|