Skip to content

Commit 1ee5216

Browse files
committed
Remove duplication of IP addresses and fix display style
1 parent 1aca285 commit 1ee5216

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

packages/bsp/common/etc/update-motd.d/10-armbian-header

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ KERNELID=$(uname -r)
108108
ip_address=$(get_ip_addresses &)
109109
wan_ip_address=$(get_wan_address &)
110110
wan_ip6_address=$(get_wan6_address &)
111+
111112
# Get access point info
112113
if systemctl is-active --quiet service hostapd && [[ -f /etc/hostapd/hostapd.conf ]]; then
113114
. /etc/hostapd/hostapd.conf
@@ -185,19 +186,31 @@ fi
185186

186187
# Display IP addresses
187188
IFS='|' read -r ipv4s ipv6s <<< "${ip_address}"
188-
if [[ -n ${ipv4s} ]]; then
189-
all_ip_address=" IPv4 addresses: "
190-
all_ip_address+="\x1B[93m(LAN)\x1B[0m \x1B[92m${ipv4s// /, }\x1B[0m "
189+
# remove WAN IPv4 from the list of all IPv4
190+
if [[ "${ipv4s}" == *${wan_ip_address}* ]]; then
191+
ipv4s=$(echo $ipv4s | sed "s/"${wan_ip_address}"//g" | xargs )
192+
fi
193+
if [[ -n ${ipv4s} || -n ${wan_ip_address} ]]; then
194+
all_ip_address=" IPv4: "
195+
if [[ -n ${ipv4s} ]]; then
196+
all_ip_address+=" \x1B[93m(LAN)\x1B[0m "
197+
fi
198+
all_ip_address+="\x1B[92m${ipv4s// /, }\x1B[0m "
191199
if [[ -n ${wan_ip_address} ]]; then
192200
all_ip_address+="\x1B[93m(WAN)\x1B[0m \x1B[95m${wan_ip_address}\x1B[0m "
193201
fi
194202
echo -e "${all_ip_address}"
195203
fi
204+
# remove WAN IPv6 from the list of all IPv6
205+
if [[ -n "${wan_ip6_address}" && "${ipv6s}" == *${wan_ip6_address}* ]]; then
206+
ipv6s=$(echo $ipv6s | sed "s/"${wan_ip6_address}"//g" | xargs )
207+
fi
208+
196209
if [[ -n ${ipv6s} ]]; then
197-
all_ip6_address=" IPv6 addresses: "
198-
all_ip6_address+="\x1B[93m(All)\x1B[0m \x1B[96m${ipv6s// /, }\x1B[0m "
210+
all_ip6_address=" IPv6: "
211+
all_ip6_address+="\x1B[96m${ipv6s// /, }\x1B[0m "
199212
if [[ -n ${wan_ip6_address} ]]; then
200-
all_ip6_address+="\x1B[93m(Outgoing WAN)\x1B[0m \x1B[95m${wan_ip6_address}\x1B[0m "
213+
all_ip6_address+="\x1B[93m(WAN)\x1B[0m \x1B[95m${wan_ip6_address}\x1B[0m "
201214
fi
202215
echo -e "${all_ip6_address}"
203216
fi

0 commit comments

Comments
 (0)