#! /bin/sh

. /etc/time.conf > /dev/null 2>&1

if [ "$1" == 'on' ];
	then 
		target=$ntp
		replace=$1
		/etc/sss_script/network/SETUP.sh "ntp=${target}" "ntp=${replace}" '/etc/time.conf'
		
		if [ "$2" != 'none' ];then 
			target=$ntpserver
                	replace=$2
			/etc/sss_script/network/SETUP.sh "ntpserver=${target}" "ntpserver=${replace}" '/etc/time.conf'
		else 	
			target=$ntpserver
                	replace=$2
			/etc/sss_script/network/SETUP.sh "ntpserver=${target}" "ntpserver=${replace}" '/etc/time.conf'
		fi

               	if [ "$3" == '1d' ]; then
			target=$ntp_update
               		replace=$3
			if [ "$target" != "$replace" ]; then 
				rm /etc/cron/cron.weekly/ntptime	
				/etc/sss_script/network/SETUP.sh "ntp_update=${target}" "ntp_update=${replace}" '/etc/time.conf'
				
			fi
			cp /etc/cron/cron.d/ntptime /etc/cron/cron.daily/
		fi
					
		if [ "$3" == '1w' ]; then
			target=$ntp_update
               		replace=$3
			if [ "$target" != "$replace" ]; then 
				rm /etc/cron/cron.daily/ntptime	
				/etc/sss_script/network/SETUP.sh "ntp_update=${target}" "ntp_update=${replace}" '/etc/time.conf'
				
			fi
			cp /etc/cron/cron.d/ntptime /etc/cron/cron.weekly/
				
		fi
			
	else
		target=$ntp
		replace="off"
		/etc/sss_script/network/SETUP.sh "ntp=${target}" "ntp=${replace}" '/etc/time.conf'
		
		target=$ntpserver
                replace=$2
		/etc/sss_script/network/SETUP.sh "ntpserver=${target}" "ntpserver=${replace}" '/etc/time.conf'
		
		if [ "$ntp_update" == '1d' ]; then
			rm /etc/cron/cron.daily/ntptime
		fi
		if [ "$ntp_update" == '1w' ]; then
			rm /etc/cron/cron.weekly/ntptime
		fi
fi 