You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

95 lines
1.9 KiB

#!/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 interface config_path
local ARGS=""
section_enabled "$cfg" || return 1
config_get config_path $cfg 'config_path'
config_get_bool port $cfg 'port'
config_get secret $cfg 'secret'
config_get interface $cfg 'interface'
# 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 tmp="/tmp/zt.$cfg.secret"
zerotier-idtool generate "$tmp" > /dev/null
secret="$(cat $tmp)"
rm "$tmp"
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_add_reload_interface_trigger "$interface"
procd_set_param command $PROG $ARGS $CONFIG_PATH
procd_close_instance
}
service_triggers() {
procd_add_reload_trigger zerotier
}
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'
}