1 | #!/bin/bash
|
---|
2 | ## @file
|
---|
3 | # For development.
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
8 | #
|
---|
9 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | # available from http://www.virtualbox.org. This file is free software;
|
---|
11 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | # General Public License (GPL) as published by the Free Software
|
---|
13 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | #
|
---|
17 | # The contents of this file may alternatively be used under the terms
|
---|
18 | # of the Common Development and Distribution License Version 1.0
|
---|
19 | # (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | # VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | # CDDL are applicable instead of those of the GPL.
|
---|
22 | #
|
---|
23 | # You may elect to license modified versions of this file under the
|
---|
24 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | #
|
---|
26 | # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | # Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | # additional information or have any questions.
|
---|
29 | #
|
---|
30 |
|
---|
31 | XNU_VERSION=`LC_ALL=C uname -r | LC_ALL=C cut -d . -f 1`
|
---|
32 | if [ "$XNU_VERSION" -ge "9" ]; then
|
---|
33 | DRVNAME="VBoxDrv.kext"
|
---|
34 | else
|
---|
35 | DRVNAME="VBoxDrvTiger.kext"
|
---|
36 | fi
|
---|
37 | BUNDLE="org.virtualbox.kext.VBoxDrv"
|
---|
38 |
|
---|
39 | DIR=`dirname "$0"`
|
---|
40 | DIR=`cd "$DIR" && pwd`
|
---|
41 | DIR="$DIR/$DRVNAME"
|
---|
42 | if [ ! -d "$DIR" ]; then
|
---|
43 | echo "Cannot find $DIR or it's not a directory..."
|
---|
44 | exit 1;
|
---|
45 | fi
|
---|
46 | if [ -n "$*" ]; then
|
---|
47 | OPTS="$*"
|
---|
48 | else
|
---|
49 | OPTS="-t"
|
---|
50 | fi
|
---|
51 |
|
---|
52 | # Make sure VBoxUSB is unloaded as it might be using symbols from us.
|
---|
53 | LOADED=`kextstat -b org.virtualbox.kext.VBoxUSB -l`
|
---|
54 | if test -n "$LOADED"; then
|
---|
55 | echo "load.sh: Unloading org.virtualbox.kext.VBoxUSB..."
|
---|
56 | sudo kextunload -v 6 -b org.virtualbox.kext.VBoxUSB
|
---|
57 | LOADED=`kextstat -b org.virtualbox.kext.VBoxUSB -l`
|
---|
58 | if test -n "$LOADED"; then
|
---|
59 | echo "load.sh: failed to unload org.virtualbox.kext.VBoxUSB, see above..."
|
---|
60 | exit 1;
|
---|
61 | fi
|
---|
62 | echo "load.sh: Successfully unloaded org.virtualbox.kext.VBoxUSB"
|
---|
63 | fi
|
---|
64 |
|
---|
65 | # Make sure VBoxNetFlt is unloaded as it might be using symbols from us.
|
---|
66 | LOADED=`kextstat -b org.virtualbox.kext.VBoxNetFlt -l`
|
---|
67 | if test -n "$LOADED"; then
|
---|
68 | echo "load.sh: Unloading org.virtualbox.kext.VBoxNetFlt..."
|
---|
69 | sudo kextunload -v 6 -b org.virtualbox.kext.VBoxNetFlt
|
---|
70 | LOADED=`kextstat -b org.virtualbox.kext.VBoxNetFlt -l`
|
---|
71 | if test -n "$LOADED"; then
|
---|
72 | echo "load.sh: failed to unload org.virtualbox.kext.VBoxNetFlt, see above..."
|
---|
73 | exit 1;
|
---|
74 | fi
|
---|
75 | echo "load.sh: Successfully unloaded org.virtualbox.kext.VBoxNetFlt"
|
---|
76 | fi
|
---|
77 |
|
---|
78 | # Make sure VBoxNetAdp is unloaded as it might be using symbols from us.
|
---|
79 | LOADED=`kextstat -b org.virtualbox.kext.VBoxNetAdp -l`
|
---|
80 | if test -n "$LOADED"; then
|
---|
81 | echo "load.sh: Unloading org.virtualbox.kext.VBoxNetAdp..."
|
---|
82 | sudo kextunload -v 6 -b org.virtualbox.kext.VBoxNetAdp
|
---|
83 | LOADED=`kextstat -b org.virtualbox.kext.VBoxNetAdp -l`
|
---|
84 | if test -n "$LOADED"; then
|
---|
85 | echo "load.sh: failed to unload org.virtualbox.kext.VBoxNetAdp, see above..."
|
---|
86 | exit 1;
|
---|
87 | fi
|
---|
88 | echo "load.sh: Successfully unloaded org.virtualbox.kext.VBoxNetAdp"
|
---|
89 | fi
|
---|
90 |
|
---|
91 | # Try unload any existing instance first.
|
---|
92 | LOADED=`kextstat -b $BUNDLE -l`
|
---|
93 | if test -n "$LOADED"; then
|
---|
94 | echo "load.sh: Unloading $BUNDLE..."
|
---|
95 | sudo kextunload -v 6 -b $BUNDLE
|
---|
96 | LOADED=`kextstat -b $BUNDLE -l`
|
---|
97 | if test -n "$LOADED"; then
|
---|
98 | echo "load.sh: failed to unload $BUNDLE, see above..."
|
---|
99 | exit 1;
|
---|
100 | fi
|
---|
101 | echo "load.sh: Successfully unloaded $BUNDLE"
|
---|
102 | fi
|
---|
103 |
|
---|
104 | set -e
|
---|
105 |
|
---|
106 | # Copy the .kext to the symbols directory and tweak the kextload options.
|
---|
107 | if test -n "$VBOX_DARWIN_SYMS"; then
|
---|
108 | echo "load.sh: copying the extension the symbol area..."
|
---|
109 | rm -Rf "$VBOX_DARWIN_SYMS/$DRVNAME"
|
---|
110 | mkdir -p "$VBOX_DARWIN_SYMS"
|
---|
111 | cp -R "$DIR" "$VBOX_DARWIN_SYMS/"
|
---|
112 | OPTS="$OPTS -s $VBOX_DARWIN_SYMS/ "
|
---|
113 | sync
|
---|
114 | fi
|
---|
115 |
|
---|
116 | trap "sudo chown -R `whoami` $DIR; exit 1" INT
|
---|
117 | # On smbfs, this might succeed just fine but make no actual changes,
|
---|
118 | # so we might have to temporarily copy the driver to a local directory.
|
---|
119 | sudo chown -R root:wheel "$DIR"
|
---|
120 | OWNER=`/usr/bin/stat -f "%u" "$DIR"`
|
---|
121 | if test "$OWNER" -ne 0; then
|
---|
122 | TMP_DIR=/tmp/loaddrv.tmp
|
---|
123 | echo "load.sh: chown didn't work on $DIR, using temp location $TMP_DIR/$DRVNAME"
|
---|
124 |
|
---|
125 | # clean up first (no sudo rm)
|
---|
126 | if test -e "$TMP_DIR"; then
|
---|
127 | sudo chown -R `whoami` "$TMP_DIR"
|
---|
128 | rm -Rf "$TMP_DIR"
|
---|
129 | fi
|
---|
130 |
|
---|
131 | # make a copy and switch over DIR
|
---|
132 | mkdir -p "$TMP_DIR/"
|
---|
133 | sudo cp -Rp "$DIR" "$TMP_DIR/"
|
---|
134 | DIR="$TMP_DIR/$DRVNAME"
|
---|
135 |
|
---|
136 | # retry
|
---|
137 | sudo chown -R root:wheel "$DIR"
|
---|
138 | fi
|
---|
139 | sudo chmod -R o-rwx "$DIR"
|
---|
140 | sync
|
---|
141 | echo "load.sh: loading $DIR..."
|
---|
142 |
|
---|
143 | if [ "$XNU_VERSION" -ge "10" ]; then
|
---|
144 | echo "${SCRIPT_NAME}.sh: loading $DIR... (kextutil $OPTS \"$DIR\")"
|
---|
145 | sudo kextutil $OPTS "$DIR"
|
---|
146 | else
|
---|
147 | sudo kextload $OPTS "$DIR"
|
---|
148 | fi
|
---|
149 | sync
|
---|
150 | sudo chown -R `whoami` "$DIR"
|
---|
151 | #sudo chmod 666 /dev/vboxdrv
|
---|
152 | kextstat | grep org.virtualbox.kext
|
---|
153 |
|
---|