#!/bin/bash
# $Header: /cvs/WebShield/wsrc/files/mgmt/set_date_time,v 1.6 2004/02/02 14:19:15 bwhittak Exp $
#
# (C) Copyright Network Associates Inc. 2001
#
# Set the system date and time
#
exec > /dev/null 2>&1
if [ -f $NETAWSS/.profile.vars ]; then 
 . $NETAWSS/.profile.vars 
else 
 . /var/NAIENV/.profile.vars 
fi 
PATH=$wsPATH:$PATH

# This script assumes SU login to work - may need to be changed
# when Tomcat is not started as root

# Parameters arrive as : MMDDHHMMYYYY Timezone 
#                        $1           $2

# Set up the time zone we are running in first
zone=/usr/share/zoneinfo/$2
zchange=false
if [[ -n "$2" && -f "$zone" ]]
then
    # Copy the localtimezone
    printf '%s\n' \
	"ZONE=\"$2\"" \
	"UTC=true" \
	"ARC=false" \
	> /etc/sysconfig/clock
    if /usr/bin/cmp -s "$zone" /etc/localtime
    then : timezone is the same
    else	# timezone change
	/bin/cp "$zone" /etc/localtime
	zchange=true
    fi
fi

# Now set the date and time
/bin/date ${1}

# Set the RTC to the system time because date does not !
/sbin/hwclock --utc --systohc 

# restart cron daemon
/etc/init.d/crond restart

# restart proxies if timezone changed
$zchange && proxy-restart &

# Update /etc/issue with the correct time so we gets updated as there is a cron job which updates it
/bin/touch /etc/issue
exit 0
