loadnetflt.sh revision d65680efa46fa49e8bf14e67b29b782510ff934c
de4157257515400c2c25373591135f110227b68cvboxsync#!/bin/bash
de4157257515400c2c25373591135f110227b68cvboxsync## @file
de4157257515400c2c25373591135f110227b68cvboxsync# For development.
de4157257515400c2c25373591135f110227b68cvboxsync#
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync#
de4157257515400c2c25373591135f110227b68cvboxsync# Copyright (C) 2006-2007 Sun Microsystems, Inc.
de4157257515400c2c25373591135f110227b68cvboxsync#
d65680efa46fa49e8bf14e67b29b782510ff934cvboxsync# Sun Microsystems, Inc. confidential
d65680efa46fa49e8bf14e67b29b782510ff934cvboxsync# All rights reserved
de4157257515400c2c25373591135f110227b68cvboxsync#
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncDRVNAME="VBoxNetFlt.kext"
de4157257515400c2c25373591135f110227b68cvboxsyncBUNDLE="org.virtualbox.kext.VBoxNetFlt"
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncDEP_DRVNAME="VBoxDrv.kext"
de4157257515400c2c25373591135f110227b68cvboxsyncDEP_BUNDLE="org.virtualbox.kext.VBoxDrv"
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncDIR=`dirname "$0"`
de4157257515400c2c25373591135f110227b68cvboxsyncDIR=`cd "$DIR" && pwd`
de4157257515400c2c25373591135f110227b68cvboxsyncDEP_DIR="$DIR/$DEP_DRVNAME"
de4157257515400c2c25373591135f110227b68cvboxsyncDIR="$DIR/$DRVNAME"
de4157257515400c2c25373591135f110227b68cvboxsyncif [ ! -d "$DIR" ]; then
de4157257515400c2c25373591135f110227b68cvboxsync echo "Cannot find $DIR or it's not a directory..."
de4157257515400c2c25373591135f110227b68cvboxsync exit 1;
de4157257515400c2c25373591135f110227b68cvboxsyncfi
de4157257515400c2c25373591135f110227b68cvboxsyncif [ ! -d "$DEP_DIR" ]; then
de4157257515400c2c25373591135f110227b68cvboxsync echo "Cannot find $DEP_DIR or it's not a directory... (dependency)"
de4157257515400c2c25373591135f110227b68cvboxsync exit 1;
de4157257515400c2c25373591135f110227b68cvboxsyncfi
de4157257515400c2c25373591135f110227b68cvboxsyncif [ -n "$*" ]; then
de4157257515400c2c25373591135f110227b68cvboxsync OPTS="$*"
de4157257515400c2c25373591135f110227b68cvboxsyncelse
de4157257515400c2c25373591135f110227b68cvboxsync OPTS="-t"
de4157257515400c2c25373591135f110227b68cvboxsyncfi
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsynctrap "sudo chown -R `whoami` $DIR $DEP_DIR; exit 1" INT
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync# Try unload any existing instance first.
de4157257515400c2c25373591135f110227b68cvboxsyncLOADED=`kextstat -b $BUNDLE -l`
de4157257515400c2c25373591135f110227b68cvboxsyncif test -n "$LOADED"; then
de4157257515400c2c25373591135f110227b68cvboxsync echo "loadnetflt.sh: Unloading $BUNDLE..."
de4157257515400c2c25373591135f110227b68cvboxsync sudo kextunload -v 6 -b $BUNDLE
de4157257515400c2c25373591135f110227b68cvboxsync LOADED=`kextstat -b $BUNDLE -l`
de4157257515400c2c25373591135f110227b68cvboxsync if test -n "$LOADED"; then
de4157257515400c2c25373591135f110227b68cvboxsync echo "loadnetflt: failed to unload $BUNDLE, see above..."
de4157257515400c2c25373591135f110227b68cvboxsync exit 1;
de4157257515400c2c25373591135f110227b68cvboxsync fi
de4157257515400c2c25373591135f110227b68cvboxsync echo "loadnetflt: Successfully unloaded $BUNDLE"
de4157257515400c2c25373591135f110227b68cvboxsyncfi
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncset -e
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync# Copy the .kext to the symbols directory and tweak the kextload options.
de4157257515400c2c25373591135f110227b68cvboxsyncif test -n "$VBOX_DARWIN_SYMS"; then
de4157257515400c2c25373591135f110227b68cvboxsync echo "loadnetflt.sh: copying the extension the symbol area..."
de4157257515400c2c25373591135f110227b68cvboxsync rm -Rf "$VBOX_DARWIN_SYMS/$DRVNAME"
de4157257515400c2c25373591135f110227b68cvboxsync mkdir -p "$VBOX_DARWIN_SYMS"
de4157257515400c2c25373591135f110227b68cvboxsync cp -R "$DIR" "$VBOX_DARWIN_SYMS/"
de4157257515400c2c25373591135f110227b68cvboxsync OPTS="$OPTS -s $VBOX_DARWIN_SYMS/ "
de4157257515400c2c25373591135f110227b68cvboxsync sync
de4157257515400c2c25373591135f110227b68cvboxsyncfi
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync# On smbfs, this might succeed just fine but make no actual changes,
de4157257515400c2c25373591135f110227b68cvboxsync# so we might have to temporarily copy the driver to a local directory.
de4157257515400c2c25373591135f110227b68cvboxsyncsudo chown -R root:wheel "$DIR" "$DEP_DIR"
de4157257515400c2c25373591135f110227b68cvboxsyncOWNER=`/usr/bin/stat -f "%u" "$DIR"`
de4157257515400c2c25373591135f110227b68cvboxsyncif test "$OWNER" -ne 0; then
de4157257515400c2c25373591135f110227b68cvboxsync TMP_DIR=/tmp/loadusb.tmp
de4157257515400c2c25373591135f110227b68cvboxsync echo "loadnetflt.sh: chown didn't work on $DIR, using temp location $TMP_DIR/$DRVNAME"
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync # clean up first (no sudo rm)
de4157257515400c2c25373591135f110227b68cvboxsync if test -e "$TMP_DIR"; then
de4157257515400c2c25373591135f110227b68cvboxsync sudo chown -R `whoami` "$TMP_DIR"
de4157257515400c2c25373591135f110227b68cvboxsync rm -Rf "$TMP_DIR"
de4157257515400c2c25373591135f110227b68cvboxsync fi
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync # make a copy and switch over DIR
de4157257515400c2c25373591135f110227b68cvboxsync mkdir -p "$TMP_DIR/"
de4157257515400c2c25373591135f110227b68cvboxsync cp -Rp "$DIR" "$TMP_DIR/"
de4157257515400c2c25373591135f110227b68cvboxsync DIR="$TMP_DIR/$DRVNAME"
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync # load.sh puts it here.
de4157257515400c2c25373591135f110227b68cvboxsync DEP_DIR="/tmp/loaddrv.tmp/$DEP_DRVNAME"
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync # retry
de4157257515400c2c25373591135f110227b68cvboxsync sudo chown -R root:wheel "$DIR" "$DEP_DIR"
de4157257515400c2c25373591135f110227b68cvboxsyncfi
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncsudo chmod -R o-rwx "$DIR"
de4157257515400c2c25373591135f110227b68cvboxsyncsync
de4157257515400c2c25373591135f110227b68cvboxsyncecho "loadnetflt: loading $DIR... (kextload $OPTS \"$DIR\")"
de4157257515400c2c25373591135f110227b68cvboxsyncsudo kextload $OPTS -d "$DEP_DIR" "$DIR"
de4157257515400c2c25373591135f110227b68cvboxsyncsync
de4157257515400c2c25373591135f110227b68cvboxsyncsudo chown -R `whoami` "$DIR" "$DEP_DIR"
de4157257515400c2c25373591135f110227b68cvboxsynckextstat | grep org.virtualbox.kext
de4157257515400c2c25373591135f110227b68cvboxsync