diff mbox series

[OpenWrt-Devel] mtd_get_mac_ascii Return first occurence of $key.

Message ID 20191126131003.324777-1-vargagab@gmail.com
State Changes Requested
Delegated to: Petr Štetiar
Headers show
Series [OpenWrt-Devel] mtd_get_mac_ascii Return first occurence of $key. | expand

Commit Message

Gábor Varga Nov. 26, 2019, 1:10 p.m. UTC
From: Gabor Varga <vargagab@gmail.com>

 For example on Asus RT-AC65P router (and the identical Asus RT-AC85P)
 the et1macaddr string has multiple occurences in u-boot-env partition.
 So, the mtd_get_mac_ascii cannot determine the WAN MAC address
 (called from /etc/board.d/02_network script), and with default 
 configuration the WAN and LAN MAC addresses are swapped.

Signed-off-by: Gabor Varga <vargagab@gmail.com>
---
 package/base-files/files/lib/functions/system.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Petr Štetiar July 11, 2020, 10:13 a.m. UTC | #1
vargagab@gmail.com <vargagab@gmail.com> [2019-11-26 14:10:03]:

Hi,

> From: Gabor Varga <vargagab@gmail.com>
> 
>  For example on Asus RT-AC65P router (and the identical Asus RT-AC85P)
>  the et1macaddr string has multiple occurences in u-boot-env partition.
>  So, the mtd_get_mac_ascii cannot determine the WAN MAC address
>  (called from /etc/board.d/02_network script), and with default 
>  configuration the WAN and LAN MAC addresses are swapped.
> 
> Signed-off-by: Gabor Varga <vargagab@gmail.com>
> ---
>  package/base-files/files/lib/functions/system.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh
> index c4dc3cc3a9..067157f53f 100644
> --- a/package/base-files/files/lib/functions/system.sh
> +++ b/package/base-files/files/lib/functions/system.sh
> @@ -72,7 +72,7 @@ mtd_get_mac_ascii() {
>  		return
>  	fi
>  
> -	mac_dirty=$(strings "$part" | sed -n 's/^'"$key"'=//p')
> +	mac_dirty=$(strings "$part" | sed -n '1,/'"$key"'=/s/^'"$key"'=//p')

 $ echo -e "abc=moo\nabc=foo" | ( export key=abc; sed -n 's/^'"$key"'=//p' )
 moo
 foo

 $ echo -e "abc=moo\nabc=foo" | ( export key=abc; sed -n '1,/'"$key"'=/s/^'"$key"'=//p' )
 moo
 foo

Seems to not work as expected.

-- ynezz
diff mbox series

Patch

diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh
index c4dc3cc3a9..067157f53f 100644
--- a/package/base-files/files/lib/functions/system.sh
+++ b/package/base-files/files/lib/functions/system.sh
@@ -72,7 +72,7 @@  mtd_get_mac_ascii() {
 		return
 	fi
 
-	mac_dirty=$(strings "$part" | sed -n 's/^'"$key"'=//p')
+	mac_dirty=$(strings "$part" | sed -n '1,/'"$key"'=/s/^'"$key"'=//p')
 
 	# "canonicalize" mac
 	[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty"