bmx7-dnsupdate: add package 5923/head
authorPaul Spooren <spooren@informatik.uni-leipzig.de>
Mon, 16 Apr 2018 08:34:26 +0000 (17:34 +0900)
committerPaul Spooren <spooren@informatik.uni-leipzig.de>
Tue, 17 Apr 2018 06:13:44 +0000 (15:13 +0900)
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>
utils/bmx7-dnsupdate/Makefile [new file with mode: 0644]
utils/bmx7-dnsupdate/files/etc/init.d/bmx7-dnsupdate [new file with mode: 0755]
utils/bmx7-dnsupdate/files/usr/bin/bmx7-dnsupdate [new file with mode: 0755]

diff --git a/utils/bmx7-dnsupdate/Makefile b/utils/bmx7-dnsupdate/Makefile
new file mode 100644 (file)
index 0000000..c9c024b
--- /dev/null
@@ -0,0 +1,27 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=bmx7-dnsupdate
+PKG_VERSION:=0.1
+PKG_RELEASE:=1
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/bmx7-dnsupdate
+  SECTION:=utils
+  CATEGORY:=Utilities
+  TITLE:=bmx7-dnsupdate
+  MAINTAINER:=Paul Spooren <spooren@informatik.uni-leipzig.de>
+  DEPENDS:=+bmx7 +bmx7-json inotifywait jshn
+endef
+
+define Build/Compile
+endef
+
+define Build/Configure
+endef
+
+define Package/bmx7-dnsupdate/install
+       $(CP) files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,bmx7-dnsupdate))
diff --git a/utils/bmx7-dnsupdate/files/etc/init.d/bmx7-dnsupdate b/utils/bmx7-dnsupdate/files/etc/init.d/bmx7-dnsupdate
new file mode 100755 (executable)
index 0000000..551395f
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh /etc/rc.common
+START=92
+USE_PROCD=1
+
+BIN=/usr/bin/bmx7-dnsupdate
+
+start_service() {
+       procd_open_instance "bmx7-dnsupdate"
+       procd_set_param command "$BIN"
+       procd_set_param stdout 1
+       procd_set_param stderr 1
+       procd_set_param respawn
+       procd_close_instance
+}
diff --git a/utils/bmx7-dnsupdate/files/usr/bin/bmx7-dnsupdate b/utils/bmx7-dnsupdate/files/usr/bin/bmx7-dnsupdate
new file mode 100755 (executable)
index 0000000..3433fe7
--- /dev/null
@@ -0,0 +1,29 @@
+#!/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