poky/scripts/runqemu-gen-tapdevs
Adrian Freihofer 14dcde95ec runqemu-gen-tapdevs: remove staging dir parameter
The parameter staging_bindir_native is no longer used. Remove it.
For now the script is backward compatible. With 4 parameters it logs an
error message but still works.

(From OE-Core rev: c47322297fcd0408c5e290e74eee4344754e03e4)

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2023-06-24 12:21:48 +01:00

2.5 KiB
Executable File

#!/bin/bash

Create a "bank" of tap network devices that can be used by the

runqemu script. This script needs to be run as root

Copyright (C) 2010 Intel Corp.

SPDX-License-Identifier: GPL-2.0-only

uid=id -u gid=id -g if [ -n "$SUDO_UID" ]; then uid=$SUDO_UID fi if [ -n "$SUDO_GID" ]; then gid=$SUDO_GID fi

usage() { echo "Usage: sudo $0 " echo "Where is the numeric user id the tap devices will be owned by" echo "Where is the numeric group id the tap devices will be owned by" echo " is the number of tap devices to create (0 to remove all)" echo "For example:" echo "$ bitbake qemu-helper-native" echo "$ sudo $0 $uid $gid 4" echo "" exit 1 }

Allow passing 4 arguments for backward compatibility with warning

if [ $# -eq 4 ]; then echo "Warning: The parameter is no longer needed. Ignoring." fi if [ $# -lt 3 ] || [ $# -gt 4 ]; then echo "Error: Incorrect number of arguments" usage fi

TUID=$1 GID=$2 COUNT=$3

check if COUNT is a number and >= 0

if ! [ $COUNT -ge 0 ]; then echo "Error: Incorrect count: $COUNT" exit 1 fi

if [ $EUID -ne 0 ]; then echo "Error: This script must be run with root privileges" exit fi

SCRIPT_DIR=dirname $0 RUNQEMU_IFUP="$SCRIPT_DIR/runqemu-ifup" if [ ! -x "$RUNQEMU_IFUP" ]; then echo "Error: Unable to find the runqemu-ifup script in $SCRIPT_DIR" exit 1 fi

if interfaces=ip tuntap list 2>/dev/null; then interfaces=echo "$interfaces" |cut -f1 -d: else echo "Failed to call 'ip tuntap list'" >&2 exit 1 fi

Ensure we start with a clean slate

for tap in $interfaces; do echo "Note: Destroying pre-existing tap interface $tap..." ip tuntap del $tap mode tap done rm -f /etc/runqemu-nosudo

if [ $COUNT -eq 0 ]; then exit 0 fi

echo "Creating $COUNT tap devices for UID: $TUID GID: $GID..." for ((index=0; index < $COUNT; index++)); do echo "Creating tap$index" if ! ifup=$RUNQEMU_IFUP $TUID $GID 2>&1; then echo "Error bringing up interface: $ifup" exit 1 fi done

echo "Note: For systems running NetworkManager, it's recommended" echo "Note: that the tap devices be set as unmanaged in the" echo "Note: NetworkManager.conf file. Add the following lines to" echo "Note: /etc/NetworkManager/NetworkManager.conf" echo "[keyfile]" echo "unmanaged-devices=interface-name:tap*"

The runqemu script will check for this file, and if it exists,

will use the existing bank of tap devices without creating

additional ones via sudo.

touch /etc/runqemu-nosudo