# This script has been modified by the SARPi Project.
#
# Exaga - sarpi.penthux.net - 20 Feb 2024
#
######

sleep 3
# test for network interface connection carrier
for NIF in $(ls /sys/class/net/ | grep -v lo); do
# If network connection exists then use it to set clock
if [[ -n $(cat /sys/class/net/"${NIF}"/carrier 2>/dev/null) ]]; then
  # set system clock from ntp server [remote]
  /usr/sbin/ntpdate time4.google.com > /dev/null 2>&1 || \
  /usr/sbin/ntpdate 0.pool.ntp.org > /dev/null 2>&1
# Or set clock using onboard RTC [if one is found]
elif [ -h /dev/rtc ]; then
  # set system clock from RTC [if detected]
  /sbin/hwclock --hctosys > /dev/null 2>&1
# Otherwise use a -24Hr Unix timestamp
else
  date -s yesterday 1> /dev/null 2> /dev/null
fi
done
rm -f /.today
