zerotier: fix multiple instance handling and port setting 6930/head
authorMoritz Warning <moritzwarning@web.de>
Sun, 9 Sep 2018 09:32:38 +0000 (11:32 +0200)
committerMoritz Warning <moritzwarning@web.de>
Sun, 9 Sep 2018 09:32:38 +0000 (11:32 +0200)
Signed-off-by: Moritz Warning <moritzwarning@web.de>
net/zerotier/Makefile
net/zerotier/files/etc/config/zerotier [new file with mode: 0644]
net/zerotier/files/etc/init.d/zerotier [new file with mode: 0755]
net/zerotier/files/zerotier.config [deleted file]
net/zerotier/files/zerotier.init [deleted file]

index 816b1818393c79a93ba5520b783dd4097c562990..c5725aad981fe2c53c024ec953514e2b31655462 100644 (file)
@@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=zerotier
 PKG_VERSION:=1.2.12
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_LICENSE:=GPL-3.0
 
@@ -66,10 +66,7 @@ ifeq ($(CONFIG_ZEROTIER_ENABLE_SELFTEST),y)
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/zerotier-selftest $(1)/usr/bin/
 endif
 
-       $(INSTALL_DIR) $(1)/etc/init.d/
-       $(INSTALL_BIN) files/zerotier.init $(1)/etc/init.d/zerotier
-       $(INSTALL_DIR) $(1)/etc/config
-       $(INSTALL_CONF) files/zerotier.config $(1)/etc/config/zerotier
+       $(CP) ./files/* $(1)/
 endef
 
 $(eval $(call BuildPackage,zerotier))
diff --git a/net/zerotier/files/etc/config/zerotier b/net/zerotier/files/etc/config/zerotier
new file mode 100644 (file)
index 0000000..1a016eb
--- /dev/null
@@ -0,0 +1,15 @@
+
+config zerotier sample_config
+       option enabled 0
+
+       # persistent configuration folder (for ZT controller mode)
+       #option config_path '/etc/zerotier'
+
+       #option port '9993'
+
+       # Generate secret on first start
+       option secret ''
+
+       # Join a public network called Earth
+       list join '8056c2e21c000001'
+       #list join '<other_network>'
diff --git a/net/zerotier/files/etc/init.d/zerotier b/net/zerotier/files/etc/init.d/zerotier
new file mode 100755 (executable)
index 0000000..ba6b427
--- /dev/null
@@ -0,0 +1,103 @@
+#!/bin/sh /etc/rc.common
+
+START=90
+
+USE_PROCD=1
+
+PROG=/usr/bin/zerotier-one
+CONFIG_PATH=/var/lib/zerotier-one
+
+section_enabled() {
+       config_get_bool enabled "$1" 'enabled' 0
+       [ $enabled -ne 0 ]
+}
+
+start_instance() {
+       local cfg="$1"
+       local port secret config_path path
+       local args=""
+
+       if ! section_enabled "$cfg"; then
+               echo "disabled in config"
+               return 1
+       fi
+
+       config_get config_path $cfg 'config_path'
+       config_get port $cfg 'port'
+       config_get secret $cfg 'secret'
+
+       path=${CONFIG_PATH}_$cfg
+
+       # Remove existing link or folder
+       rm -rf $path
+
+       # Create link from CONFIG_PATH to config_path
+       if [ -n "$config_path" -a "$config_path" != "$path" ]; then
+               if [ ! -d "$config_path" ]; then
+                       echo "ZeroTier config_path does not exist: $config_path" 1>&2
+                       return
+               fi
+
+               ln -s $config_path $path
+       fi
+
+       mkdir -p $path/networks.d
+
+       # link latest default config path to latest config path
+       rm -f $CONFIG_PATH
+       ln -s $path $CONFIG_PATH
+
+       if [ -n "$port" ]; then
+               args="$args -p${port}"
+       fi
+
+       if [ -z "$secret" ]; then
+               echo "Generate secret - please wait..."
+               local sf="/tmp/zt.$cfg.secret"
+
+               zerotier-idtool generate "$sf" > /dev/null
+               [ $? -ne 0 ] && return 1
+
+               secret="$(cat $sf)"
+               rm "$sf"
+
+               uci set zerotier.$cfg.secret="$secret"
+               uci commit zerotier
+       fi
+
+       if [ -n "$secret" ]; then
+               echo "$secret" > $path/identity.secret
+               # make sure there is not previous identity.public
+               rm -f $path/identity.public
+       fi
+
+       add_join() {
+               # an (empty) config file will cause ZT to join a network
+               touch $path/networks.d/$1.conf
+       }
+
+       config_list_foreach $cfg 'join' add_join
+
+       procd_open_instance
+       procd_set_param command $PROG $args $path
+       procd_set_param stderr 1
+       procd_close_instance
+}
+
+start_service() {
+       config_load 'zerotier'
+       config_foreach start_instance 'zerotier'
+}
+
+stop_instance() {
+       local cfg="$1"
+
+       # Remove existing link or folder
+       rm -rf ${CONFIG_PATH}_${cfg}
+}
+
+stop_service() {
+       config_load 'zerotier'
+       config_foreach stop_instance 'zerotier'
+       rm -f ${CONFIG_PATH}
+}
diff --git a/net/zerotier/files/zerotier.config b/net/zerotier/files/zerotier.config
deleted file mode 100644 (file)
index b62e155..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-
-config zerotier sample_config
-       option enabled 0
-
-       # persistent configuration folder (for ZT controller mode)
-       #option config_path '/etc/zerotier'
-
-       #option port '9993'
-
-       # Generate secret on first start
-       option secret 'generate'
-
-       # Join a public network called Earth
-       list join '8056c2e21c000001'
diff --git a/net/zerotier/files/zerotier.init b/net/zerotier/files/zerotier.init
deleted file mode 100644 (file)
index 390dbd3..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/bin/sh /etc/rc.common
-
-START=90
-
-USE_PROCD=1
-
-PROG=/usr/bin/zerotier-one
-CONFIG_PATH=/var/lib/zerotier-one
-
-section_enabled() {
-       config_get_bool enabled "$1" 'enabled' 0
-       [ $enabled -gt 0 ]
-}
-
-start_instance() {
-       local cfg="$1"
-       local port secret config_path
-       local ARGS=""
-
-       if ! section_enabled "$cfg"; then
-               echo "disabled in config"
-               return 1
-       fi
-
-       config_get config_path $cfg 'config_path'
-       config_get_bool port $cfg 'port'
-       config_get secret $cfg 'secret'
-
-       # Remove existing link or folder
-       rm -rf $CONFIG_PATH
-
-       # Create link from CONFIG_PATH to config_path
-       if [ -n "$config_path" -a "$config_path" != $CONFIG_PATH ]; then
-               if [ ! -d "$config_path" ]; then
-                       echo "ZeroTier config_path does not exist: $config_path"
-                       return
-               fi
-
-               ln -s $config_path $CONFIG_PATH
-       fi
-
-       mkdir -p $CONFIG_PATH/networks.d
-
-       if [ -n "$port" ]; then
-               ARGS="$ARGS -p$port"
-       fi
-
-       if [ "$secret" = "generate" ]; then
-               echo "Generate secret - please wait..."
-               local sf="/tmp/zt.$cfg.secret"
-
-               zerotier-idtool generate "$sf" > /dev/null
-               [ $? -ne 0 ] && return 1
-
-               secret="$(cat $sf)"
-               rm "$sf"
-
-               uci set zerotier.$cfg.secret="$secret"
-               uci commit zerotier
-       fi
-
-       if [ -n "$secret" ]; then
-               echo "$secret" > $CONFIG_PATH/identity.secret
-               # make sure there is not previous identity.public
-               rm -f $CONFIG_PATH/identity.public
-       fi
-
-       add_join() {
-               # an (empty) config file will cause ZT to join a network
-               touch $CONFIG_PATH/networks.d/$1.conf
-       }
-
-       config_list_foreach $cfg 'join' add_join
-
-       procd_open_instance
-       procd_set_param command $PROG $ARGS $CONFIG_PATH
-       procd_set_param stderr 1
-       procd_close_instance
-}
-
-start_service() {
-       config_load 'zerotier'
-       config_foreach start_instance 'zerotier'
-}
-
-stop_instance() {
-       local cfg="$1"
-
-       # Remove existing link or folder
-       rm -rf $CONFIG_PATH
-}
-
-stop_service() {
-       config_load 'zerotier'
-       config_foreach stop_instance 'zerotier'
-}