Add file-based auto-join script to ZeroTier
This commit is contained in:
parent
d3e7b87f09
commit
e0a042098b
3 changed files with 30 additions and 2 deletions
|
@ -27,9 +27,10 @@ makeinstall_target() {
|
|||
make DESTDIR=${INSTALL} install
|
||||
rm -rf ${INSTALL}/usr/share/man/
|
||||
|
||||
install -Dm755 ${PKG_DIR}/scripts/zerotier-join.sh ${INSTALL}/usr/sbin/
|
||||
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/
|
||||
cp -R ${PKG_DIR}/profile.d/95-zerotier ${INSTALL}/etc/profile.d/
|
||||
install -Dm755 ${PKG_DIR}/profile.d/95-zerotier ${INSTALL}/etc/profile.d/
|
||||
}
|
||||
|
||||
|
|
25
packages/network/zerotier-one/scripts/zerotier-join.sh
Normal file
25
packages/network/zerotier-one/scripts/zerotier-join.sh
Normal 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
|
|
@ -5,9 +5,11 @@ After=network-pre.target
|
|||
|
||||
[Service]
|
||||
ExecStart=/usr/sbin/zerotier-one /storage/.config/zerotier/
|
||||
ExecStartPost=/usr/sbin/zerotier-join.sh
|
||||
Restart=always
|
||||
KillMode=process
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
Loading…
Reference in a new issue