1 | #!/bin/bash
|
---|
2 | ## @file
|
---|
3 | # For development.
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
8 | #
|
---|
9 | # Sun Microsystems, Inc. confidential
|
---|
10 | # All rights reserved
|
---|
11 | #
|
---|
12 |
|
---|
13 | DRVNAME="VBoxNetFlt.kext"
|
---|
14 | BUNDLE="org.virtualbox.kext.VBoxNetFlt"
|
---|
15 |
|
---|
16 | DEP_DRVNAME="VBoxDrv.kext"
|
---|
17 | DEP_BUNDLE="org.virtualbox.kext.VBoxDrv"
|
---|
18 |
|
---|
19 |
|
---|
20 | DIR=`dirname "$0"`
|
---|
21 | DIR=`cd "$DIR" && pwd`
|
---|
22 | DEP_DIR="$DIR/$DEP_DRVNAME"
|
---|
23 | DIR="$DIR/$DRVNAME"
|
---|
24 | if [ ! -d "$DIR" ]; then
|
---|
25 | echo "Cannot find $DIR or it's not a directory..."
|
---|
26 | exit 1;
|
---|
27 | fi
|
---|
28 | if [ ! -d "$DEP_DIR" ]; then
|
---|
29 | echo "Cannot find $DEP_DIR or it's not a directory... (dependency)"
|
---|
30 | exit 1;
|
---|
31 | fi
|
---|
32 | if [ -n "$*" ]; then
|
---|
33 | OPTS="$*"
|
---|
34 | else
|
---|
35 | OPTS="-t"
|
---|
36 | fi
|
---|
37 |
|
---|
38 | trap "sudo chown -R `whoami` $DIR $DEP_DIR; exit 1" INT
|
---|
39 |
|
---|
40 | # Try unload any existing instance first.
|
---|
41 | LOADED=`kextstat -b $BUNDLE -l`
|
---|
42 | if test -n "$LOADED"; then
|
---|
43 | echo "loadnetflt.sh: Unloading $BUNDLE..."
|
---|
44 | sudo kextunload -v 6 -b $BUNDLE
|
---|
45 | LOADED=`kextstat -b $BUNDLE -l`
|
---|
46 | if test -n "$LOADED"; then
|
---|
47 | echo "loadnetflt: failed to unload $BUNDLE, see above..."
|
---|
48 | exit 1;
|
---|
49 | fi
|
---|
50 | echo "loadnetflt: Successfully unloaded $BUNDLE"
|
---|
51 | fi
|
---|
52 |
|
---|
53 | set -e
|
---|
54 |
|
---|
55 | # Copy the .kext to the symbols directory and tweak the kextload options.
|
---|
56 | if test -n "$VBOX_DARWIN_SYMS"; then
|
---|
57 | echo "loadnetflt.sh: copying the extension the symbol area..."
|
---|
58 | rm -Rf "$VBOX_DARWIN_SYMS/$DRVNAME"
|
---|
59 | mkdir -p "$VBOX_DARWIN_SYMS"
|
---|
60 | cp -R "$DIR" "$VBOX_DARWIN_SYMS/"
|
---|
61 | OPTS="$OPTS -s $VBOX_DARWIN_SYMS/ "
|
---|
62 | sync
|
---|
63 | fi
|
---|
64 |
|
---|
65 | # On smbfs, this might succeed just fine but make no actual changes,
|
---|
66 | # so we might have to temporarily copy the driver to a local directory.
|
---|
67 | sudo chown -R root:wheel "$DIR" "$DEP_DIR"
|
---|
68 | OWNER=`/usr/bin/stat -f "%u" "$DIR"`
|
---|
69 | if test "$OWNER" -ne 0; then
|
---|
70 | TMP_DIR=/tmp/loadusb.tmp
|
---|
71 | echo "loadnetflt.sh: chown didn't work on $DIR, using temp location $TMP_DIR/$DRVNAME"
|
---|
72 |
|
---|
73 | # clean up first (no sudo rm)
|
---|
74 | if test -e "$TMP_DIR"; then
|
---|
75 | sudo chown -R `whoami` "$TMP_DIR"
|
---|
76 | rm -Rf "$TMP_DIR"
|
---|
77 | fi
|
---|
78 |
|
---|
79 | # make a copy and switch over DIR
|
---|
80 | mkdir -p "$TMP_DIR/"
|
---|
81 | cp -Rp "$DIR" "$TMP_DIR/"
|
---|
82 | DIR="$TMP_DIR/$DRVNAME"
|
---|
83 |
|
---|
84 | # load.sh puts it here.
|
---|
85 | DEP_DIR="/tmp/loaddrv.tmp/$DEP_DRVNAME"
|
---|
86 |
|
---|
87 | # retry
|
---|
88 | sudo chown -R root:wheel "$DIR" "$DEP_DIR"
|
---|
89 | fi
|
---|
90 |
|
---|
91 | sudo chmod -R o-rwx "$DIR"
|
---|
92 | sync
|
---|
93 | echo "loadnetflt: loading $DIR... (kextload $OPTS \"$DIR\")"
|
---|
94 | sudo kextload $OPTS -d "$DEP_DIR" "$DIR"
|
---|
95 | sync
|
---|
96 | sudo chown -R `whoami` "$DIR" "$DEP_DIR"
|
---|
97 | kextstat | grep org.virtualbox.kext
|
---|
98 |
|
---|