From a3604166551968b78bc5192c7037dbb0c89d9b99 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Tue, 5 Apr 2022 09:51:35 -0700 Subject: [PATCH] Move Synology home-dir to /var/packages/zerotier/var --- synology/build.sh | 1 - synology/ztpkg-dsm6/service-setup.sh | 2 -- synology/ztpkg-dsm6/start-stop-status.sh | 34 +++++++++++------------- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/synology/build.sh b/synology/build.sh index 47e9285a9..172d06341 100755 --- a/synology/build.sh +++ b/synology/build.sh @@ -114,7 +114,6 @@ REQUIRED_DSM = 6.2.4 ENV += ZT_SYNOLOGY=1 -SERVICE_SETUP = ../../ztpkg-dsm6/service-setup.sh SSS_SCRIPT = ../../ztpkg-dsm6/start-stop-status.sh PRE_STRIP_TARGET = zerotier_install diff --git a/synology/ztpkg-dsm6/service-setup.sh b/synology/ztpkg-dsm6/service-setup.sh index 10988beb2..136072cb7 100644 --- a/synology/ztpkg-dsm6/service-setup.sh +++ b/synology/ztpkg-dsm6/service-setup.sh @@ -6,8 +6,6 @@ service_postinst() service_postuninst() { - # remove all files except for identity files and network config files (for future convenience) - find /var/lib/zerotier-one/* -type f -o -type d ! -name 'identity.*' -delete exit 0 } diff --git a/synology/ztpkg-dsm6/start-stop-status.sh b/synology/ztpkg-dsm6/start-stop-status.sh index 8cd7c4ff6..701058924 100755 --- a/synology/ztpkg-dsm6/start-stop-status.sh +++ b/synology/ztpkg-dsm6/start-stop-status.sh @@ -1,19 +1,15 @@ #!/bin/sh -if [ "${SYNOPKG_DSM_VERSION_MAJOR}" -eq "6" ]; then - PKGDIR="/var/packages/zerotier/var" -else - PKGDIR="${SYNOPKG_PKGVAR}" -fi +PKGVAR=/var/packages/zerotier/var -ZTO_PID_FILE="${PKGDIR}/zerotier-one.pid" -WAT_PID_FILE="${PKGDIR}/zerotier-watchdog.pid" -ZTO_LOG_FILE="${PKGDIR}/zerotier-one.log" +ZTO_PID_FILE="$PKGVAR/zerotier-one.pid" +WAT_PID_FILE="$PKGVAR/zerotier-watchdog.pid" +ZTO_LOG_FILE="$PKGVAR/zerotier-one.log" log() { local timestamp=$(date --iso-8601=second) - echo "${timestamp} $1" >> ${ZTO_LOG_FILE} + echo "$timestamp $1" >> $ZTO_LOG_FILE } configure_tun() @@ -40,13 +36,13 @@ configure_cli() { # Create ZT CLI symlinks if needed mkdir -p /usr/local/bin/ - ln -s ${SYNOPKG_PKGDEST}/bin/zerotier-one /usr/local/bin/zerotier-cli - ln -s ${SYNOPKG_PKGDEST}/bin/zerotier-one /usr/local/bin/zerotier-idtool + ln -s $SYNOPKG_PKGDEST/bin/zerotier-one /usr/local/bin/zerotier-cli + ln -s $SYNOPKG_PKGDEST/bin/zerotier-one /usr/local/bin/zerotier-idtool } apply_routes() { - echo $BASHPID >> ${WAT_PID_FILE} + echo $BASHPID >> $WAT_PID_FILE log "Started Watchdog ($(cat $WAT_PID_FILE))" # Wait for ZT service to come online before attempting queries @@ -89,20 +85,20 @@ configure_routes() start_daemon() { - ${SYNOPKG_PKGDEST}/bin/zerotier-one -d + ${SYNOPKG_PKGDEST}/bin/zerotier-one $PKGVAR -d echo $(pidof zerotier-one) > ${ZTO_PID_FILE} log "Started ZeroTier ($(cat $ZTO_PID_FILE))" } stop_daemon() { - if [ -r "${ZTO_PID_FILE}" ]; then + if [ -r "$ZTO_PID_FILE" ]; then local ZTO_PID=$(cat "${ZTO_PID_FILE}") log "Stopped ZeroTier ($(cat $ZTO_PID_FILE))" kill -TERM $ZTO_PID - wait_for_status 1 || kill -KILL $PID >> ${LOG_FILE} 2>&1 + wait_for_status 1 || kill -KILL $PID >> $LOG_FILE 2>&1 rm -f $ZTO_PID_FILE > /dev/null fi - if [ -r "${WAT_PID_FILE}" ]; then + if [ -r "$WAT_PID_FILE" ]; then local WAT_PID=$(cat "${WAT_PID_FILE}") log "Stopped Watchdog ($(cat $WAT_PID_FILE))" kill -TERM $WAT_PID @@ -112,17 +108,17 @@ stop_daemon() { daemon_status() { - if [ -f ${ZTO_PID_FILE} ] && kill -0 `cat ${ZTO_PID_FILE}` > /dev/null 2>&1; then + if [ -f $ZTO_PID_FILE ] && kill -0 `cat $ZTO_PID_FILE` > /dev/null 2>&1; then return fi - rm -f ${ZTO_PID_FILE} + rm -f $ZTO_PID_FILE return 1 } wait_for_status() { counter=$2 - while [ ${counter} -gt 0 ]; do + while [ $counter -gt 0 ]; do daemon_status [ $? -eq $1 ] && return let counter=counter-1