#!/bin/sh
#
# Script Name: dated
# Description: Daemon which store the current date/time every 10m on Raspberry Pi
#              Should the system date is not set by NTP on start-up it will restore
#              the system date to the last known good date time setup
# Author     : Konstantinos Mantzaris <kmanjaris@gmail.com>
# Web Site   : http://SlaXBMC.blogspot.com
#

if [ "$(date +"%Y")" = "1970" ] && [ -f /var/log/dated/dated.dat ] ; then date "$(cat /var/log/dated/dated.dat)" ; fi
while `sleep 10m` ; do
    if [ "$(date +"%Y")" = "1970" ] ; then
        if [ ! -f /var/log/dated/dated.dat ] ; then 
    	    echo "020112002014" > /var/log/dated/dated.dat
    	    chmod 644 /var/log/dated/dated.dat
    	fi
	date $(cat /var/log/dated/dated.dat)
    else
	date +"%m%d%H%M%Y" > /var/log/dated/dated.dat
    fi
done
