From patchwork Sat May 14 12:32:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [2/7] fff-nodewatcher: style: unify to tabs From: Tim Niemeyer X-Patchwork-Id: 118 Message-Id: <1463229144-29414-2-git-send-email-tim@tn-x.org> To: franken-dev@freifunk.net Cc: Tim Niemeyer Date: Sat, 14 May 2016 14:32:19 +0200 Signed-off-by: Tim Niemeyer Reviewed-by: Tobias Klaus --- .../fff/fff-nodewatcher/files/usr/sbin/nodewatcher | 192 ++++++++++----------- 1 file changed, 96 insertions(+), 96 deletions(-) diff --git a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher index 1610055..0b463b7 100755 --- a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher +++ b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher @@ -22,13 +22,13 @@ else fi if [ $SCRIPT_ERROR_LEVEL -gt "1" ]; then - err() { - echo $1 >> $SCRIPT_LOGFILE - } + err() { + echo $1 >> $SCRIPT_LOGFILE + } else - err() { - : - } + err() { + : + } fi #this method checks id the logfile has bekome too big and deletes the first X lines @@ -36,7 +36,7 @@ delete_log() { if [ -f $SCRIPT_LOGFILE ]; then if [ `ls -la $SCRIPT_LOGFILE | awk '{ print $5 }'` -gt "6000" ]; then sed -i '1,60d' $SCRIPT_LOGFILE - err "`date`: Logfile has been made smaller" + err "`date`: Logfile has been made smaller" fi fi } @@ -75,24 +75,24 @@ crawl() { contact="$contact" fi uptime=$(awk '{ printf ""$1""$2"" }' /proc/uptime) - - memory=$(awk ' - /^MemTotal/ { printf ""$2"" } - /^Cached:/ { printf ""$2"" } - /^Buffers/ { printf ""$2"" } - /^MemFree/ { printf ""$2"" } - ' /proc/meminfo) + + memory=$(awk ' + /^MemTotal/ { printf ""$2"" } + /^Cached:/ { printf ""$2"" } + /^Buffers/ { printf ""$2"" } + /^MemFree/ { printf ""$2"" } + ' /proc/meminfo) cpu=$(awk -F': ' ' - /model/ { printf ""$2"" } - /system type/ { printf ""$2"" } - ' /proc/cpuinfo) + /model/ { printf ""$2"" } + /system type/ { printf ""$2"" } + ' /proc/cpuinfo) model="$(cat /var/sysinfo/model)" local_time="`date +%s`" load=$(awk '{ printf ""$3""$4"" }' /proc/loadavg) - err "`date`: Collecting version information" + err "`date`: Collecting version information" - batman_adv_version=$(cat /sys/module/batman_adv/version) + batman_adv_version=$(cat /sys/module/batman_adv/version) kernel_version=$(uname -r) fastd_version=$(fastd -v | awk '{ print $2 }') nodewatcher_version=$SCRIPT_VERSION @@ -101,91 +101,91 @@ crawl() { status_text="$(cat "$SCRIPT_STATUS_FILE")" fi - # example for /etc/openwrt_release: - #DISTRIB_ID="OpenWrt" - #DISTRIB_RELEASE="Attitude Adjustment" - #DISTRIB_REVISION="r35298" - #DISTRIB_CODENAME="attitude_adjustment" - #DISTRIB_TARGET="atheros/generic" - #DISTRIB_DESCRIPTION="OpenWrt Attitude Adjustment 12.09-rc1" + # example for /etc/openwrt_release: + #DISTRIB_ID="OpenWrt" + #DISTRIB_RELEASE="Attitude Adjustment" + #DISTRIB_REVISION="r35298" + #DISTRIB_CODENAME="attitude_adjustment" + #DISTRIB_TARGET="atheros/generic" + #DISTRIB_DESCRIPTION="OpenWrt Attitude Adjustment 12.09-rc1" . /etc/openwrt_release - distname=$DISTRIB_ID - distversion=$DISTRIB_RELEASE - - # example for /etc/firmware_release: - #FIRMWARE_VERSION="95f36685e7b6cbf423f02cf5c7f1e785fd4ccdae-dirty" - #BUILD_DATE="build date: Di 29. Jan 19:33:34 CET 2013" - #OPENWRT_CORE_REVISION="35298" - #OPENWRT_FEEDS_PACKAGES_REVISION="35298" + distname=$DISTRIB_ID + distversion=$DISTRIB_RELEASE + + # example for /etc/firmware_release: + #FIRMWARE_VERSION="95f36685e7b6cbf423f02cf5c7f1e785fd4ccdae-dirty" + #BUILD_DATE="build date: Di 29. Jan 19:33:34 CET 2013" + #OPENWRT_CORE_REVISION="35298" + #OPENWRT_FEEDS_PACKAGES_REVISION="35298" . /etc/firmware_release SYSTEM_DATA="online$status_text$hostname${description}${geo}${position_comment}${contact}$distname$distversion$cpu$model$memory$load$uptime$local_time$batman_adv_version$kernel_version$fastd_version$nodewatcher_version$FIRMWARE_VERSION$FIRMWARE_COMMUNITY$BUILD_DATE$OPENWRT_CORE_REVISION$OPENWRT_FEEDS_PACKAGES_REVISION" - err "`date`: Collecting information from network interfaces" + err "`date`: Collecting information from network interfaces" #Get interfaces interface_data="" #Loop interfaces - 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 - - #Get interface data for whitelisted interfaces - awkscript=' - /ether/ { printf ""$2"" } - /mtu/ { printf ""$5"" }' - if inArray "$IPWHITELIST" "$iface"; then - awkscript=$awkscript' - /inet / { split($2, a, "/"); printf ""a[1]"" } - /inet6/ && /scope global/ { printf ""$2"" } - /inet6/ && /scope link/ { printf ""$2""}' - fi - addrs=$(ip addr show dev ${iface} | awk "$awkscript") - - traffic_rx=`cat $ifpath/statistics/rx_bytes` - traffic_tx=`cat $ifpath/statistics/tx_bytes` - - interface_data=$interface_data"<$iface>$iface$addrs$traffic_rx$traffic_tx" - - interface_data=$interface_data$(iwconfig ${iface} 2>/dev/null | awk -F':' ' - /Mode/{ split($2, m, " "); printf ""m[1]"" } - /Cell/{ split($0, c, " "); printf ""c[5]"" } - /ESSID/ { split($0, e, "\""); printf ""e[2]"" } - /Freq/{ split($3, f, " "); printf ""f[1]f[2]"" } - /Tx-Power/{ split($0, p, "="); sub(/[[:space:]]*$/, "", p[2]); printf ""p[2]"" } - ')"" + 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 + + #Get interface data for whitelisted interfaces + awkscript=' + /ether/ { printf ""$2"" } + /mtu/ { printf ""$5"" }' + if inArray "$IPWHITELIST" "$iface"; then + awkscript=$awkscript' + /inet / { split($2, a, "/"); printf ""a[1]"" } + /inet6/ && /scope global/ { printf ""$2"" } + /inet6/ && /scope link/ { printf ""$2""}' + fi + addrs=$(ip addr show dev ${iface} | awk "$awkscript") + + traffic_rx=`cat $ifpath/statistics/rx_bytes` + traffic_tx=`cat $ifpath/statistics/tx_bytes` + + interface_data=$interface_data"<$iface>$iface$addrs$traffic_rx$traffic_tx" + + interface_data=$interface_data$(iwconfig ${iface} 2>/dev/null | awk -F':' ' + /Mode/{ split($2, m, " "); printf ""m[1]"" } + /Cell/{ split($0, c, " "); printf ""c[5]"" } + /ESSID/ { split($0, e, "\""); printf ""e[2]"" } + /Freq/{ split($3, f, " "); printf ""f[1]f[2]"" } + /Tx-Power/{ split($0, p, "="); sub(/[[:space:]]*$/, "", p[2]); printf ""p[2]"" } + ')"" done - err "`date`: Collecting information from batman advanced and it´s interfaces" + err "`date`: Collecting information from batman advanced and it´s interfaces" #B.A.T.M.A.N. advanced - if [ -f /sys/module/batman_adv/version ]; then - for iface in $(grep active /sys/class/net/*/batman_adv/iface_status); do - status=${iface#*:} - iface=${iface%/batman_adv/iface_status:active} - iface=${iface#/sys/class/net/} - BATMAN_ADV_INTERFACES=$BATMAN_ADV_INTERFACES"<$iface>$iface$status" - done - - # Build a list of direct neighbors - batman_adv_originators=$(awk \ - 'BEGIN { FS=" "; i=0 } # set the delimiter to " " - /O/ { next } # ignore lines with O (will remove second line) - /B/ { next } # ignore line with B (will remove first line) - { sub("\\(", "", $0) # remove parentheses - sub("\\)", "", $0) - sub("\\[", "", $0) - sub("\\]:", "", $0) - sub(" ", " ", $0) - o=$1".*"$1 # build a regex to find lines that contains the $1 (=originator) twice - if ($0 ~ o) # filter for this regex (will remove entries without direct neighbor) - { - printf ""$1""$3""$4""$2""$5"" - i++ - } - }' /sys/kernel/debug/batman_adv/bat0/originators) - + if [ -f /sys/module/batman_adv/version ]; then + for iface in $(grep active /sys/class/net/*/batman_adv/iface_status); do + status=${iface#*:} + iface=${iface%/batman_adv/iface_status:active} + iface=${iface#/sys/class/net/} + BATMAN_ADV_INTERFACES=$BATMAN_ADV_INTERFACES"<$iface>$iface$status" + done + + # Build a list of direct neighbors + batman_adv_originators=$(awk \ + 'BEGIN { FS=" "; i=0 } # set the delimiter to " " + /O/ { next } # ignore lines with O (will remove second line) + /B/ { next } # ignore line with B (will remove first line) + { sub("\\(", "", $0) # remove parentheses + sub("\\)", "", $0) + sub("\\[", "", $0) + sub("\\]:", "", $0) + sub(" ", " ", $0) + o=$1".*"$1 # build a regex to find lines that contains the $1 (=originator) twice + if ($0 ~ o) # filter for this regex (will remove entries without direct neighbor) + { + printf ""$1""$3""$4""$2""$5"" + i++ + } + }' /sys/kernel/debug/batman_adv/bat0/originators) + batman_adv_gateway_mode=$(batctl gw) batman_adv_gateway_list=$(awk \ @@ -202,8 +202,8 @@ crawl() { printf ""$1""$2""$3""$4""$5""$6" "$7" "$8"" i++ }' /sys/kernel/debug/batman_adv/bat0/gateways) - fi - err "`date`: Collecting information about conected clients" + fi + err "`date`: Collecting information about conected clients" #CLIENTS client_count=0 for clientif in ${CLIENT_INTERFACES}; do @@ -211,7 +211,7 @@ crawl() { client_count=$((client_count + $cc)) done - err "`date`: Putting all information into a XML-File and save it at "$SCRIPT_DATA_FILE + err "`date`: Putting all information into a XML-File and save it at "$SCRIPT_DATA_FILE DATA="$SYSTEM_DATA$interface_data$BATMAN_ADV_INTERFACES$batman_adv_originators$batman_adv_gateway_mode$batman_adv_gateway_list$client_count"