summaryrefslogtreecommitdiffstats
path: root/scripts/poky-qemu-ifup
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/poky-qemu-ifup')
-rwxr-xr-xscripts/poky-qemu-ifup53
1 files changed, 19 insertions, 34 deletions
diff --git a/scripts/poky-qemu-ifup b/scripts/poky-qemu-ifup
index 5ae6c6aefb..cd4c47b608 100755
--- a/scripts/poky-qemu-ifup
+++ b/scripts/poky-qemu-ifup
@@ -6,14 +6,17 @@
6# tunctl which does not support the group permissions option, hence 6# tunctl which does not support the group permissions option, hence
7# the need to use Poky's version. 7# the need to use Poky's version.
8# 8#
9# If this script is being run standalone in order to set up a bank of tap 9# If you find yourself calling this script a lot, you can add the
10# devices for later qemu use, then a group id must be the first argument. 10# the following to your /etc/sudoers file to be able to run this
11# The resulting tap device will be group-owned by this group, and qemu 11# command without entering your password each time:
12# users must be members of this group.
13# 12#
14# If the kernel is too old to support TUNSETGROUP, then a user must be passed 13# <my-username> ALL=NOPASSWD: /path/to/poky-qemu-ifup
15# in as the second argument, the tap device will be owned by that user, and 14# <my-username> ALL=NOPASSWD: /path/to/poky-qemu-ifdown
16# only that user will be able to use it. 15#
16# If you'd like to create a bank of tap devices at once, you should use
17# the poky-gen-tapdevs script instead. If tap devices are set up using
18# that script, the poky-qemu script will never end up calling this
19# script.
17# 20#
18# Copyright (c) 2006-2010 Intel Corp. 21# Copyright (c) 2006-2010 Intel Corp.
19# 22#
@@ -31,26 +34,24 @@
31# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 34# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 35
33usage() { 36usage() {
34 echo "$0 <gid> {uid} <native-sysroot-basedir>" 37 echo "sudo $0 <gid> <native-sysroot-basedir>"
35 echo "Where uid is *only* included if this script complains when it's missing"
36} 38}
37 39
38if [[ $# -lt 2 || $# -gt 3 ]]; then 40if [ $EUID -ne 0 ]; then
41 echo "Error: This script (poky-qemu-ifup) must be run with root privileges"
42 exit 1
43fi
44
45if [ $# -ne 2 ]; then
39 usage 46 usage
40 exit 1 47 exit 1
41fi 48fi
42 49
43USER=""
44GROUP="-g $1" 50GROUP="-g $1"
45if [ $# -eq 2 ]; then 51NATIVE_SYSROOT_DIR=$2
46 NATIVE_SYSROOT_DIR=$2
47else
48 USER=$2
49 NATIVE_SYSROOT_DIR=$3
50fi
51 52
52TUNCTL=$NATIVE_SYSROOT_DIR/usr/bin/tunctl 53TUNCTL=$NATIVE_SYSROOT_DIR/usr/bin/tunctl
53if [ ! -e "$TUNCTL" ]; then 54if [ ! -x "$TUNCTL" ]; then
54 echo "Error: Unable to find tunctl binary in '$NATIVE_SYSROOT_DIR/usr/bin'" 55 echo "Error: Unable to find tunctl binary in '$NATIVE_SYSROOT_DIR/usr/bin'"
55 56
56 if [[ "$NATIVE_SYSROOT_DIR" =~ ^\/opt\/poky ]]; then 57 if [[ "$NATIVE_SYSROOT_DIR" =~ ^\/opt\/poky ]]; then
@@ -64,22 +65,6 @@ fi
64 65
65TAP=`$TUNCTL -b $GROUP 2>&1` 66TAP=`$TUNCTL -b $GROUP 2>&1`
66STATUS=$? 67STATUS=$?
67if [[ "$TAP" =~ "TUNSETGROUP" ]]; then
68 # TUNSETGROUP failed because of permissions or the kernel being too old
69 # Retry, falling back to a specific user
70 if [ "$USER" = "" ]; then
71 echo "TUNSETGROUP failed - add a username to the command line in order"
72 echo "to have the tap device owned by that user"
73 exit 1
74 fi
75 TAP=`$TUNCTL -b -u $USER 2>&1`
76 STATUS=$?
77 # Force this to appear on stderr in order that the user sees it if this
78 # is running from poky-qemu-internal and in order to avoid having this
79 # output confuse it.
80 echo "Only user $USER will be able to use $TAP - upgrade the kernel to " 1>&2
81 echo "2.6.23 or later in order to allow group access to tap devices" 1>&2
82fi
83if [ $STATUS -ne 0 ]; then 68if [ $STATUS -ne 0 ]; then
84 echo "tunctl failed:" 69 echo "tunctl failed:"
85 echo $TAP 70 echo $TAP