#!/bin/sh
# ntp hotplug script for travelmate
# Copyright (c) 2020-2026 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.

# set (s)hellcheck exceptions
# shellcheck disable=all

trm_init="/etc/init.d/travelmate"
trm_funlib="/usr/lib/travelmate-functions.sh"
trm_ntplock="/var/run/travelmate/travelmate.ntp.lock"

# ensure runtime directory exists
#
[ ! -d "${trm_ntplock%/*}" ] && mkdir -p "${trm_ntplock%/*}"

# check for ntp hotplug event and travelmate service autostart condition
#
if mkdir "${trm_ntplock}" 2>/dev/null; then
	if [ "${ACTION}" = "stratum" ] && "${trm_init}" enabled; then
		. "${trm_funlib}"
		f_log "info" "get ntp time sync"
	fi
fi
