#!/bin/sh
#
# IPCop CGIs
#
# This file is part of the IPCop Project
# 
# This code is distributed under the terms of the GPL
#
# (c) Eric Oberlander June 2002
#
# /usr/local/bin/timecheck

if [ -e /var/ipfire/time/enable ]; then
	if [ $(cat /var/ipfire/time/settings | grep period) ] && [ -e /var/lock/time/counter ]; then
		if [ $(cat /var/lock/time/counter) -gt 0 ]; then
			echo $(($(cat /var/lock/time/counter)-5)) > /var/lock/time/counter
		else
			touch /var/lock/time/settimenow
			rm -f /var/lock/time/counter
		fi
	else
		# EAO added 2003-08-14 for v1.3.1
		# if settings are restored from a backup
		# /var/lock/time/counter will not exist
		if [ $(cat /var/ipfire/time/settings | grep periodic) ]; then
			touch /var/lock/time/settimenow
		fi
	fi

	if [ -e /var/lock/time/settimenow ]; then
		if 	[ -e /var/ipfire/time/settime.conf ]; then
			/usr/local/bin/settime $(cat /var/ipfire/time/settime.conf)
		fi
	fi
fi		
