From 7bba4e48f63629ba328d134f78e840d6a646551b Mon Sep 17 00:00:00 2001
From: Sukru Senli <sukru.senli@iopsys.eu>
Date: Thu, 10 Feb 2022 17:20:33 +0100
Subject: [PATCH] iopsys-econet: fix tc3162-eth-portmap.sh

---
 .../netifd/pre-reload/tc3162-eth-portmap.sh   | 23 ++++++++-----------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/iopsys-econet/base-files/lib/netifd/pre-reload/tc3162-eth-portmap.sh b/iopsys-econet/base-files/lib/netifd/pre-reload/tc3162-eth-portmap.sh
index ac86f282c..d67725fa4 100644
--- a/iopsys-econet/base-files/lib/netifd/pre-reload/tc3162-eth-portmap.sh
+++ b/iopsys-econet/base-files/lib/netifd/pre-reload/tc3162-eth-portmap.sh
@@ -25,22 +25,19 @@ tc3162_eth_portmap() {
 		;;
 		br-lan)
 			section="$(uci show network | grep 'name=.*br-lan' | cut -d'.' -f2)"
-			lan_ports="$(uci -q get network.$section.ports)"
-			lan1_port=$(echo $lan_ports | cut -d' ' -f1 | cut -d'.' -f2)
-			lan1_port="${lan1_port:--1}"
-			lan2_port=$(echo $lan_ports | cut -d' ' -f2 | cut -d'.' -f2)
-			lan2_port="${lan2_port:--1}"
-			lan3_port=$(echo $lan_ports | cut -d' ' -f3 | cut -d'.' -f2)
-			lan3_port="${lan3_port:--1}"
-			lan4_port=$(echo $lan_ports | cut -d' ' -f4 | cut -d'.' -f2)
-			lan4_port="${lan4_port:--1}"
-			lan5_port=$(echo $lan_ports | cut -d' ' -f5 | cut -d'.' -f2)
-			lan5_port="${lan5_port:--1}"
-			lan6_port=$(echo $lan_ports | cut -d' ' -f6 | cut -d'.' -f2)
-			lan6_port="${lan6_port:--1}"				
+			lan_ports="$(uci -q get network.$section.ports | tr -d 'eth0.')"
+			port_num=$(echo $lan_ports | wc -w)
+			[ $port_num -gt 0 ] && lan1_port="$(echo $lan_ports | cut -d' ' -f1)"
+			[ $port_num -gt 1 ] && lan2_port="$(echo $lan_ports | cut -d' ' -f2)"
+			[ $port_num -gt 2 ] && lan3_port="$(echo $lan_ports | cut -d' ' -f3)"
+			[ $port_num -gt 3 ] && lan4_port="$(echo $lan_ports | cut -d' ' -f4)"
+			[ $port_num -gt 4 ] && lan5_port="$(echo $lan_ports | cut -d' ' -f5)"
+			[ $port_num -gt 5 ] && lan6_port="$(echo $lan_ports | cut -d' ' -f6)"
 		;;
 	esac
 
+	logger -t "netifd-pre-reload" "echo $wan_port $lan1_port $lan2_port $lan3_port $lan4_port $lan5_port $lan6_port > /proc/tc3162/eth_portmap"
+
 	echo $wan_port $lan1_port $lan2_port $lan3_port $lan4_port $lan5_port $lan6_port > /proc/tc3162/eth_portmap
 }
 
-- 
GitLab