From 1ee5216a6941b571364eeb62523806b9c1be0c14 Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Sun, 23 Mar 2025 19:48:11 +0100 Subject: [PATCH] Remove duplication of IP addresses and fix display style --- .../etc/update-motd.d/10-armbian-header | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/bsp/common/etc/update-motd.d/10-armbian-header b/packages/bsp/common/etc/update-motd.d/10-armbian-header index df0bd18a1..0c14586e9 100755 --- a/packages/bsp/common/etc/update-motd.d/10-armbian-header +++ b/packages/bsp/common/etc/update-motd.d/10-armbian-header @@ -108,6 +108,7 @@ KERNELID=$(uname -r) ip_address=$(get_ip_addresses &) wan_ip_address=$(get_wan_address &) wan_ip6_address=$(get_wan6_address &) + # Get access point info if systemctl is-active --quiet service hostapd && [[ -f /etc/hostapd/hostapd.conf ]]; then . /etc/hostapd/hostapd.conf @@ -185,19 +186,31 @@ fi # Display IP addresses IFS='|' read -r ipv4s ipv6s <<< "${ip_address}" -if [[ -n ${ipv4s} ]]; then - all_ip_address=" IPv4 addresses: " - all_ip_address+="\x1B[93m(LAN)\x1B[0m \x1B[92m${ipv4s// /, }\x1B[0m " +# remove WAN IPv4 from the list of all IPv4 +if [[ "${ipv4s}" == *${wan_ip_address}* ]]; then + ipv4s=$(echo $ipv4s | sed "s/"${wan_ip_address}"//g" | xargs ) +fi +if [[ -n ${ipv4s} || -n ${wan_ip_address} ]]; then + all_ip_address=" IPv4: " + if [[ -n ${ipv4s} ]]; then + all_ip_address+=" \x1B[93m(LAN)\x1B[0m " + fi + all_ip_address+="\x1B[92m${ipv4s// /, }\x1B[0m " if [[ -n ${wan_ip_address} ]]; then all_ip_address+="\x1B[93m(WAN)\x1B[0m \x1B[95m${wan_ip_address}\x1B[0m " fi echo -e "${all_ip_address}" fi +# remove WAN IPv6 from the list of all IPv6 +if [[ -n "${wan_ip6_address}" && "${ipv6s}" == *${wan_ip6_address}* ]]; then + ipv6s=$(echo $ipv6s | sed "s/"${wan_ip6_address}"//g" | xargs ) +fi + if [[ -n ${ipv6s} ]]; then - all_ip6_address=" IPv6 addresses: " - all_ip6_address+="\x1B[93m(All)\x1B[0m \x1B[96m${ipv6s// /, }\x1B[0m " + all_ip6_address=" IPv6: " + all_ip6_address+="\x1B[96m${ipv6s// /, }\x1B[0m " if [[ -n ${wan_ip6_address} ]]; then - all_ip6_address+="\x1B[93m(Outgoing WAN)\x1B[0m \x1B[95m${wan_ip6_address}\x1B[0m " + all_ip6_address+="\x1B[93m(WAN)\x1B[0m \x1B[95m${wan_ip6_address}\x1B[0m " fi echo -e "${all_ip6_address}" fi