xref: /onnv-gate/usr/src/cmd/ypcmd/ypinit.sh (revision 5728:9da4de721b0a)
10Sstevel@tonic-gate#!/sbin/sh
20Sstevel@tonic-gate#
30Sstevel@tonic-gate# CDDL HEADER START
40Sstevel@tonic-gate#
50Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*5728Spwernau# Common Development and Distribution License (the "License").
7*5728Spwernau# You may not use this file except in compliance with the License.
80Sstevel@tonic-gate#
90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate# See the License for the specific language governing permissions
120Sstevel@tonic-gate# and limitations under the License.
130Sstevel@tonic-gate#
140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate#
200Sstevel@tonic-gate# CDDL HEADER END
210Sstevel@tonic-gate#
220Sstevel@tonic-gate#
23*5728Spwernau# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate# Use is subject to license terms.
250Sstevel@tonic-gate
260Sstevel@tonic-gate#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
270Sstevel@tonic-gate#	  All Rights Reserved
280Sstevel@tonic-gate
290Sstevel@tonic-gate# Portions of this source code were derived from Berkeley 4.3 BSD
300Sstevel@tonic-gate# under license from the Regents of the University of California.
310Sstevel@tonic-gate
320Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
330Sstevel@tonic-gate
340Sstevel@tonic-gate# set -xv
350Sstevel@tonic-gateYPXFR=/usr/lib/netsvc/yp/ypxfr
360Sstevel@tonic-gateMAKEPATH=/usr/ccs/bin
370Sstevel@tonic-gatemaps="publickey publickey.byname"
380Sstevel@tonic-gateyproot_dir=/var/yp
390Sstevel@tonic-gateyproot_exe=/usr/sbin/yp
400Sstevel@tonic-gatehf=/var/run/ypservers.$$
410Sstevel@tonic-gateXFR=${YPXFR}
420Sstevel@tonic-gate
430Sstevel@tonic-gatehosts_file=/etc/hosts
440Sstevel@tonic-gatehosts6_file=/etc/inet/ipnodes
450Sstevel@tonic-gateclientp=F
460Sstevel@tonic-gatemasterp=F
470Sstevel@tonic-gateslavep=F
480Sstevel@tonic-gatehost=""
490Sstevel@tonic-gatedef_dom=""
500Sstevel@tonic-gatemaster=""
510Sstevel@tonic-gategot_host_list=F
520Sstevel@tonic-gatefirst_time=T
530Sstevel@tonic-gateexit_on_error=F
540Sstevel@tonic-gateerrors_in_setup=F
550Sstevel@tonic-gate
560Sstevel@tonic-gateenable_next_boot () {
570Sstevel@tonic-gate	/usr/sbin/svcadm disable -t $1
580Sstevel@tonic-gate	[ $? = 0 ] || echo "ypinit: unable to temporarily disable $1"
590Sstevel@tonic-gate	/usr/sbin/svccfg -s $1 \
600Sstevel@tonic-gate	    setprop general/enabled = true
610Sstevel@tonic-gate	[ $? = 0 ] || echo "ypinit: unable to enable $1 for next boot"
620Sstevel@tonic-gate}
630Sstevel@tonic-gate
640Sstevel@tonic-gateenable_this_boot () {
650Sstevel@tonic-gate	/usr/sbin/svcadm enable $1
660Sstevel@tonic-gate	[ $? = 0 ] || echo "ypinit: unable to enable $1"
670Sstevel@tonic-gate}
680Sstevel@tonic-gate
69*5728Spwernauis_valid_ipaddr () {
70*5728Spwernau	test -n "`echo $1 | awk 'NF != 1 {exit} \
71*5728Spwernau	    $1 !~ /[0-9]/ || /[;-~]/ || /!--/ || /\// {exit} \
72*5728Spwernau	    $1 !~ /\./ {exit} {print}'`" || \
73*5728Spwernau	test -n "`echo $1 | awk 'NF != 1 {exit} \
74*5728Spwernau	    ($1 !~ /[0-9]/ && $1 !~ /[A-F]/ && \
75*5728Spwernau	    $1 !~ /[a-f]/) || \
76*5728Spwernau	    /[;-@]/ || /[G-\`]/ || /[g-~]/ || /!--/ || \
77*5728Spwernau	    /\// {exit} \
78*5728Spwernau	    $1 !~ /:/ {exit} {print}'`"
79*5728Spwernau}
80*5728Spwernau
810Sstevel@tonic-gatePATH=/bin:/usr/bin:/usr/etc:/usr/sbin:$yproot_exe:$MAKEPATH:$PATH
820Sstevel@tonic-gateexport PATH
830Sstevel@tonic-gate
840Sstevel@tonic-gate# To do cleanup
850Sstevel@tonic-gatetrap '/usr/bin/rm -f $hf' 0 1 2 3 15
860Sstevel@tonic-gate
870Sstevel@tonic-gatecase $# in
880Sstevel@tonic-gate1)	case $1 in
890Sstevel@tonic-gate	-c)	clientp=T;;
900Sstevel@tonic-gate	-m)	masterp=T;;
910Sstevel@tonic-gate	*)	echo 'usage:'
920Sstevel@tonic-gate		echo '	ypinit -c'
930Sstevel@tonic-gate		echo '	ypinit -m'
940Sstevel@tonic-gate		echo '	ypinit -s master_server'
950Sstevel@tonic-gate		echo ""
960Sstevel@tonic-gate		echo "\
970Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master "
980Sstevel@tonic-gate                echo "\
990Sstevel@tonic-gateyp server data base, and -s is used for a slave data base."
1000Sstevel@tonic-gate		echo "\
1010Sstevel@tonic-gatemaster_server must be an existing reachable yp server."
1020Sstevel@tonic-gate		exit 1;;
1030Sstevel@tonic-gate	esac;;
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate2)	case $1 in
1060Sstevel@tonic-gate	-s)	slavep=T; master=$2;
1070Sstevel@tonic-gate		if ( grep $master $hosts_file $hosts6_file > /dev/null )
1080Sstevel@tonic-gate		then
1090Sstevel@tonic-gate			echo ""
1100Sstevel@tonic-gate		else
1110Sstevel@tonic-gate			echo "server not found in $hosts_file or $hosts6_file"
1120Sstevel@tonic-gate			exit 1
1130Sstevel@tonic-gate		fi;;
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate	*)	echo 'usage:'
1160Sstevel@tonic-gate		echo '	ypinit -c'
1170Sstevel@tonic-gate		echo '	ypinit -m'
1180Sstevel@tonic-gate		echo '	ypinit -s master_server'
1190Sstevel@tonic-gate		echo ""
1200Sstevel@tonic-gate		echo "\
1210Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master "
1220Sstevel@tonic-gate                echo "\
1230Sstevel@tonic-gateyp server data base, and -s is used for a slave data base."
1240Sstevel@tonic-gate		echo "\
1250Sstevel@tonic-gatemaster_server must be an existing reachable yp server."
1260Sstevel@tonic-gate		exit 1;;
1270Sstevel@tonic-gate	esac;;
1280Sstevel@tonic-gate3)	case $1 in
1290Sstevel@tonic-gate	-c)	clientp=T;;
1300Sstevel@tonic-gate	*)	echo 'usage:'
1310Sstevel@tonic-gate		echo '	ypinit -c'
1320Sstevel@tonic-gate		echo '	ypinit -m'
1330Sstevel@tonic-gate		echo '	ypinit -s master_server'
1340Sstevel@tonic-gate		echo ""
1350Sstevel@tonic-gate		echo "\
1360Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master "
1370Sstevel@tonic-gate                echo "\
1380Sstevel@tonic-gateyp server data base, and -s is used for a slave data base."
1390Sstevel@tonic-gate		echo "\
1400Sstevel@tonic-gatemaster_server must be an existing reachable yp server."
1410Sstevel@tonic-gate		exit 1;;
1420Sstevel@tonic-gate	esac;;
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate*)	echo 'usage:'
1450Sstevel@tonic-gate	echo '	ypinit -c'
1460Sstevel@tonic-gate	echo '	ypinit -m'
1470Sstevel@tonic-gate	echo '	ypinit -s master_server'
1480Sstevel@tonic-gate	echo ""
1490Sstevel@tonic-gate	echo "\
1500Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master "
1510Sstevel@tonic-gate	echo "\
1520Sstevel@tonic-gateyp server data base, and -s is used for a slave data base."
1530Sstevel@tonic-gate	echo "\
1540Sstevel@tonic-gatemaster_server must be an existing reachable yp server."
1550Sstevel@tonic-gate	exit 1;;
1560Sstevel@tonic-gateesac
1570Sstevel@tonic-gate
1580Sstevel@tonic-gateif [ $? -ne 0 ]
1590Sstevel@tonic-gatethen
1600Sstevel@tonic-gate	echo "\
1610Sstevel@tonic-gateYou have to be the superuser to run this.  Please log in as root."
1620Sstevel@tonic-gate	exit 1
1630Sstevel@tonic-gatefi
1640Sstevel@tonic-gate
1650Sstevel@tonic-gatehost=`uname -n`
1660Sstevel@tonic-gate
1670Sstevel@tonic-gateif [ $? -ne 0 ]
1680Sstevel@tonic-gatethen
1690Sstevel@tonic-gate	echo "Can't get local host's name.  Please check your path."
1700Sstevel@tonic-gate	exit 1
1710Sstevel@tonic-gatefi
1720Sstevel@tonic-gate
1730Sstevel@tonic-gateif [ -z "$host" ]
1740Sstevel@tonic-gatethen
1750Sstevel@tonic-gate	echo "The local host's name hasn't been set.  Please set it."
1760Sstevel@tonic-gate	exit 1
1770Sstevel@tonic-gatefi
1780Sstevel@tonic-gate
1790Sstevel@tonic-gatedef_dom=`domainname`
1800Sstevel@tonic-gate
1810Sstevel@tonic-gateif [ $? -ne 0 ]
1820Sstevel@tonic-gatethen
1830Sstevel@tonic-gate	echo "Can't get local host's domain name.  Please check your path."
1840Sstevel@tonic-gate	exit 1
1850Sstevel@tonic-gatefi
1860Sstevel@tonic-gate
1870Sstevel@tonic-gateif [ -z "$def_dom" ]
1880Sstevel@tonic-gatethen
1890Sstevel@tonic-gate	echo "The local host's domain name hasn't been set.  Please set it."
1900Sstevel@tonic-gate	exit 1
1910Sstevel@tonic-gatefi
1920Sstevel@tonic-gate
1930Sstevel@tonic-gatedomainname $def_dom
1940Sstevel@tonic-gatereal_def_dom=$def_dom
1950Sstevel@tonic-gate#def_dom=`ypalias -d $def_dom`
1960Sstevel@tonic-gateypservers_map=`ypalias ypservers`
1970Sstevel@tonic-gatedomain_dir="$yproot_dir""/""$def_dom"
1980Sstevel@tonic-gatebinding_dir="$yproot_dir""/binding/""$def_dom"
1990Sstevel@tonic-gatebinding_file="$yproot_dir""/binding/""$def_dom""/ypservers"
2000Sstevel@tonic-gate
2010Sstevel@tonic-gateif [ ! -d $yproot_dir -o -f $yproot_dir ]
2020Sstevel@tonic-gatethen
2030Sstevel@tonic-gate    echo "\
2040Sstevel@tonic-gateThe directory $yproot_dir doesn't exist.  Restore it from the distribution."
2050Sstevel@tonic-gate	exit 1
2060Sstevel@tonic-gatefi
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate# add domainname and ypservers aliases to aliases file
2090Sstevel@tonic-gateecho ypservers $ypservers_map >> $yproot_dir/aliases
2100Sstevel@tonic-gateecho $real_def_dom $def_dom >> $yproot_dir/aliases
2110Sstevel@tonic-gatesort $yproot_dir/aliases | uniq > /var/run/.ypaliases; mv /var/run/.ypaliases $yproot_dir/aliases
2120Sstevel@tonic-gate
2130Sstevel@tonic-gateif [ ! -d "$yproot_dir"/binding ]
2140Sstevel@tonic-gatethen
2150Sstevel@tonic-gate	mkdir "$yproot_dir"/binding
2160Sstevel@tonic-gatefi
2170Sstevel@tonic-gate
2180Sstevel@tonic-gateif [ ! -d  $binding_dir ]
2190Sstevel@tonic-gatethen
2200Sstevel@tonic-gate	mkdir  "$binding_dir"
2210Sstevel@tonic-gatefi
2220Sstevel@tonic-gate
2230Sstevel@tonic-gateif [ $slavep = F ]
2240Sstevel@tonic-gatethen
2250Sstevel@tonic-gate	while [ $got_host_list = F ]; do
2260Sstevel@tonic-gate		touch $hf    # make sure file exists
2270Sstevel@tonic-gate		echo ""
2280Sstevel@tonic-gate		echo "\
2290Sstevel@tonic-gateIn order for NIS to operate sucessfully, we have to construct a list of the "
2300Sstevel@tonic-gate		echo "\
2310Sstevel@tonic-gateNIS servers.  Please continue to add the names for YP servers in order of"
2320Sstevel@tonic-gate		echo "\
2330Sstevel@tonic-gatepreference, one per line.  When you are done with the list, type a <control D>"
2340Sstevel@tonic-gate		echo "\
2350Sstevel@tonic-gateor a return on a line by itself."
2360Sstevel@tonic-gate		if [ $masterp = T ]
2370Sstevel@tonic-gate		then
2380Sstevel@tonic-gate			echo $host > $hf
2390Sstevel@tonic-gate			echo "\tnext host to add:  $host"
2400Sstevel@tonic-gate		elif [ -f $binding_file ]
2410Sstevel@tonic-gate		then
2420Sstevel@tonic-gate			if [ $first_time = T ]
2430Sstevel@tonic-gate			then
2440Sstevel@tonic-gate				for h in `cat $binding_file`
2450Sstevel@tonic-gate				do
2460Sstevel@tonic-gate					echo $h >> $hf
2470Sstevel@tonic-gate					echo "\tnext host to add:  $h"
2480Sstevel@tonic-gate				done
2490Sstevel@tonic-gate			fi
2500Sstevel@tonic-gate		fi
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate		echo  "\tnext host to add:  \c"
2530Sstevel@tonic-gate
2540Sstevel@tonic-gate		while read h ; test -n "$h"
2550Sstevel@tonic-gate		do
256*5728Spwernau			#
257*5728Spwernau			# Host should be in the v4 or v6 hosts file or
258*5728Spwernau			# reasonably resemble an IP address.  We'll do a
259*5728Spwernau			# sanity check that a v4 addr is one word consisting
260*5728Spwernau			# of only numbers and the "." character,
261*5728Spwernau			# which should guard against fully qualified
262*5728Spwernau			# hostnames and most malformed entries.  IPv6
263*5728Spwernau			# addresses can be numbers, hex letters, and have
264*5728Spwernau			# at least one ":" character and possibly one or
265*5728Spwernau			# more "." characters for embedded v4 addresses
266*5728Spwernau			#
267*5728Spwernau			if ( grep $h $hosts_file $hosts6_file > /dev/null ) || \
268*5728Spwernau			    ( test $clientp = T && `is_valid_ipaddr $h` )
2690Sstevel@tonic-gate			then
2700Sstevel@tonic-gate				echo $h >> $hf
2710Sstevel@tonic-gate				echo  "\tnext host to add:  \c"
2720Sstevel@tonic-gate			else
273*5728Spwernau				echo "host $h not found in $hosts_file or" \
274*5728Spwernau				    "$hosts6_file.\nNot added to the list."
2750Sstevel@tonic-gate				echo ""
2760Sstevel@tonic-gate				echo  "Do you wish to abort [y/n: y]  \c"
2770Sstevel@tonic-gate				read cont_ok
2780Sstevel@tonic-gate
2790Sstevel@tonic-gate				case $cont_ok in
2800Sstevel@tonic-gate				n*)	echo "\tnext host to add:  \c";;
2810Sstevel@tonic-gate				N*)	echo "\tnext host to add:  \c";;
2820Sstevel@tonic-gate				*)	exit 1;;
2830Sstevel@tonic-gate				esac
2840Sstevel@tonic-gate			fi
2850Sstevel@tonic-gate
2860Sstevel@tonic-gate		done
2870Sstevel@tonic-gate
2880Sstevel@tonic-gate		echo ""
2890Sstevel@tonic-gate		if [ -s $hf ]
2900Sstevel@tonic-gate		then
2910Sstevel@tonic-gate			echo "The current list of yp servers looks like this:"
2920Sstevel@tonic-gate			echo ""
2930Sstevel@tonic-gate			cat $hf
2940Sstevel@tonic-gate			echo ""
2950Sstevel@tonic-gate			echo "Is this correct?  [y/n: y]  \c"
2960Sstevel@tonic-gate		else
2970Sstevel@tonic-gate			echo "You have not added any server information."
2980Sstevel@tonic-gate			echo ""
2990Sstevel@tonic-gate			echo "Do you still wish to exit? [y/n: y]  \c"
3000Sstevel@tonic-gate		fi
3010Sstevel@tonic-gate
3020Sstevel@tonic-gate		read hlist_ok
3030Sstevel@tonic-gate
3040Sstevel@tonic-gate		case $hlist_ok in
3050Sstevel@tonic-gate		n*)	got_host_list=F
3060Sstevel@tonic-gate			first_time=F
3070Sstevel@tonic-gate			rm $hf
3080Sstevel@tonic-gate			echo "Let's try the whole thing again...";;
3090Sstevel@tonic-gate		N*)	got_host_list=F
3100Sstevel@tonic-gate			first_time=F
3110Sstevel@tonic-gate			rm $hf
3120Sstevel@tonic-gate			echo "Let's try the whole thing again...";;
3130Sstevel@tonic-gate		*)	got_host_list=T;;
3140Sstevel@tonic-gate		esac
3150Sstevel@tonic-gate	done
3160Sstevel@tonic-gate
3170Sstevel@tonic-gate	if [ -s $hf ]
3180Sstevel@tonic-gate	then
3190Sstevel@tonic-gate		cp  $hf $binding_file
3200Sstevel@tonic-gate	fi
3210Sstevel@tonic-gatefi
3220Sstevel@tonic-gate
3230Sstevel@tonic-gate#
3240Sstevel@tonic-gate# Start client service on next boot, unless we're establishing a slave
3250Sstevel@tonic-gate# server, in which case the binding is needed now (or should be
3260Sstevel@tonic-gate# preserved).
3270Sstevel@tonic-gate#
3280Sstevel@tonic-gateif [ $slavep = T ]
3290Sstevel@tonic-gatethen
3300Sstevel@tonic-gate	enable_this_boot network/nis/client:default
3310Sstevel@tonic-gateelse
3320Sstevel@tonic-gate	enable_next_boot network/nis/client:default
3330Sstevel@tonic-gatefi
3340Sstevel@tonic-gate
3350Sstevel@tonic-gate#
3360Sstevel@tonic-gate# As a client, our configuration is correct once a binding file is
3370Sstevel@tonic-gate# established, and so we can exit (making sure we're no longer a server,
3380Sstevel@tonic-gate# of course).
3390Sstevel@tonic-gate#
3400Sstevel@tonic-gateif [ $clientp = T ]
3410Sstevel@tonic-gatethen
3420Sstevel@tonic-gate	rm $hf
3430Sstevel@tonic-gate	/usr/sbin/svcadm disable network/nis/server:default
3440Sstevel@tonic-gate	/usr/sbin/svcadm disable network/nis/xfr:default
3450Sstevel@tonic-gate	/usr/sbin/svcadm disable network/nis/passwd:default
3460Sstevel@tonic-gate	/usr/sbin/svcadm disable network/nis/update:default
3470Sstevel@tonic-gate	exit 0
3480Sstevel@tonic-gatefi
3490Sstevel@tonic-gate
3500Sstevel@tonic-gateif [ $slavep = T ]
3510Sstevel@tonic-gatethen
3520Sstevel@tonic-gate	if [ $host = $master ]
3530Sstevel@tonic-gate	then
3540Sstevel@tonic-gate		echo "\
3550Sstevel@tonic-gateThe host specified should be a running master yp server, not this machine."
3560Sstevel@tonic-gate		exit 1
3570Sstevel@tonic-gate	fi
3580Sstevel@tonic-gate
3590Sstevel@tonic-gate	maps=`ypwhich -m | egrep $master$| awk '{ printf("%s ",$1) }' -`
3600Sstevel@tonic-gate	if [ -z "$maps" ]
3610Sstevel@tonic-gate	then
3620Sstevel@tonic-gate		echo "Can't enumerate maps from $master. Please check that it is running."
3630Sstevel@tonic-gate		exit 1
3640Sstevel@tonic-gate	fi
3650Sstevel@tonic-gatefi
3660Sstevel@tonic-gate
3670Sstevel@tonic-gateecho ""
3680Sstevel@tonic-gate
3690Sstevel@tonic-gateecho "Installing the YP database will require that you answer a few questions."
3700Sstevel@tonic-gateecho "Questions will all be asked at the beginning of the procedure."
3710Sstevel@tonic-gateecho ""
3720Sstevel@tonic-gateecho "Do you want this procedure to quit on non-fatal errors? [y/n: n]  \c"
3730Sstevel@tonic-gateread doexit
3740Sstevel@tonic-gate
3750Sstevel@tonic-gatecase $doexit in
3760Sstevel@tonic-gatey*)	exit_on_error=T;;
3770Sstevel@tonic-gateY*)	exit_on_error=T;;
3780Sstevel@tonic-gate*)	echo "\
3790Sstevel@tonic-gateOK, please remember to go back and redo manually whatever fails.  If you"
3800Sstevel@tonic-gate	echo "\
3810Sstevel@tonic-gatedon't, some part of the system (perhaps the yp itself) won't work.";;
3820Sstevel@tonic-gateesac
3830Sstevel@tonic-gate
3840Sstevel@tonic-gateecho "The yp domain directory is $yproot_dir""/""$def_dom"
3850Sstevel@tonic-gate
3860Sstevel@tonic-gatefor dir in $yproot_dir/$def_dom
3870Sstevel@tonic-gatedo
3880Sstevel@tonic-gate
3890Sstevel@tonic-gate	if [ -d $dir ]; then
3900Sstevel@tonic-gate		echo  "Can we destroy the existing $dir and its contents? [y/n: n]  \c"
3910Sstevel@tonic-gate		read kill_old_dir
3920Sstevel@tonic-gate
3930Sstevel@tonic-gate		case $kill_old_dir in
3940Sstevel@tonic-gate		y*)	rm -r -f $dir
3950Sstevel@tonic-gate
3960Sstevel@tonic-gate			if [ $?  -ne 0 ]
3970Sstevel@tonic-gate			then
3980Sstevel@tonic-gate			echo "Can't clean up old directory $dir.  Fatal error."
3990Sstevel@tonic-gate				exit 1
4000Sstevel@tonic-gate			fi;;
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate		Y*)	rm -r -f $dir
4030Sstevel@tonic-gate
4040Sstevel@tonic-gate			if [ $?  -ne 0 ]
4050Sstevel@tonic-gate			then
4060Sstevel@tonic-gate			echo "Can't clean up old directory $dir.  Fatal error."
4070Sstevel@tonic-gate				exit 1
4080Sstevel@tonic-gate			fi;;
4090Sstevel@tonic-gate
4100Sstevel@tonic-gate		*)    echo "OK, please clean it up by hand and start again.  Bye"
4110Sstevel@tonic-gate			exit 0;;
4120Sstevel@tonic-gate		esac
4130Sstevel@tonic-gate	fi
4140Sstevel@tonic-gate
4150Sstevel@tonic-gate	mkdir $dir
4160Sstevel@tonic-gate
4170Sstevel@tonic-gate	if [ $?  -ne 0 ]
4180Sstevel@tonic-gate	then
4190Sstevel@tonic-gate		echo "Can't make new directory $dir.  Fatal error."
4200Sstevel@tonic-gate		exit 1
4210Sstevel@tonic-gate	fi
4220Sstevel@tonic-gate
4230Sstevel@tonic-gatedone
4240Sstevel@tonic-gate
4250Sstevel@tonic-gateif [ $slavep = T ]
4260Sstevel@tonic-gatethen
4270Sstevel@tonic-gate	echo "\
4280Sstevel@tonic-gateThere will be no further questions. The remainder of the procedure should take"
4290Sstevel@tonic-gate	echo "a few minutes, to copy the data bases from $master."
4300Sstevel@tonic-gate
4310Sstevel@tonic-gate	for dom in  $real_def_dom
4320Sstevel@tonic-gate	do
4330Sstevel@tonic-gate		for map in $maps
4340Sstevel@tonic-gate		do
4350Sstevel@tonic-gate			echo "Transferring $map..."
4360Sstevel@tonic-gate			$XFR -h $master -c -d $dom $map
4370Sstevel@tonic-gate
4380Sstevel@tonic-gate			if [ $?  -ne 0 ]
4390Sstevel@tonic-gate			then
4400Sstevel@tonic-gate				errors_in_setup=T
4410Sstevel@tonic-gate
4420Sstevel@tonic-gate				if [ $exit_on_error = T ]
4430Sstevel@tonic-gate				then
4440Sstevel@tonic-gate					exit 1
4450Sstevel@tonic-gate				fi
4460Sstevel@tonic-gate			fi
4470Sstevel@tonic-gate		done
4480Sstevel@tonic-gate	done
4490Sstevel@tonic-gate
4500Sstevel@tonic-gate	echo ""
4510Sstevel@tonic-gate	echo  "${host}'s nis data base has been set up\n"
4520Sstevel@tonic-gate
4530Sstevel@tonic-gate	if [ $errors_in_setup = T ]
4540Sstevel@tonic-gate	then
4550Sstevel@tonic-gate		echo " with errors.  Please remember"
4560Sstevel@tonic-gate		echo "to figure out what went wrong, and fix it."
4570Sstevel@tonic-gate	else
4580Sstevel@tonic-gate		echo " without any errors."
4590Sstevel@tonic-gate	fi
4600Sstevel@tonic-gate
4610Sstevel@tonic-gate	# enable slave services
4620Sstevel@tonic-gate	enable_this_boot network/nis/server:default
4630Sstevel@tonic-gate
4640Sstevel@tonic-gate	enable_this_boot network/nis/client:default
4650Sstevel@tonic-gate
4660Sstevel@tonic-gate	exit 0
4670Sstevel@tonic-gateelse
4680Sstevel@tonic-gate
4690Sstevel@tonic-gate	rm -f $yproot_dir/*.time
4700Sstevel@tonic-gate
4710Sstevel@tonic-gate	echo "\
4720Sstevel@tonic-gateThere will be no further questions. The remainder of the procedure should take"
4730Sstevel@tonic-gate	echo "5 to 10 minutes."
4740Sstevel@tonic-gate
4750Sstevel@tonic-gate	echo "Building $yproot_dir/$def_dom/ypservers..."
4760Sstevel@tonic-gate	makedbm $hf $yproot_dir/$def_dom/$ypservers_map
4770Sstevel@tonic-gate
4780Sstevel@tonic-gate	if [ $?  -ne 0 ]
4790Sstevel@tonic-gate	then
4800Sstevel@tonic-gate		echo "\
4810Sstevel@tonic-gateCouldn't build yp data base $yproot_dir/$def_dom/$ypservers_map."
4820Sstevel@tonic-gate		errors_in_setup=T
4830Sstevel@tonic-gate
4840Sstevel@tonic-gate		if [ $exit_on_error = T ]
4850Sstevel@tonic-gate		then
4860Sstevel@tonic-gate			exit 1
4870Sstevel@tonic-gate		fi
4880Sstevel@tonic-gate	fi
4890Sstevel@tonic-gate
4900Sstevel@tonic-gate	rm $hf
4910Sstevel@tonic-gate
4920Sstevel@tonic-gate	in_pwd=`pwd`
4930Sstevel@tonic-gate	cd $yproot_dir
4940Sstevel@tonic-gate	echo  "Running \c"
4950Sstevel@tonic-gate	echo  $yproot_dir "\c"
4960Sstevel@tonic-gate	echo "/Makefile..."
4970Sstevel@tonic-gate	make NOPUSH=1
4980Sstevel@tonic-gate
4990Sstevel@tonic-gate	if [ $?  -ne 0 ]
5000Sstevel@tonic-gate	then
5010Sstevel@tonic-gate		echo "\
5020Sstevel@tonic-gateError running Makefile."
5030Sstevel@tonic-gate		errors_in_setup=T
5040Sstevel@tonic-gate
5050Sstevel@tonic-gate		if [ $exit_on_error = T ]
5060Sstevel@tonic-gate		then
5070Sstevel@tonic-gate			exit 1
5080Sstevel@tonic-gate		fi
5090Sstevel@tonic-gate	fi
5100Sstevel@tonic-gate
5110Sstevel@tonic-gate	cd $in_pwd
5120Sstevel@tonic-gate	echo ""
5130Sstevel@tonic-gate	echo  "\
5140Sstevel@tonic-gate$host has been set up as a yp master server\c"
5150Sstevel@tonic-gate
5160Sstevel@tonic-gate	if [ $errors_in_setup = T ]
5170Sstevel@tonic-gate	then
5180Sstevel@tonic-gate		echo " with errors.  Please remember"
5190Sstevel@tonic-gate		echo "to figure out what went wrong, and fix it."
5200Sstevel@tonic-gate	else
5210Sstevel@tonic-gate		echo " without any errors."
5220Sstevel@tonic-gate	fi
5230Sstevel@tonic-gate
5240Sstevel@tonic-gate	echo ""
5250Sstevel@tonic-gate	echo "\
5260Sstevel@tonic-gateIf there are running slave yp servers, run yppush now for any data bases"
5270Sstevel@tonic-gate	echo "\
5280Sstevel@tonic-gatewhich have been changed.  If there are no running slaves, run ypinit on"
5290Sstevel@tonic-gate	echo "\
5300Sstevel@tonic-gatethose hosts which are to be slave servers."
5310Sstevel@tonic-gate
5320Sstevel@tonic-gate	# enable master services
5330Sstevel@tonic-gate	enable_this_boot network/nis/server:default
5340Sstevel@tonic-gate	enable_this_boot network/nis/xfr:default
5350Sstevel@tonic-gate	enable_this_boot network/nis/passwd:default
5360Sstevel@tonic-gate	enable_this_boot network/nis/update:default
5370Sstevel@tonic-gate
5380Sstevel@tonic-gate	enable_this_boot network/nis/client:default
5390Sstevel@tonic-gatefi
540