VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/VBoxNetFlt/darwin/loadnetflt.sh@ 79846

Last change on this file since 79846 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette