#!/bin/bash

# Script to repair the localtime file per ODT K2691.
#
# The main objective is to ensure that the localtime is set as a symbolic
# link to a valid, up to date timezone file.  If it is not, it will
# automatically set it to America/New_York.
#
# The SE needs to reboot once this is done.
#
# Module History:
# 00 03/23/2007  J. Bieber     D63J K2619 Base code release

actzTrace "XTODFTZT: -> fixTimeZone"

timeZoneDir='/usr/share/zoneinfo'
localTimeFile='/etc/localtime'
timeZone='America/New_York'
logFile='/console/data/fixTimeZoneLog'
tempFile='/console/data/fixTimeZoneTemp'

# Save this file in case we need to retrieve this file.
echo "`date` Checking if $timeZoneDir is a symbolic link." >> $logFile

# Let's perform a list of the localTimeFile and save it in our log file.
ls -l $localTimeFile >> $logFile

# Let's test to see if we have a symbolic link
if ls -l $localTimeFile | grep '>' > $tempFile; then

  # Symbolic link found - let's save it and quit.
  actzTrace "XTODFTZT:    localTime is a symbolic link."
  echo "localTime is a symbolic link." >> $logFile
else

  # Symbolic link was not found.
  actzTrace "XTODFTZT:    localTime is not a symbolic link."
  echo "localTime is not a symbolic link." >> $logFile

  # Step One: Delete the local time zone file if it exists.
  if [[ -e $localTimeFile ]]; then
    actzTrace 'XTODFTZF:    Deleting $localTimeFile.'
    rm -f $localTimeFile
  fi

  # Step Two: Set the local time to America/New_York
  actzTrace "XTODFTZF:    Linking $timeZoneDir/$timeZone to $localTimeFile."
  ln -sf $timeZoneDir/$timeZone $localTimeFile
fi

# Add a copy of the tempFile to the logFile and then erase it.
cat $tempFile >> $logFile
rm $tempFile

actzTrace "XTODFTZT: <- fixTimeZone"

exit 0
