Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Update MOTD to include IPv6 local addresses #7315

Merged
merged 3 commits into from
Oct 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions packages/bsp/common/etc/update-motd.d/10-armbian-header
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ VENDORTEMP="${VENDOR}"

if [[ -f /etc/armbian-distribution-status ]]; then
. /etc/armbian-distribution-status
# Fina a way that works
# Find a way that works
[[ -f /etc/lsb-release ]] && DISTRIBUTION_CODENAME=$(grep CODENAME /etc/lsb-release | cut -d"=" -f2)
[[ -f /etc/lsb-release ]] && DISTRIBUTION_ID=$(grep DISTRIB_ID /etc/lsb-release | cut -d"=" -f2)
[[ -z "$DISTRIBUTION_CODENAME" && -f /etc/os-release ]] && DISTRIBUTION_CODENAME=$(grep VERSION_CODENAME /etc/os-release | cut -d"=" -f2)
Expand Down Expand Up @@ -60,21 +60,24 @@ function get_wan_address() {
} # get wan ip address

function get_ip_addresses() {
local ips=()
local ipv4s=()
local ipv6s=()

for f in /sys/class/net/*; do
local intf=$(basename $f)
# match only interface names "dummy0" and "lo"
# match only interface names
if [[ $intf =~ $HIDE_IP_PATTERN ]]; then
continue
else
local tmp=$(ip -4 addr show dev $intf | grep -v "$intf:avahi" | awk '/inet/ {print $2}' | cut -d'/' -f1 | uniq)
# add both name and IP - can be informative but becomes ugly with long persistent/predictable device names
#[[ -n $tmp ]] && ips+=("$intf: $tmp")
# add IP only
[[ -n $tmp ]] && ips+=("$tmp")
local ipv4=$(ip -4 addr show dev $intf | grep -v "$intf:avahi" | awk '/inet/ {print $2}' | cut -d'/' -f1 | uniq)
local ipv6=$(ip -6 addr show dev $intf | grep -v "$intf:avahi" | awk '/inet6/ {print $2}' | cut -d'/' -f1 | uniq)

[[ -n $ipv4 ]] && ipv4s+=("$ipv4")
[[ -n $ipv6 ]] && ipv6s+=("$ipv6")
fi
done
echo "${ips[@]}"

echo "${ipv4s[@]}|${ipv6s[@]}"
} # get_ip_addresses

# Read Armbian kernel version
Expand Down Expand Up @@ -147,7 +150,8 @@ if [[ -n $HARDWARE_STATUS ]]; then
echo -e " Support: $HARDWARE_STATUS"
fi

echo -en " IP addresses: \x1B[93m(LAN)\x1B[0m \x1B[92m$ip_address\x1B[0m "
IFS='|' read -r ipv4s ipv6s <<< "$ip_address"
echo -en " IP addresses: \x1B[93m(LAN)\x1B[0m IPv4: \x1B[92m${ipv4s// /, }\x1B[0m IPv6: \x1B[96m${ipv6s// /, }\x1B[0m"
if [[ -n $wan_ip_address ]]; then
echo -e "\x1B[93m(WAN)\x1B[0m $wan_ip_address"
fi
Expand Down