Add file-based auto-join script to ZeroTier

This commit is contained in:
NeoTheFox 2023-05-12 16:24:41 +04:00
parent d3e7b87f09
commit e0a042098b
3 changed files with 30 additions and 2 deletions

View file

@ -27,9 +27,10 @@ makeinstall_target() {
make DESTDIR=${INSTALL} install make DESTDIR=${INSTALL} install
rm -rf ${INSTALL}/usr/share/man/ rm -rf ${INSTALL}/usr/share/man/
install -Dm755 ${PKG_DIR}/scripts/zerotier-join.sh ${INSTALL}/usr/sbin/
mkdir -p ${INSTALL}/usr/lib/systemd/system mkdir -p ${INSTALL}/usr/lib/systemd/system
cp -R ${PKG_DIR}/system.d/zerotier-one.service ${INSTALL}/usr/lib/systemd/system/ install -Dm644 ${PKG_DIR}/system.d/zerotier-one.service ${INSTALL}/usr/lib/systemd/system/
mkdir -p ${INSTALL}/etc/profile.d/ mkdir -p ${INSTALL}/etc/profile.d/
cp -R ${PKG_DIR}/profile.d/95-zerotier ${INSTALL}/etc/profile.d/ install -Dm755 ${PKG_DIR}/profile.d/95-zerotier ${INSTALL}/etc/profile.d/
} }

View file

@ -0,0 +1,25 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2023-present NeoTheFox (https://github.com/NeoTheFox)
NETWORKS_FILE=/storage/.config/zerotier-networks
[[ -f ${NETWORKS_FILE} ]] || (echo "No networks defined" && exit 0)
shopt -s expand_aliases
alias zerotier-cli="zerotier-cli -D/storage/.config/zerotier/"
zerotier-cli listnetworks | cut -d' ' -f 3 | while read net
do
[[ "$net" == "<nwid>" ]] && continue
echo "Checking $net"
grep -Fxq $net ${NETWORKS_FILE} || (echo "Leaving $net (not in the file)" && zerotier-cli leave $net)
done
cat ${NETWORKS_FILE} | while read net
do
echo "Joining $net"
zerotier-cli join $net
done
# Just in case the last join fails...
exit 0

View file

@ -5,9 +5,11 @@ After=network-pre.target
[Service] [Service]
ExecStart=/usr/sbin/zerotier-one /storage/.config/zerotier/ ExecStart=/usr/sbin/zerotier-one /storage/.config/zerotier/
ExecStartPost=/usr/sbin/zerotier-join.sh
Restart=always Restart=always
KillMode=process KillMode=process
Restart=on-failure Restart=on-failure
RestartSec=5
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target