Skip to content

Commit

Permalink
Allow interface selection on NetworkMonitorMode (#1108)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
EvilOlaf authored and Thomas Kaiser committed Sep 11, 2018
1 parent 845baff commit c3a8d55
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/bsp/common/usr/bin/armbianmonitor
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ctrl-c> to exit]\n"
Expand Down

0 comments on commit c3a8d55

Please sign in to comment.