#!/bin/ksh

# File: config_template/init/DiffHelper
#
#                     COPYRIGHT (c) 2002, 2003  BY
#          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
# 
# THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
# ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
# INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
# COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
# OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
# TRANSFERED.


# Little script to help with installation of setup .conf files.
# Update the target directory, but only if the file has changed.
# In that case, copy the old file to the backups directory.

TMP1=/tmp/DiffHelper1_$$
TMP2=/tmp/DiffHelper2_$$
trap "rm -f ${TMP1} ${TMP2} ; exit" INT EXIT


while [ ! "$1" = "" ] ; do
  FILE="$1" ; shift
  TARGET="${IRIS_CONFIG}${FILE}"

  if [ -r ${TARGET} ] ; then
    rm -f ${TMP1} ${TMP2}

# Copy file to be compared to temporary directory, with the IRIS version
# removed.
    grep -v ".sVersion =" ${FILE}   > ${TMP1}
    grep -v ".sVersion =" ${TARGET} > ${TMP2}
    diff ${TMP1} ${TMP2} >/dev/null
    DIFF_RESULT="$?"

# If they are different, then replace
    if [ "0" != "${DIFF_RESULT}" ] ; then
      echo "Install : ${FILE}"
      mkdir -p ${IRIS_CONFIG}backups
      rootcp -p ${TARGET} ${IRIS_CONFIG}backups/
      rootcp ${FILE} ${TARGET}
      rootchown operator ${TARGET}
    fi
  fi
done
