diff options
author | Hannu Nyman <hannu.nyman@iki.fi> | 2015-11-20 22:01:27 +0200 |
---|---|---|
committer | Hannu Nyman <hannu.nyman@iki.fi> | 2015-11-20 22:01:27 +0200 |
commit | 6f49ab92e5616cf1a65538da4d7c3ce99a01cd83 (patch) | |
tree | c21650588ccc4b93772bcb59b5b660a084c388d8 | |
parent | f16405df915f5b60b85296e29382137eb3132011 (diff) | |
parent | e0bcfe82fbc15bdda8638a6731a76200505c13e7 (diff) |
Merge pull request #554 from bittorf/better_neigh.sh
freifunk-common: neigh.sh - show hostnames
-rwxr-xr-x | contrib/package/freifunk-common/files/usr/bin/neigh.sh | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/contrib/package/freifunk-common/files/usr/bin/neigh.sh b/contrib/package/freifunk-common/files/usr/bin/neigh.sh index cf4342450c..b1dc01a77e 100755 --- a/contrib/package/freifunk-common/files/usr/bin/neigh.sh +++ b/contrib/package/freifunk-common/files/usr/bin/neigh.sh @@ -2,9 +2,69 @@ . /usr/share/libubox/jshn.sh -VARS="localIP:Local remoteIP:Remote validityTime:vTime linkQuality:LQ neighborLinkQuality:NLQ linkCost:Cost" +hostsfile_getname() +{ + local config="$1" + local i=0 + local value file -for HOST in 127.0.0.1 ::1;do + while value="$( uci -q get $config.@LoadPlugin[$i].library )"; do { + case "$value" in + 'olsrd_nameservice.so.'*) + file="$( uci -q get $config.@LoadPlugin[$i].hosts_file )" + break + ;; + esac + + i=$(( i + 1 )) + } done + + echo "${file:-/var/run/hosts_olsr}" +} + +read_hostnames() +{ + local file_list=" $( hostsfile_getname 'olsrd' ) $(hostsfile_getname 'olsrd6' ) " + local line ip hostname file file_list_uniq + + for file in $file_list; do { + case " $file_list_uniq " in + *" $file "*) + ;; + *) + file_list_uniq="$file_list_uniq $file" + ;; + esac + } done + + for file in $file_list_uniq; do { + [ -e "$file" ] || continue + + while read -r line; do { + case "$line" in + [0-9]*) + # 2001:bf7:820:901::1 stuttgarter-core.olsr # myself + # 10.63.160.161 AlexLaterne # 10.63.160.161 + set -f + set +f -- $line + ip="$1" + hostname="$2" + + # global vars, e.g. + # IP_1_2_3_4='foo' or IP_2001_bf7_820_901__1='bar' + eval IP_${ip//[.:]/_}="$hostname" + ;; + esac + } done <"$file" + } done +} + +read_hostnames + +VARS='localIP:Local remoteIP:Remote validityTime:vTime linkQuality:LQ' +VARS="$VARS neighborLinkQuality:NLQ linkCost:Cost remoteHostname:Host" + +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 @@ -29,6 +89,7 @@ for HOST in 127.0.0.1 ::1;do ;;*) for v in ${VARS};do eval printf \"%-\${_${v%:*}}s \" \$${v%:*} + eval remoteHostname="\$IP_${remoteIP//[.:]/_}" done echo ;;esac |