0006-scripts-use-strings-instead-of-arrays.patch 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. From 2127850302de2bd8dccff0e31415ce0218750773 Mon Sep 17 00:00:00 2001
  2. From: Ioana Ciornei <[email protected]>
  3. Date: Tue, 24 Oct 2017 16:29:53 +0000
  4. Subject: [PATCH 06/12] scripts: use strings instead of arrays
  5. Signed-off-by: Ioana Ciornei <[email protected]>
  6. ---
  7. scripts/ls-main | 21 ++++++++++++++-------
  8. 1 file changed, 14 insertions(+), 7 deletions(-)
  9. diff --git a/scripts/ls-main b/scripts/ls-main
  10. index a39df2c..b0c742e 100755
  11. --- a/scripts/ls-main
  12. +++ b/scripts/ls-main
  13. @@ -485,7 +485,9 @@ create_dpsw() {
  14. # Make a link in case there is an end point specified
  15. index=0
  16. - for i in "${endpoint[@]}"; do
  17. + echo "${endpoint}" |
  18. + while read -r i
  19. + do
  20. connect $root_c "$dpsw.$index" "$i"
  21. index=$((index + 1))
  22. done
  23. @@ -519,8 +521,8 @@ process_addsw() {
  24. max_fdb_mc_groups=32
  25. # dpsw object label
  26. label=
  27. - #Endpoint objects provided as argument
  28. - endpoint=()
  29. + # Endpoint objects provided as argument
  30. + endpoint=
  31. ifcnt=0
  32. container=$root_c
  33. @@ -559,7 +561,7 @@ process_addsw() {
  34. container="${i#*=}"
  35. ;;
  36. @(dpni|dpmac).+([0-9]))
  37. - endpoint[$ifcnt]="$(echo ${i#*=} | tr -d ,)"
  38. + endpoint="${endpoint}"$'\n'"${i}"
  39. ifcnt=$((ifcnt + 1))
  40. ;;
  41. *)
  42. @@ -571,14 +573,19 @@ process_addsw() {
  43. done
  44. # Check if there are more endpoints provided than the number of the interfaces
  45. - if [ $num_ifs -lt ${#endpoint[@]} ]; then
  46. + if [ $num_ifs -lt $ifcnt ]; then
  47. echo "Error: there are more endpoints provided than the number of the interfaces"
  48. usage_addsw
  49. exit 1
  50. fi
  51. + # Delete first empty line from the endpoint string
  52. + endpoint="$(echo "${endpoint}" | tail -n +2)"
  53. +
  54. # Check if the endpoints are valid
  55. - for i in "${endpoint[@]}"; do
  56. + echo "${endpoint}" |
  57. + while read -r i
  58. + do
  59. type_of_endpoint "$i"
  60. check_endpoint "$i"
  61. has_endpoint "$i"
  62. @@ -592,7 +599,7 @@ process_addsw() {
  63. if (( $object_exists_status == 1 )); then
  64. echo "Created ETHSW object $dpsw with ${num_ifs} ports"
  65. - if [ $num_ifs -gt ${#endpoint[@]} ]; then
  66. + if [ $num_ifs -gt $ifcnt ]; then
  67. echo "Do not forget to connect devices to interface(s)."
  68. fi
  69. fi
  70. --
  71. 2.14.1