Files
packages/utils/bmx7-dnsupdate/files/usr/bin/bmx7-dnsupdate
T
Paul Spooren dda234aff8 bmx7-dnsupdate: add package
Makes it easy to address bmx7 shorids and hostnames with ping, ssh, etc.
Both are stored in /tmp/hosts/ and so loaded by dnsmasq.
Instead of using a cron job which triggers the bmx7 deamon every so and
so, inotifywait is used to see creation or deletion of originators in
/var/run/bmx7/json/originators/

Signed-off-by: Paul Spooren <spooren@informatik.uni-leipzig.de>
2018-04-17 15:13:44 +09:00

30 lines
784 B
Bash
Executable File

#!/bin/sh
. /usr/share/libubox/jshn.sh
while true; do
json_load "$(bmx7 -c jshow=originators)"
json_select "originators"
idx="1"
# clean all bmx7 dns entries
> /tmp/hosts/bmx7
while json_get_type Type "$idx" && [ "$Type" == object ]; do
json_select "$idx"
json_get_var shortId shortId
json_get_var name name
json_get_var primaryIp primaryIp
printf "$primaryIp $name\n$primaryIp $shortId\n" >> /tmp/hosts/bmx7
json_select ..
$((idx++)) 2> /dev/null
done
# reload dnsmasq to apply changes
logger -t bmx7-dnsupdate "dnsmasq updated due to new hosts"
killall -HUP dnsmasq
# block until originators changes
inotifywait -e create -e delete -q /var/run/bmx7/json/originators/
done