aboutsummaryrefslogtreecommitdiffstats
path: root/package/network/utils/layerscape/restool/patches/0007-scripts-use-Bourne-shell-s-pattern-matching.patch
blob: ed9d76d454fc9cfa58c0a747ff03ab8813e775f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
From e1036011baf9204d5fe6dd74e5a65f95b9681ebd Mon Sep 17 00:00:00 2001
From: Ioana Ciornei <ioana.ciornei@nxp.com>
Date: Tue, 24 Oct 2017 16:29:56 +0000
Subject: [PATCH 07/12] scripts: use Bourne shell's pattern matching

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
 scripts/ls-main | 71 ++++++++++++++++++++++++++++-----------------------------
 1 file changed, 35 insertions(+), 36 deletions(-)

diff --git a/scripts/ls-main b/scripts/ls-main
index b0c742e..a8b9573 100755
--- a/scripts/ls-main
+++ b/scripts/ls-main
@@ -72,8 +72,6 @@
 #
 ##
 
-shopt -s extglob
-
 # Intercept the Ctrl+C command but do not interrupt execution
 trap ' ' INT
 
@@ -370,15 +368,16 @@ process_addmux() {
 			-c=* | --container=*)
 				container="${i#*=}"
 				;;
-			*(dprc.+([0-9])/)dpmac.+([0-9]))
-				endpoint="${i#*=}"
-				;;
-			*(dprc.+([0-9])/)dpni.+([0-9]))
-				endpoint="${i#*=}"
-				;;
 			*)
-				usage_addmux
-				exit 1
+				arg_dpmac="$(echo $i | grep -x -E "(dprc.[0-9]+/)*dpmac.[0-9]+" || true )"
+				arg_dpni="$(echo $i | grep -x -E "(dprc.+[0-9]+/)*dpni.[0-9]+" || true )"
+				if [ "$i" = "$arg_dpmac"  ] ||
+				   [ "$i" = "$arg_dpni" ]; then
+					endpoint="$i"
+				else
+					usage_addmux
+					exit 1
+				fi
 				;;
 		esac
 	done
@@ -560,14 +559,17 @@ process_addsw() {
 			-c=* | --container=*)
 				container="${i#*=}"
 				;;
-			@(dpni|dpmac).+([0-9]))
-				endpoint="${endpoint}"$'\n'"${i}"
-				ifcnt=$((ifcnt + 1))
-				;;
 			*)
-				echo "Error: $i argument is invalid"
-				usage_addsw
-				exit 1
+				arg_dpmac="$(echo $i | grep -x -E "dpmac.[0-9]+" || true )"
+				arg_dpni="$(echo $i | grep -x -E "dpni.[0-9]+" || true )"
+				if [ "$i" = "$arg_dpmac"  ] ||
+				   [ "$i" = "$arg_dpni" ]; then
+					endpoint="$i"
+				else
+					echo "Error: $i argument is invalid"
+					usage_addsw
+					exit 1
+				fi
 				;;
 		esac
 	done
@@ -704,7 +706,8 @@ process_addni() {
 				;;
 			--mac-addr=*)
 				mac_addr="${i#*=}"
-				if [[ ! "$mac_addr" =~ ^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$ ]]; then
+				mac_addr_valid="$(echo $mac_addr | grep -x -E "^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$" || true )"
+				if [ "$mac_addr" != "$mac_addr_valid" ]; then
 					echo "Invalid MAC address: $mac_addr"
 					exit 1
 				fi
@@ -776,25 +779,21 @@ process_addni() {
 			-o=* | --options=*)
 				options="${i#*=}"
 				;;
-			*(dprc.+([0-9])/)dpmac.+([0-9]))
-				no_link=0
-				endpoint="${i#*=}"
-				;;
-			*(dprc.+([0-9])/)dpni.+([0-9]))
-				no_link=0
-				endpoint="${i#*=}"
-				;;
-			*(dprc.+([0-9])/)dpdmux.+([0-9]).+([0-9]))
-				no_link=0
-				endpoint="${i#*=}"
-				;;
-			*(dprc.+([0-9])/)dpsw.+([0-9]).+([0-9]))
-				no_link=0
-				endpoint="${i#*=}"
-				;;
 			*)
-				usage_addni
-				exit 1
+				arg_dpmac="$(echo $i | grep -x -E "(dprc.[0-9]+/)*dpmac.[0-9]+" || true )"
+				arg_dpni="$(echo $i | grep -x -E "(dprc.+[0-9]+/)*dpni.[0-9]+" || true )"
+				arg_dpdmux="$(echo $i | grep -x -E "(dprc.[0-9]+/)*dpdmux.[0-9]+.[0-9]+" || true )"
+				arg_dpsw="$(echo $i | grep -x -E "(dprc.[0-9]+/)*dpsw.[0-9]+.[0-9]+" || true )"
+				if [ "$i" = "$arg_dpmac"  ] ||
+				   [ "$i" = "$arg_dpni"   ] ||
+				   [ "$i" = "$arg_dpdmux" ] ||
+				   [ "$i" = "$arg_dpsw" ]; then
+					no_link=0
+					endpoint="$i"
+				else
+					usage_addni
+					exit 1
+				fi
 				;;
 		esac
 	done
-- 
2.14.1