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 | DRVNAME="VBoxDrv.kext"
|
---|
32 | BUNDLE="org.virtualbox.kext.VBoxDrv"
|
---|
33 |
|
---|
34 | DIR=`dirname "$0"`
|
---|
35 | DIR=`cd "$DIR" && pwd`
|
---|
36 | DIR="$DIR/$DRVNAME"
|
---|
37 | if [ ! -d "$DIR" ]; then
|
---|
38 | echo "Cannot find $DIR or it's not a directory..."
|
---|
39 | exit 1;
|
---|
40 | fi
|
---|
41 | if [ -n "$*" ]; then
|
---|
42 | OPTS="$*"
|
---|
43 | else
|
---|
44 | OPTS="-t"
|
---|
45 | fi
|
---|
46 |
|
---|
47 | # Make sure VBoxUSB is unloaded as it might be using symbols from us.
|
---|
48 | LOADED=`kextstat -b org.virtualbox.kext.VBoxUSB -l`
|
---|
49 | if test -n "$LOADED"; then
|
---|
50 | echo "load.sh: Unloading org.virtualbox.kext.VBoxUSB..."
|
---|
51 | sudo kextunload -v 6 -b org.virtualbox.kext.VBoxUSB
|
---|
52 | LOADED=`kextstat -b org.virtualbox.kext.VBoxUSB -l`
|
---|
53 | if test -n "$LOADED"; then
|
---|
54 | echo "load.sh: failed to unload org.virtualbox.kext.VBoxUSB, see above..."
|
---|
55 | exit 1;
|
---|
56 | fi
|
---|
57 | echo "load.sh: Successfully unloaded org.virtualbox.kext.VBoxUSB"
|
---|
58 | fi
|
---|
59 |
|
---|
60 | # Try unload any existing instance first.
|
---|
61 | LOADED=`kextstat -b $BUNDLE -l`
|
---|
62 | if test -n "$LOADED"; then
|
---|
63 | echo "load.sh: Unloading $BUNDLE..."
|
---|
64 | sudo kextunload -v 6 -b $BUNDLE
|
---|
65 | LOADED=`kextstat -b $BUNDLE -l`
|
---|
66 | if test -n "$LOADED"; then
|
---|
67 | echo "load.sh: failed to unload $BUNDLE, see above..."
|
---|
68 | exit 1;
|
---|
69 | fi
|
---|
70 | echo "load.sh: Successfully unloaded $BUNDLE"
|
---|
71 | fi
|
---|
72 |
|
---|
73 | set -e
|
---|
74 | trap "sudo chown -R `whoami` $DIR; exit 1" INT
|
---|
75 | # On smbfs, this might succeed just fine but make no actual changes,
|
---|
76 | # so we might have to temporarily copy the driver to a local directory.
|
---|
77 | sudo chown -R root:wheel "$DIR"
|
---|
78 | OWNER=`stat -f "%u" "$DIR"`
|
---|
79 | if test "$OWNER" -ne 0; then
|
---|
80 | TMP_DIR=/tmp/loaddrv.tmp
|
---|
81 | echo "load.sh: chown didn't work on $DIR, using temp location $TMP_DIR/$DRVNAME"
|
---|
82 |
|
---|
83 | # clean up first (no sudo rm)
|
---|
84 | if test -e "$TMP_DIR"; then
|
---|
85 | sudo chown -R `whoami` "$TMP_DIR"
|
---|
86 | rm -Rf "$TMP_DIR"
|
---|
87 | fi
|
---|
88 |
|
---|
89 | # make a copy and switch over DIR
|
---|
90 | mkdir -p "$TMP_DIR/"
|
---|
91 | cp -Rp "$DIR" "$TMP_DIR/"
|
---|
92 | DIR="$TMP_DIR/$DRVNAME"
|
---|
93 |
|
---|
94 | # retry
|
---|
95 | sudo chown -R root:wheel "$DIR"
|
---|
96 | fi
|
---|
97 | sudo chmod -R o-rwx "$DIR"
|
---|
98 | sync
|
---|
99 | echo "load.sh: loading $DIR..."
|
---|
100 | sudo kextload $OPTS "$DIR"
|
---|
101 | sync
|
---|
102 | sudo chown -R `whoami` "$DIR"
|
---|
103 | #sudo chmod 666 /dev/vboxdrv
|
---|
104 | kextstat | grep org.virtualbox.kext
|
---|
105 |
|
---|