From patchwork Tue Jan 7 13:40:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [3/5] nodewatcher.d: Tiny cosmetic improvements From: Adrian Schmutzler X-Patchwork-Id: 1259 Message-Id: <20200107134024.1755-3-freifunk@adrianschmutzler.de> To: franken-dev@freifunk.net Date: Tue, 7 Jan 2020 14:40:22 +0100 This applies some tiny improvements to just-moved nodewatcher.d code: - Remove comments about obvious things - Introduce newlines to make code easier to read - Use shorter conditional syntax for easy cases Signed-off-by: Adrian Schmutzler Reviewed-by: Fabian Bläse --- .../files/usr/lib/nodewatcher.d/30-batman-adv.sh | 2 +- .../files/usr/lib/nodewatcher.d/20-interfaces.sh | 14 +++++--------- .../files/usr/lib/nodewatcher.d/10-systemdata.sh | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/packages/fff/fff-batman-adv/files/usr/lib/nodewatcher.d/30-batman-adv.sh b/src/packages/fff/fff-batman-adv/files/usr/lib/nodewatcher.d/30-batman-adv.sh index 37100a2d..5fe4d89a 100755 --- a/src/packages/fff/fff-batman-adv/files/usr/lib/nodewatcher.d/30-batman-adv.sh +++ b/src/packages/fff/fff-batman-adv/files/usr/lib/nodewatcher.d/30-batman-adv.sh @@ -7,7 +7,7 @@ debug() { } debug "$(date): Collecting information from batman advanced and its interfaces" -#B.A.T.M.A.N. advanced + if [ -f /sys/module/batman_adv/version ]; then for iface in $(batctl if | sed 's/ //'); do status=${iface##*:} diff --git a/src/packages/fff/fff-network/files/usr/lib/nodewatcher.d/20-interfaces.sh b/src/packages/fff/fff-network/files/usr/lib/nodewatcher.d/20-interfaces.sh index 5373d6ef..acb1eeeb 100755 --- a/src/packages/fff/fff-network/files/usr/lib/nodewatcher.d/20-interfaces.sh +++ b/src/packages/fff/fff-network/files/usr/lib/nodewatcher.d/20-interfaces.sh @@ -12,25 +12,21 @@ debug() { inArray() { local value for value in $1; do - if [ "$value" = "$2" ]; then - return 0 - fi + [ "$value" = "$2" ] && return 0 done return 1 } debug "$(date): Collecting information from network interfaces" -#Get interfaces interface_data="" -#Loop interfaces -#for entry in $IFACES; do + +# Loop through interfaces: for entry in $IFACES; do for filename in $(grep 'up\|unknown' /sys/class/net/*/operstate); do ifpath=${filename%/operstate*} iface=${ifpath#/sys/class/net/} - if inArray "$IFACEBLACKLIST" "$iface"; then - continue - fi + + inArray "$IFACEBLACKLIST" "$iface" && continue #Get interface data for whitelisted interfaces # shellcheck disable=SC2016 diff --git a/src/packages/fff/fff-nodewatcher/files/usr/lib/nodewatcher.d/10-systemdata.sh b/src/packages/fff/fff-nodewatcher/files/usr/lib/nodewatcher.d/10-systemdata.sh index ddc906e6..a61e1e57 100755 --- a/src/packages/fff/fff-nodewatcher/files/usr/lib/nodewatcher.d/10-systemdata.sh +++ b/src/packages/fff/fff-nodewatcher/files/usr/lib/nodewatcher.d/10-systemdata.sh @@ -9,8 +9,8 @@ debug() { (>&2 echo "$1") } -#Get system data from other locations debug "$(date): Collecting basic system status data" + hostname="$(cat /proc/sys/kernel/hostname)" mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" = "OpenWrt" ] && hostname="$mac"