#!/bin/ksh
#
# 
# Copyright 07/08/99 Sun Microsystems, Inc. All Rights Reserved
#
#
#
# call dsimport with the appropriate parameters. This is used to be able to
# keep the default makefile as created by the system administrators for NIS
#
BASEDIR=$(pkgparam SUNWsds BASEDIR)
PATH=$BASEDIR/SUNWconn/ldap/sbin:$BASEDIR/SUNWconn/ldap/bin:$BASEDIR/SUNWconn/ldap/lib:/usr/ccs/bin:/bin:$PATH
export PATH
ETCDIR=$(pkgparam SUNWsds ETCDIR)
. $ETCDIR/current/dsserv.ini

while getopts blsd:i:o:m: c
do
	true
done
shift `expr $OPTIND - 1`
TABLENAME=`echo $2 | sed 's/.*\///'`
echo Processing $TABLENAME
unset IN
if [ "$1" != "-" ]
then
	IN=$1
fi
case $TABLENAME in
	ethers.byname|group.bygid|hosts.byname|\
	networks.byname|passwd.byuid|protocols.byname)
		cat $IN >/dev/null
		exit 0;;
	#
	# special case for hosts.byaddr 
	#
	hosts.byaddr)
		dsmulti $IN | dsimport -p $LdapPort -r -t $TABLENAME
		exit 0
		;;
	#
	# special case for ethers.byaddr
	#
	ethers.byaddr)
		dsmulti -n $IN | grep -v YP_MULTI | dsimport -p $LdapPort -r -t $TABLENAME
		exit 0
		;;
	#
	# special case for netgrop
	#
	netgroup)
		#
		# suppress comments and empty lines and call dsimport
		# And change tabs into space
		#
		sed -e '/^#/d;s/	/ /g;s/  */ /g;s/ \\$/\\/' $IN | dsimport -p $LdapPort -r -t $TABLENAME
		exit 0
		;;
	#
	# special case for services
	#
	services.byservicename)
		/bin/sort -fu | dsimport -p $LdapPort -r -t $TABLENAME
		exit 0
		;;
	#
	# special case for mail.aliases
	#
	mail.aliases)
		egrep -v "^#|^$" $IN | egrep -v "@[ 	][ 	]*@" | dsimport -p $LdapPort -r -t $TABLENAME
		exit 0
		;;
esac
#
# suppress comments and empty lines and call dsimport
#
egrep -v "^#|^$" $IN | dsimport -p $LdapPort -r -t $TABLENAME
exit 0
