wg-installer: add hotplug script for olsr
authorNick Hainke <vincent@systemli.org>
Thu, 6 Jan 2022 21:03:18 +0000 (22:03 +0100)
committerNick Hainke <vincent@systemli.org>
Thu, 6 Jan 2022 21:44:48 +0000 (22:44 +0100)
Add hotplug-olsrd to automatically mesh with olsrd via new wireguard
links.

Signed-off-by: Nick Hainke <vincent@systemli.org>
(cherry picked from commit d35c22951bfabb9b34133471fe1e389909d2007b)

net/wg-installer/Makefile
net/wg-installer/wg-server/hotplug.d/99-mesh-olsrd [new file with mode: 0644]

index b39a8903cdf273327610a80c328fff173ede7000..dc1983b4408c80c61208c94994ccde59d3ed1c17 100644 (file)
@@ -58,6 +58,16 @@ define Package/wg-installer-server-hotplug-babeld/install
        $(INSTALL_BIN) ./wg-server/hotplug.d/99-mesh-babeld $(1)/etc/hotplug.d/net/99-mesh-babeld
 endef
 
+define Package/wg-installer-server-hotplug-olsrd
+       $(call Package/wg-installer-server)
+       DEPENDS:=wg-installer-server
+endef
+
+define Package/wg-installer-server-hotplug-olsrd/install
+       $(INSTALL_DIR) $(1)/etc/hotplug.d/net/
+       $(INSTALL_BIN) ./wg-server/hotplug.d/99-mesh-olsrd $(1)/etc/hotplug.d/net/99-mesh-olsrd
+endef
+
 define Package/wg-installer-client
        $(call Package/wg-installer/Default)
        TITLE+= (client)
@@ -78,4 +88,5 @@ endef
 
 $(eval $(call BuildPackage,wg-installer-server))
 $(eval $(call BuildPackage,wg-installer-server-hotplug-babeld))
+$(eval $(call BuildPackage,wg-installer-server-hotplug-olsrd))
 $(eval $(call BuildPackage,wg-installer-client))
diff --git a/net/wg-installer/wg-server/hotplug.d/99-mesh-olsrd b/net/wg-installer/wg-server/hotplug.d/99-mesh-olsrd
new file mode 100644 (file)
index 0000000..648ef69
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+# check if wireguard
+if [ "${DEVTYPE}" != "wireguard" ]; then
+       exit 0
+fi
+
+# check if correct naming
+slicedint=$(echo $INTERFACE | cut -c1-3)
+if [ "${slicedint}" != "wg_" ]; then
+       exit 0
+fi
+
+if [ "${ACTION}" == "add" ]; then
+       uci add olsrd Interface
+       uci set olsrd.@Interface[-1].ignore=0
+       uci set olsrd.@Interface[-1].interface="${INTERFACE}"
+       uci set olsrd.@Interface[-1].Mode="ether"
+       uci commit
+       /etc/init.d/olsrd reload
+fi
+
+if [ "${ACTION}" == "remove" ]; then
+       i=0
+       while uci get olsrd.@Interface[$i] &> /dev/null ; do
+               if [ "$(uci get olsrd.@Interface[$i].interface)" == "${INTERFACE}" ]; then
+                       uci delete olsrd.@Interface[$i]
+               fi
+               i=$((i+1));
+       done
+       uci commit
+       /etc/init.d/olsrd reload
+fi