:
#      @(#)yp_first.sh	4.1 System V NFS  source
#      SCCS IDENTIFICATION
#
#	System V NFS 
#
#	Copyright 1991 INTERACTIVE Systems Corporation (ISC)
#	Copyright 1986-1989 Lachman Associates, Incorporated (LAI)
#
#	All Rights Reserved.
#
#	The copyright above and this notice must be preserved in all
#	copies of this source code.  The copyright above does not
#	evidence any actual or intended publication of this source
#	code.
#
#	This is unpublished proprietary trade secret source code of
#	Lachman Associates.  This source code may not be copied,
#	disclosed, distributed, demonstrated or licensed except as
#	expressly authorized by Lachman Associates.
#

# yp_first.sh - set up a populated yp directory structure on a master server,
# a slave server, or a slave copier.

log(){
	echo "\n$*" 
	echo "\nyp_first: $*" >> /usr/adm/nislog
}
etcsave_dir=$ROOT/usr/lib/nisrt/etc
etcroot_dir=$ROOT/etc
yproot_dir=$ROOT/etc/yp
maps=`oawk '{print $2 ; }' $yproot_dir/YP_MAP_X_LATE`
hf=/tmp/yp$$
XFR=${YPXFR-$ROOT/etc/yp/ypxfr}

masterp=F
slavep=F
copierp=F
host=""
def_dom=""
got_host_list=F
exit_on_error=F
errors_in_setup=F

PATH=$PATH:/etc
export PATH 

host=`hostname`

if [ $? -ne 0 ]
then 
	log "Can't get local host's name.  Please check your path."
	exit 1
fi

if [ -z "$host" ]
then
	log "The local host's name hasn't been set.  Please set it."
	exit 1
fi

def_dom=`domainname`

if [ $? -ne 0 ]
then 
	log "Can't get local host's domain name.  Please check your path."
	exit 1
fi

domainname "$def_dom"

if [ $? -ne 0 ]
then 
	log "\
You have to be the superuser to run this.  Please log in as root."
	exit 1
fi

if [ "$def_dom" = "unknown" ]
then
	log "Can't get local host's domain name.  Please check your path."
	exit 1
fi

# 
# do this to make sure that we are bound to the correct master
#

/etc/yp/ypset $master > /dev/null 2>&1

for dom in  $def_dom
do
	for map in $maps
	do
		echo "Transferring $map..."
		$XFR -h $master -c -d $dom $map

#
# this should not happen unless something really wrong happened
# because all the map names in YP_MAP_XLATE were verified in the
# ypinit script.  If this error does occur, just log it because we are
# in the middle of a boot sequence
#
		if [ $? -ne 0 ]
		then
			log "Could not get map $map from $master."
		fi
	done
done
