#!/bin/sh
#
# Copyright (C) 1997 Florian La Roche
#

DOMAIN=`domainname`

if test -z "$DOMAIN" -o "$DOMAIN" = "(none)" ; then
	echo "You haven't set the domainname."
	exit 1
fi

if ! test -d /var/yp/$DOMAIN ; then
	echo "I have created the subdirectory /var/yp/$DOMAIN."
	mkdir -p -m 0755 /var/yp/$DOMAIN
fi

# if we initialize a slave server, we force a transfer of all maps
if test "$1" = init ; then
	FLAG="-f"
fi

pidof ypserv > /dev/null
if test $? -ne 0 ; then
	CFLAG="-c"
fi

ypwhich -m | while read map server; do
	/usr/lib/yp/ypxfr $FLAG -h $server $CFLAG $map;
done
