#!/bin/sh
# $Revision: 1.3 $
#bcpyrght
#***************************************************************************
#* $VRTScprght: Copyright 1993 - 2005 VERITAS Software Corporation, All Rights Reserved $ *
#***************************************************************************
#ecpyrght
#
# You need to be root to run this script.
#
# This script runs on the client and merges the new authentication
# configuration file templates with their corresponding existing
# configuration files.
#
# The format of the files has not changed for this release.  If the
# configuration file does not exist, the corresponding template file
# will be copied in its place.  If the configuration file does exist,
# it will not be changed.

# INSERT fn.set_echo_var
#----- $Id: fn.set_echo_var,v 1.3 2004/11/22 20:01:21 $ -----
#
#		This function is a case statement sets
#		the ECHO variable
#		with the appropriate path & flags.

#Define Echo to allow escape characters
case "`uname -s`" in
	Linux*)
		unset POSIXLY_CORRECT
		ECHO="/bin/echo -e"
		;;
	SunOS*)
		ECHO="/usr/bin/echo"
		;;
	*)
		ECHO="echo"
		;;
esac

OPENV_DIR=/usr/openv
OPENV_VAR=${OPENV_DIR}/var
OPENV_AUTH=${OPENV_VAR}/auth

errors=0
for file in "${OPENV_AUTH}"/template.*.txt
do
	if [ ! -r "${file}" ]
	then
		# No template files
		continue
	fi
	target="${OPENV_AUTH}/"`basename "${file}" | sed 's/^template\.//'`
	if [ -f "${target}" ]
	then
		# Configuration file already exists.
		# In the future, we might have to merge with the template.
		# For now, just leave the configuration file as is.
		chmod 644 "${target}"
		chgrp bin "${target}"
		continue
	fi

	# Configuration file does not exist.  Copy template in its place.
	cp "${file}" "${target}"
	if [ ! -f "${target}" ]
	then
		${ECHO} \
		"Cannot create authentication configuration file ${target}" >&2
		errors=`expr "${errors}" + 1`
	fi
	chmod 644 "${target}"
	chgrp bin "${target}"
done

exit "${errors}"
