package/freifunk-common: neigh.sh: fix for missing .. as well as aligned headers
authorPatrick Grimm <patrick@lunatiki.de>
Mon, 14 Oct 2013 17:29:40 +0000 (17:29 +0000)
committerPatrick Grimm <patrick@lunatiki.de>
Mon, 14 Oct 2013 17:29:40 +0000 (17:29 +0000)
contrib/package/freifunk-common/files/usr/bin/neigh.sh

index 4c734ae221499c008f397dd30a5b450f95747ee2..cf4342450cddc5ff1f6c96ea531120a7a970af13 100755 (executable)
@@ -2,21 +2,40 @@
 
 . /usr/share/libubox/jshn.sh
 
+VARS="localIP:Local remoteIP:Remote validityTime:vTime linkQuality:LQ neighborLinkQuality:NLQ linkCost:Cost"
+
 for HOST in 127.0.0.1 ::1;do
        json_init
        json_load "$(echo /links|nc ${HOST} 9090)"
        if json_is_a links array;then
-               echo "LocalIP           RemoteIP        vTime   LQ              NLQ             Cost"
                json_select links
-               i=1
-               while json_is_a ${i} object;do
-                       json_select ${i}
-                       json_get_vars localIP remoteIP validityTime linkQuality neighborLinkQuality linkCost
-                       echo "${localIP}        ${remoteIP}     ${validityTime} ${linkQuality}  ${neighborLinkQuality}  ${linkCost}"
-                       json_select 
-                       i=$(( i + 1 ))
+               for v in ${VARS};do
+                       eval _${v%:*}=0
+               done
+               for j in 0 1;do
+                       case ${j} in 1)
+                               for v in ${VARS};do
+                                       eval printf \"%-\${_${v%:*}}s \" ${v#*:}
+                               done
+                               echo
+                       ;;esac
+                       i=1;while json_is_a ${i} object;do
+                               json_select ${i}
+                               json_get_vars $(for v in ${VARS};do echo ${v%:*};done)
+                               case ${j} in 0)
+                                       for v in ${VARS};do
+                                               eval "test \${_${v%:*}} -lt \${#${v%:*}} && _${v%:*}=\${#${v%:*}}"
+                                       done
+                               ;;*)
+                                       for v in ${VARS};do
+                                               eval printf \"%-\${_${v%:*}}s \" \$${v%:*}
+                                       done
+                                       echo
+                               ;;esac
+                               json_select ..
+                               i=$(( i + 1 ))
+                       done
                done
        fi
        echo
 done
-