From c3a8d55f3a605323060d334183706f400335a313 Mon Sep 17 00:00:00 2001 From: Werner Date: Tue, 11 Sep 2018 22:25:31 +0200 Subject: [PATCH] Allow interface selection on NetworkMonitorMode (#1108) When running armbianmonitor -N/n and two or more routable network interfaces are detected create a dynamic dialog box to select which interface should be monitored. Otherwise proceed as usual. Also reverts #1106 --- packages/bsp/common/usr/bin/armbianmonitor | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/bsp/common/usr/bin/armbianmonitor b/packages/bsp/common/usr/bin/armbianmonitor index 05e67a28aa6b..9dbc369d4629 100755 --- a/packages/bsp/common/usr/bin/armbianmonitor +++ b/packages/bsp/common/usr/bin/armbianmonitor @@ -1025,14 +1025,32 @@ VerifyInstallation() { } # VerifyInstallation NetworkMonitorMode() { - + # Allow armbianmonitor to return back to armbian-config trap "echo ; exit 0" 0 1 2 3 15 timerStart kickAllStatsDown - iface=$(route -n | egrep UG | egrep -o "[a-zA-Z0-9]*$" | head -n 1) + + # Count interfaces - multiple routes causing interfaces to show up more than once, filtering... + ifacecount=$(route -n | egrep UG | egrep -o "[a-zA-Z0-9]*$" | sort | uniq) + # If there are two ore more interfaces detected open a dynamic dialog box to select which to monitor + if [ "$(echo -e $ifacecount | tr ' ' '\n' | wc -l)" -gt 1 ]; then + ifacemenu=$(route -n | egrep UG | egrep -o "[a-zA-Z0-9]*$" | sort | uniq | awk '{a[$1]=$1}END{for(i in a)printf i" "a[i]" "}') + ifacefunc() { + dialog --backtitle "Interface selector" \ + --title "Multiple network interfaces detected" \ + --menu "Choose which interface to monitor:" \ + 15 50 $(route -n | egrep UG | egrep -o "[a-zA-Z0-9]*$" | sort | uniq | wc -l) \ + $(echo $ifacemenu) 2>&1 >$(tty) + } + iface=$(ifacefunc) + else + # Use default behavior if one interface is found only + iface=$(route -n | egrep UG | egrep -o "[a-zA-Z0-9]*$") + fi printf "\nruntime network statistics: $(uname -n)\n" + printf "network interface: $(echo $iface)\n" printf "[tap 'd' to display column headings]\n" printf "[tap 'z' to reset counters]\n" printf "[use to exit]\n"