#! /bin/bash
#Copyright 1998-2022 Stonie R. Cooper, Licensed under the auspices of GPLv3,
# See top-level copyright disclaimer (COPYRIGHT) and license (LICENSE)
sync_path="/tmp/time_adjust"
if [ -f ${sync_path} ]
then
  typeset -i adjustment=`cat ${sync_path} 2> /dev/null`
  if [ ${adjustment} -ne 0 ]
  then
    if [ ${adjustment} -gt 0 ]
    then
      date -us "+${adjustment} seconds" > /dev/null 2>&1
    else
      date -us "${adjustment} seconds" > /dev/null 2>&1
    fi
    hwclock --systohc > /dev/null 2>&1
    echo "0" > ${sync_path}
  fi
fi
