10-gluon-announced 872 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. . /usr/share/libubox/jshn.sh
  3. . /lib/functions/service.sh
  4. DEVLIST=/var/run/gluon-announced.devs
  5. DAEMON=/usr/bin/gluon-announced
  6. ifname_to_dev () {
  7. json_load "$(ubus call network.interface.$1 status)"
  8. json_get_var dev device
  9. echo "$dev"
  10. }
  11. restart_announced () {
  12. SERVICE_USE_PID=1
  13. SERVICE_WRITE_PID=1
  14. SERVICE_DAEMONIZE=1
  15. DEVS=$(cat $DEVLIST | while read dev iface;do echo -n " -i $dev";done)
  16. service_stop $DAEMON
  17. service_start $DAEMON -g ff02:0:0:0:0:0:2:1001 -p 1001 -s '/lib/gluon/announce/collect.lua nodeinfo' $DEVS
  18. }
  19. case "$ACTION" in
  20. ifdown)
  21. sed -i "/$INTERFACE/d" $DEVLIST
  22. ;;
  23. ifup)
  24. DEVICE=$(ifname_to_dev $INTERFACE)
  25. MESH=$(cat /sys/class/net/$DEVICE/batman_adv/mesh_iface)
  26. [ $MESH = "bat0" ] || exit 0
  27. DEVS="$(cat $DEVLIST; echo $DEVICE $INTERFACE)"
  28. echo "$DEVS" | sort | uniq > $DEVLIST
  29. restart_announced
  30. ;;
  31. esac