diff mbox series

[3/4] runqemu-ifdown: catch up with ifup

Message ID 20230626133213.47920-4-adrian.freihofer@siemens.com
State Accepted, archived
Commit be72e5e32da5a251db14b42d3e9c0951178e216d
Headers show
Series fix runqemu-ifup/down scritps | expand

Commit Message

Adrian Freihofer June 26, 2023, 1:29 p.m. UTC
- Drop the native-sysroot-basedir parameter
  still allow it to keep backward compatibility
  write a warning to stderr
- Add a space after ! in the if as suggested by shellcheck
- Support the new OE_TAP_NAME variable as well

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 scripts/runqemu-ifdown | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/scripts/runqemu-ifdown b/scripts/runqemu-ifdown
index 78be28812d4..822a2a39b9f 100755
--- a/scripts/runqemu-ifdown
+++ b/scripts/runqemu-ifdown
@@ -16,7 +16,7 @@ 
 #
 
 usage() {
-	echo "sudo $(basename $0) <tap-dev> <native-sysroot-basedir>"
+	echo "sudo $(basename $0) <tap-dev>"
 }
 
 if [ $EUID -ne 0 ]; then
@@ -24,15 +24,19 @@  if [ $EUID -ne 0 ]; then
 	exit 1
 fi
 
-if [ $# -ne 2 ]; then
+if [ $# -gt 2 ] || [ $# -lt 1 ]; then
 	usage
 	exit 1
 fi
 
+# backward compatibility
+if [ $# -eq 2 ] ; then
+	echo "Warning: native-sysroot-basedir parameter is ignored. It is no longer needed." >&2
+fi
+
 TAP=$1
-STAGING_BINDIR_NATIVE=$2
 
-if !ip tuntap del $TAP mode tap 2>/dev/null; then
+if ! ip tuntap del $TAP mode tap 2>/dev/null; then
 	echo "Error: Unable to run up tuntap del"
 	exit 1
 fi
@@ -56,8 +60,13 @@  if [ ! -x "$IPTABLES" ]; then
 	echo "$IPTABLES cannot be executed"
 	exit 1
 fi
-n=$[ (`echo $TAP | sed 's/tap//'` * 2) + 1 ]
-dest=$[ (`echo $TAP | sed 's/tap//'` * 2) + 2 ]
+
+if [ -z "$OE_TAP_NAME" ]; then
+	OE_TAP_NAME=tap
+fi
+
+n=$[ (`echo $TAP | sed "s/$OE_TAP_NAME//"` * 2) + 1 ]
+dest=$[ (`echo $TAP | sed "s/$OE_TAP_NAME//"` * 2) + 2 ]
 $IPTABLES -D POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$n/32
 $IPTABLES -D POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$dest/32
 true