From 967664705c8cb66363547a27b478fb03711bf9b3 Mon Sep 17 00:00:00 2001 From: duhow Date: Sun, 22 Dec 2024 21:17:09 +0100 Subject: [PATCH] listener: fix NTP sync check date --- packages/porcupine/config/launcher | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/porcupine/config/launcher b/packages/porcupine/config/launcher index 9592bea..a5c9080 100755 --- a/packages/porcupine/config/launcher +++ b/packages/porcupine/config/launcher @@ -51,11 +51,19 @@ set_volume(){ } check_date(){ - YEAR=2024 + # get build time which matches the default time set in system + # when hot rebooting, this time is still set, so NTP is required + + BUILD_TIME=$(date -d "`micocfg_build_time`" +%s) + if [ -z "$BUILD_TIME" ] || ! [ "$BUILD_TIME" -eq "$BUILD_TIME" ] 2>/dev/null; then + BUILD_TIME=$(find /etc -type f -maxdepth 1 -exec date -r {} +%s \; | sort -nr | head -n1) + fi COUNT=0 until [ "$COUNT" -ge 5 ]; do - if [ "`date +%Y`" -ge "$YEAR" ]; then - log "all good" + CURRENT_TIME=$(date +%s) + DIFF=$((CURRENT_TIME - BUILD_TIME)) + if [ "$DIFF" -gt 600 ]; then + log "time is ok, we are in sync" break fi log "updating time - times $COUNT"