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