ed9d76d454fc9cfa58c0a747ff03ab8813e775f7
[openwrt/staging/robimarko.git] /
1 From e1036011baf9204d5fe6dd74e5a65f95b9681ebd Mon Sep 17 00:00:00 2001
2 From: Ioana Ciornei <ioana.ciornei@nxp.com>
3 Date: Tue, 24 Oct 2017 16:29:56 +0000
4 Subject: [PATCH 07/12] scripts: use Bourne shell's pattern matching
5
6 Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
7 ---
8 scripts/ls-main | 71 ++++++++++++++++++++++++++++-----------------------------
9 1 file changed, 35 insertions(+), 36 deletions(-)
10
11 diff --git a/scripts/ls-main b/scripts/ls-main
12 index b0c742e..a8b9573 100755
13 --- a/scripts/ls-main
14 +++ b/scripts/ls-main
15 @@ -72,8 +72,6 @@
16 #
17 ##
18
19 -shopt -s extglob
20 -
21 # Intercept the Ctrl+C command but do not interrupt execution
22 trap ' ' INT
23
24 @@ -370,15 +368,16 @@ process_addmux() {
25 -c=* | --container=*)
26 container="${i#*=}"
27 ;;
28 - *(dprc.+([0-9])/)dpmac.+([0-9]))
29 - endpoint="${i#*=}"
30 - ;;
31 - *(dprc.+([0-9])/)dpni.+([0-9]))
32 - endpoint="${i#*=}"
33 - ;;
34 *)
35 - usage_addmux
36 - exit 1
37 + arg_dpmac="$(echo $i | grep -x -E "(dprc.[0-9]+/)*dpmac.[0-9]+" || true )"
38 + arg_dpni="$(echo $i | grep -x -E "(dprc.+[0-9]+/)*dpni.[0-9]+" || true )"
39 + if [ "$i" = "$arg_dpmac" ] ||
40 + [ "$i" = "$arg_dpni" ]; then
41 + endpoint="$i"
42 + else
43 + usage_addmux
44 + exit 1
45 + fi
46 ;;
47 esac
48 done
49 @@ -560,14 +559,17 @@ process_addsw() {
50 -c=* | --container=*)
51 container="${i#*=}"
52 ;;
53 - @(dpni|dpmac).+([0-9]))
54 - endpoint="${endpoint}"$'\n'"${i}"
55 - ifcnt=$((ifcnt + 1))
56 - ;;
57 *)
58 - echo "Error: $i argument is invalid"
59 - usage_addsw
60 - exit 1
61 + arg_dpmac="$(echo $i | grep -x -E "dpmac.[0-9]+" || true )"
62 + arg_dpni="$(echo $i | grep -x -E "dpni.[0-9]+" || true )"
63 + if [ "$i" = "$arg_dpmac" ] ||
64 + [ "$i" = "$arg_dpni" ]; then
65 + endpoint="$i"
66 + else
67 + echo "Error: $i argument is invalid"
68 + usage_addsw
69 + exit 1
70 + fi
71 ;;
72 esac
73 done
74 @@ -704,7 +706,8 @@ process_addni() {
75 ;;
76 --mac-addr=*)
77 mac_addr="${i#*=}"
78 - if [[ ! "$mac_addr" =~ ^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$ ]]; then
79 + mac_addr_valid="$(echo $mac_addr | grep -x -E "^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$" || true )"
80 + if [ "$mac_addr" != "$mac_addr_valid" ]; then
81 echo "Invalid MAC address: $mac_addr"
82 exit 1
83 fi
84 @@ -776,25 +779,21 @@ process_addni() {
85 -o=* | --options=*)
86 options="${i#*=}"
87 ;;
88 - *(dprc.+([0-9])/)dpmac.+([0-9]))
89 - no_link=0
90 - endpoint="${i#*=}"
91 - ;;
92 - *(dprc.+([0-9])/)dpni.+([0-9]))
93 - no_link=0
94 - endpoint="${i#*=}"
95 - ;;
96 - *(dprc.+([0-9])/)dpdmux.+([0-9]).+([0-9]))
97 - no_link=0
98 - endpoint="${i#*=}"
99 - ;;
100 - *(dprc.+([0-9])/)dpsw.+([0-9]).+([0-9]))
101 - no_link=0
102 - endpoint="${i#*=}"
103 - ;;
104 *)
105 - usage_addni
106 - exit 1
107 + arg_dpmac="$(echo $i | grep -x -E "(dprc.[0-9]+/)*dpmac.[0-9]+" || true )"
108 + arg_dpni="$(echo $i | grep -x -E "(dprc.+[0-9]+/)*dpni.[0-9]+" || true )"
109 + arg_dpdmux="$(echo $i | grep -x -E "(dprc.[0-9]+/)*dpdmux.[0-9]+.[0-9]+" || true )"
110 + arg_dpsw="$(echo $i | grep -x -E "(dprc.[0-9]+/)*dpsw.[0-9]+.[0-9]+" || true )"
111 + if [ "$i" = "$arg_dpmac" ] ||
112 + [ "$i" = "$arg_dpni" ] ||
113 + [ "$i" = "$arg_dpdmux" ] ||
114 + [ "$i" = "$arg_dpsw" ]; then
115 + no_link=0
116 + endpoint="$i"
117 + else
118 + usage_addni
119 + exit 1
120 + fi
121 ;;
122 esac
123 done
124 --
125 2.14.1
126