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 | # Try unload any existing instance first.
|
---|
79 | LOADED=`kextstat -b $BUNDLE -l`
|
---|
80 | if test -n "$LOADED"; then
|
---|
81 | echo "load.sh: Unloading $BUNDLE..."
|
---|
82 | sudo kextunload -v 6 -b $BUNDLE
|
---|
83 | LOADED=`kextstat -b $BUNDLE -l`
|
---|
84 | if test -n "$LOADED"; then
|
---|
85 | echo "load.sh: failed to unload $BUNDLE, see above..."
|
---|
86 | exit 1;
|
---|
87 | fi
|
---|
88 | echo "load.sh: Successfully unloaded $BUNDLE"
|
---|
89 | fi
|
---|
90 |
|
---|
91 | set -e
|
---|
92 |
|
---|
93 | # Copy the .kext to the symbols directory and tweak the kextload options.
|
---|
94 | if test -n "$VBOX_DARWIN_SYMS"; then
|
---|
95 | echo "load.sh: copying the extension the symbol area..."
|
---|
96 | rm -Rf "$VBOX_DARWIN_SYMS/$DRVNAME"
|
---|
97 | mkdir -p "$VBOX_DARWIN_SYMS"
|
---|
98 | cp -R "$DIR" "$VBOX_DARWIN_SYMS/"
|
---|
99 | OPTS="$OPTS -s $VBOX_DARWIN_SYMS/ "
|
---|
100 | sync
|
---|
101 | fi
|
---|
102 |
|
---|
103 | trap "sudo chown -R `whoami` $DIR; exit 1" INT
|
---|
104 | # On smbfs, this might succeed just fine but make no actual changes,
|
---|
105 | # so we might have to temporarily copy the driver to a local directory.
|
---|
106 | sudo chown -R root:wheel "$DIR"
|
---|
107 | OWNER=`/usr/bin/stat -f "%u" "$DIR"`
|
---|
108 | if test "$OWNER" -ne 0; then
|
---|
109 | TMP_DIR=/tmp/loaddrv.tmp
|
---|
110 | echo "load.sh: chown didn't work on $DIR, using temp location $TMP_DIR/$DRVNAME"
|
---|
111 |
|
---|
112 | # clean up first (no sudo rm)
|
---|
113 | if test -e "$TMP_DIR"; then
|
---|
114 | sudo chown -R `whoami` "$TMP_DIR"
|
---|
115 | rm -Rf "$TMP_DIR"
|
---|
116 | fi
|
---|
117 |
|
---|
118 | # make a copy and switch over DIR
|
---|
119 | mkdir -p "$TMP_DIR/"
|
---|
120 | sudo cp -Rp "$DIR" "$TMP_DIR/"
|
---|
121 | DIR="$TMP_DIR/$DRVNAME"
|
---|
122 |
|
---|
123 | # retry
|
---|
124 | sudo chown -R root:wheel "$DIR"
|
---|
125 | fi
|
---|
126 | sudo chmod -R o-rwx "$DIR"
|
---|
127 | sync
|
---|
128 | echo "load.sh: loading $DIR..."
|
---|
129 | sudo kextload $OPTS "$DIR"
|
---|
130 | sync
|
---|
131 | sudo chown -R `whoami` "$DIR"
|
---|
132 | #sudo chmod 666 /dev/vboxdrv
|
---|
133 | kextstat | grep org.virtualbox.kext
|
---|
134 |
|
---|