xref: /titanic_52/usr/src/cmd/ypcmd/ypinit.sh (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate#!/sbin/sh
2*7c478bd9Sstevel@tonic-gate#
3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate#
5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate# with the License.
9*7c478bd9Sstevel@tonic-gate#
10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate# and limitations under the License.
14*7c478bd9Sstevel@tonic-gate#
15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate#
21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate#
23*7c478bd9Sstevel@tonic-gate#
24*7c478bd9Sstevel@tonic-gate# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
25*7c478bd9Sstevel@tonic-gate# Use is subject to license terms.
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
28*7c478bd9Sstevel@tonic-gate#	  All Rights Reserved
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate# Portions of this source code were derived from Berkeley 4.3 BSD
31*7c478bd9Sstevel@tonic-gate# under license from the Regents of the University of California.
32*7c478bd9Sstevel@tonic-gate
33*7c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
34*7c478bd9Sstevel@tonic-gate
35*7c478bd9Sstevel@tonic-gate# set -xv
36*7c478bd9Sstevel@tonic-gateYPXFR=/usr/lib/netsvc/yp/ypxfr
37*7c478bd9Sstevel@tonic-gateMAKEPATH=/usr/ccs/bin
38*7c478bd9Sstevel@tonic-gatemaps="publickey publickey.byname"
39*7c478bd9Sstevel@tonic-gateyproot_dir=/var/yp
40*7c478bd9Sstevel@tonic-gateyproot_exe=/usr/sbin/yp
41*7c478bd9Sstevel@tonic-gatehf=/var/run/ypservers.$$
42*7c478bd9Sstevel@tonic-gateXFR=${YPXFR}
43*7c478bd9Sstevel@tonic-gate
44*7c478bd9Sstevel@tonic-gatehosts_file=/etc/hosts
45*7c478bd9Sstevel@tonic-gatehosts6_file=/etc/inet/ipnodes
46*7c478bd9Sstevel@tonic-gateclientp=F
47*7c478bd9Sstevel@tonic-gatemasterp=F
48*7c478bd9Sstevel@tonic-gateslavep=F
49*7c478bd9Sstevel@tonic-gatehost=""
50*7c478bd9Sstevel@tonic-gatedef_dom=""
51*7c478bd9Sstevel@tonic-gatemaster=""
52*7c478bd9Sstevel@tonic-gategot_host_list=F
53*7c478bd9Sstevel@tonic-gatefirst_time=T
54*7c478bd9Sstevel@tonic-gateexit_on_error=F
55*7c478bd9Sstevel@tonic-gateerrors_in_setup=F
56*7c478bd9Sstevel@tonic-gate
57*7c478bd9Sstevel@tonic-gateenable_next_boot () {
58*7c478bd9Sstevel@tonic-gate	/usr/sbin/svcadm disable -t $1
59*7c478bd9Sstevel@tonic-gate	[ $? = 0 ] || echo "ypinit: unable to temporarily disable $1"
60*7c478bd9Sstevel@tonic-gate	/usr/sbin/svccfg -s $1 \
61*7c478bd9Sstevel@tonic-gate	    setprop general/enabled = true
62*7c478bd9Sstevel@tonic-gate	[ $? = 0 ] || echo "ypinit: unable to enable $1 for next boot"
63*7c478bd9Sstevel@tonic-gate}
64*7c478bd9Sstevel@tonic-gate
65*7c478bd9Sstevel@tonic-gateenable_this_boot () {
66*7c478bd9Sstevel@tonic-gate	/usr/sbin/svcadm enable $1
67*7c478bd9Sstevel@tonic-gate	[ $? = 0 ] || echo "ypinit: unable to enable $1"
68*7c478bd9Sstevel@tonic-gate}
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gatePATH=/bin:/usr/bin:/usr/etc:/usr/sbin:$yproot_exe:$MAKEPATH:$PATH
71*7c478bd9Sstevel@tonic-gateexport PATH
72*7c478bd9Sstevel@tonic-gate
73*7c478bd9Sstevel@tonic-gate# To do cleanup
74*7c478bd9Sstevel@tonic-gatetrap '/usr/bin/rm -f $hf' 0 1 2 3 15
75*7c478bd9Sstevel@tonic-gate
76*7c478bd9Sstevel@tonic-gatecase $# in
77*7c478bd9Sstevel@tonic-gate1)	case $1 in
78*7c478bd9Sstevel@tonic-gate	-c)	clientp=T;;
79*7c478bd9Sstevel@tonic-gate	-m)	masterp=T;;
80*7c478bd9Sstevel@tonic-gate	*)	echo 'usage:'
81*7c478bd9Sstevel@tonic-gate		echo '	ypinit -c'
82*7c478bd9Sstevel@tonic-gate		echo '	ypinit -m'
83*7c478bd9Sstevel@tonic-gate		echo '	ypinit -s master_server'
84*7c478bd9Sstevel@tonic-gate		echo ""
85*7c478bd9Sstevel@tonic-gate		echo "\
86*7c478bd9Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master "
87*7c478bd9Sstevel@tonic-gate                echo "\
88*7c478bd9Sstevel@tonic-gateyp server data base, and -s is used for a slave data base."
89*7c478bd9Sstevel@tonic-gate		echo "\
90*7c478bd9Sstevel@tonic-gatemaster_server must be an existing reachable yp server."
91*7c478bd9Sstevel@tonic-gate		exit 1;;
92*7c478bd9Sstevel@tonic-gate	esac;;
93*7c478bd9Sstevel@tonic-gate
94*7c478bd9Sstevel@tonic-gate2)	case $1 in
95*7c478bd9Sstevel@tonic-gate	-s)	slavep=T; master=$2;
96*7c478bd9Sstevel@tonic-gate		if ( grep $master $hosts_file $hosts6_file > /dev/null )
97*7c478bd9Sstevel@tonic-gate		then
98*7c478bd9Sstevel@tonic-gate			echo ""
99*7c478bd9Sstevel@tonic-gate		else
100*7c478bd9Sstevel@tonic-gate			echo "server not found in $hosts_file or $hosts6_file"
101*7c478bd9Sstevel@tonic-gate			exit 1
102*7c478bd9Sstevel@tonic-gate		fi;;
103*7c478bd9Sstevel@tonic-gate
104*7c478bd9Sstevel@tonic-gate	*)	echo 'usage:'
105*7c478bd9Sstevel@tonic-gate		echo '	ypinit -c'
106*7c478bd9Sstevel@tonic-gate		echo '	ypinit -m'
107*7c478bd9Sstevel@tonic-gate		echo '	ypinit -s master_server'
108*7c478bd9Sstevel@tonic-gate		echo ""
109*7c478bd9Sstevel@tonic-gate		echo "\
110*7c478bd9Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master "
111*7c478bd9Sstevel@tonic-gate                echo "\
112*7c478bd9Sstevel@tonic-gateyp server data base, and -s is used for a slave data base."
113*7c478bd9Sstevel@tonic-gate		echo "\
114*7c478bd9Sstevel@tonic-gatemaster_server must be an existing reachable yp server."
115*7c478bd9Sstevel@tonic-gate		exit 1;;
116*7c478bd9Sstevel@tonic-gate	esac;;
117*7c478bd9Sstevel@tonic-gate3)	case $1 in
118*7c478bd9Sstevel@tonic-gate	-c)	clientp=T;;
119*7c478bd9Sstevel@tonic-gate	*)	echo 'usage:'
120*7c478bd9Sstevel@tonic-gate		echo '	ypinit -c'
121*7c478bd9Sstevel@tonic-gate		echo '	ypinit -m'
122*7c478bd9Sstevel@tonic-gate		echo '	ypinit -s master_server'
123*7c478bd9Sstevel@tonic-gate		echo ""
124*7c478bd9Sstevel@tonic-gate		echo "\
125*7c478bd9Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master "
126*7c478bd9Sstevel@tonic-gate                echo "\
127*7c478bd9Sstevel@tonic-gateyp server data base, and -s is used for a slave data base."
128*7c478bd9Sstevel@tonic-gate		echo "\
129*7c478bd9Sstevel@tonic-gatemaster_server must be an existing reachable yp server."
130*7c478bd9Sstevel@tonic-gate		exit 1;;
131*7c478bd9Sstevel@tonic-gate	esac;;
132*7c478bd9Sstevel@tonic-gate
133*7c478bd9Sstevel@tonic-gate*)	echo 'usage:'
134*7c478bd9Sstevel@tonic-gate	echo '	ypinit -c'
135*7c478bd9Sstevel@tonic-gate	echo '	ypinit -m'
136*7c478bd9Sstevel@tonic-gate	echo '	ypinit -s master_server'
137*7c478bd9Sstevel@tonic-gate	echo ""
138*7c478bd9Sstevel@tonic-gate	echo "\
139*7c478bd9Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master "
140*7c478bd9Sstevel@tonic-gate	echo "\
141*7c478bd9Sstevel@tonic-gateyp server data base, and -s is used for a slave data base."
142*7c478bd9Sstevel@tonic-gate	echo "\
143*7c478bd9Sstevel@tonic-gatemaster_server must be an existing reachable yp server."
144*7c478bd9Sstevel@tonic-gate	exit 1;;
145*7c478bd9Sstevel@tonic-gateesac
146*7c478bd9Sstevel@tonic-gate
147*7c478bd9Sstevel@tonic-gateif [ $? -ne 0 ]
148*7c478bd9Sstevel@tonic-gatethen
149*7c478bd9Sstevel@tonic-gate	echo "\
150*7c478bd9Sstevel@tonic-gateYou have to be the superuser to run this.  Please log in as root."
151*7c478bd9Sstevel@tonic-gate	exit 1
152*7c478bd9Sstevel@tonic-gatefi
153*7c478bd9Sstevel@tonic-gate
154*7c478bd9Sstevel@tonic-gatehost=`uname -n`
155*7c478bd9Sstevel@tonic-gate
156*7c478bd9Sstevel@tonic-gateif [ $? -ne 0 ]
157*7c478bd9Sstevel@tonic-gatethen
158*7c478bd9Sstevel@tonic-gate	echo "Can't get local host's name.  Please check your path."
159*7c478bd9Sstevel@tonic-gate	exit 1
160*7c478bd9Sstevel@tonic-gatefi
161*7c478bd9Sstevel@tonic-gate
162*7c478bd9Sstevel@tonic-gateif [ -z "$host" ]
163*7c478bd9Sstevel@tonic-gatethen
164*7c478bd9Sstevel@tonic-gate	echo "The local host's name hasn't been set.  Please set it."
165*7c478bd9Sstevel@tonic-gate	exit 1
166*7c478bd9Sstevel@tonic-gatefi
167*7c478bd9Sstevel@tonic-gate
168*7c478bd9Sstevel@tonic-gatedef_dom=`domainname`
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gateif [ $? -ne 0 ]
171*7c478bd9Sstevel@tonic-gatethen
172*7c478bd9Sstevel@tonic-gate	echo "Can't get local host's domain name.  Please check your path."
173*7c478bd9Sstevel@tonic-gate	exit 1
174*7c478bd9Sstevel@tonic-gatefi
175*7c478bd9Sstevel@tonic-gate
176*7c478bd9Sstevel@tonic-gateif [ -z "$def_dom" ]
177*7c478bd9Sstevel@tonic-gatethen
178*7c478bd9Sstevel@tonic-gate	echo "The local host's domain name hasn't been set.  Please set it."
179*7c478bd9Sstevel@tonic-gate	exit 1
180*7c478bd9Sstevel@tonic-gatefi
181*7c478bd9Sstevel@tonic-gate
182*7c478bd9Sstevel@tonic-gatedomainname $def_dom
183*7c478bd9Sstevel@tonic-gatereal_def_dom=$def_dom
184*7c478bd9Sstevel@tonic-gate#def_dom=`ypalias -d $def_dom`
185*7c478bd9Sstevel@tonic-gateypservers_map=`ypalias ypservers`
186*7c478bd9Sstevel@tonic-gatedomain_dir="$yproot_dir""/""$def_dom"
187*7c478bd9Sstevel@tonic-gatebinding_dir="$yproot_dir""/binding/""$def_dom"
188*7c478bd9Sstevel@tonic-gatebinding_file="$yproot_dir""/binding/""$def_dom""/ypservers"
189*7c478bd9Sstevel@tonic-gate
190*7c478bd9Sstevel@tonic-gateif [ ! -d $yproot_dir -o -f $yproot_dir ]
191*7c478bd9Sstevel@tonic-gatethen
192*7c478bd9Sstevel@tonic-gate    echo "\
193*7c478bd9Sstevel@tonic-gateThe directory $yproot_dir doesn't exist.  Restore it from the distribution."
194*7c478bd9Sstevel@tonic-gate	exit 1
195*7c478bd9Sstevel@tonic-gatefi
196*7c478bd9Sstevel@tonic-gate
197*7c478bd9Sstevel@tonic-gate# add domainname and ypservers aliases to aliases file
198*7c478bd9Sstevel@tonic-gateecho ypservers $ypservers_map >> $yproot_dir/aliases
199*7c478bd9Sstevel@tonic-gateecho $real_def_dom $def_dom >> $yproot_dir/aliases
200*7c478bd9Sstevel@tonic-gatesort $yproot_dir/aliases | uniq > /var/run/.ypaliases; mv /var/run/.ypaliases $yproot_dir/aliases
201*7c478bd9Sstevel@tonic-gate
202*7c478bd9Sstevel@tonic-gateif [ ! -d "$yproot_dir"/binding ]
203*7c478bd9Sstevel@tonic-gatethen
204*7c478bd9Sstevel@tonic-gate	mkdir "$yproot_dir"/binding
205*7c478bd9Sstevel@tonic-gatefi
206*7c478bd9Sstevel@tonic-gate
207*7c478bd9Sstevel@tonic-gateif [ ! -d  $binding_dir ]
208*7c478bd9Sstevel@tonic-gatethen
209*7c478bd9Sstevel@tonic-gate	mkdir  "$binding_dir"
210*7c478bd9Sstevel@tonic-gatefi
211*7c478bd9Sstevel@tonic-gate
212*7c478bd9Sstevel@tonic-gateif [ $slavep = F ]
213*7c478bd9Sstevel@tonic-gatethen
214*7c478bd9Sstevel@tonic-gate	while [ $got_host_list = F ]; do
215*7c478bd9Sstevel@tonic-gate		touch $hf    # make sure file exists
216*7c478bd9Sstevel@tonic-gate		echo ""
217*7c478bd9Sstevel@tonic-gate		echo "\
218*7c478bd9Sstevel@tonic-gateIn order for NIS to operate sucessfully, we have to construct a list of the "
219*7c478bd9Sstevel@tonic-gate		echo "\
220*7c478bd9Sstevel@tonic-gateNIS servers.  Please continue to add the names for YP servers in order of"
221*7c478bd9Sstevel@tonic-gate		echo "\
222*7c478bd9Sstevel@tonic-gatepreference, one per line.  When you are done with the list, type a <control D>"
223*7c478bd9Sstevel@tonic-gate		echo "\
224*7c478bd9Sstevel@tonic-gateor a return on a line by itself."
225*7c478bd9Sstevel@tonic-gate		if [ $masterp = T ]
226*7c478bd9Sstevel@tonic-gate		then
227*7c478bd9Sstevel@tonic-gate			echo $host > $hf
228*7c478bd9Sstevel@tonic-gate			echo "\tnext host to add:  $host"
229*7c478bd9Sstevel@tonic-gate		elif [ -f $binding_file ]
230*7c478bd9Sstevel@tonic-gate		then
231*7c478bd9Sstevel@tonic-gate			if [ $first_time = T ]
232*7c478bd9Sstevel@tonic-gate			then
233*7c478bd9Sstevel@tonic-gate				for h in `cat $binding_file`
234*7c478bd9Sstevel@tonic-gate				do
235*7c478bd9Sstevel@tonic-gate					echo $h >> $hf
236*7c478bd9Sstevel@tonic-gate					echo "\tnext host to add:  $h"
237*7c478bd9Sstevel@tonic-gate				done
238*7c478bd9Sstevel@tonic-gate			fi
239*7c478bd9Sstevel@tonic-gate		fi
240*7c478bd9Sstevel@tonic-gate
241*7c478bd9Sstevel@tonic-gate		echo  "\tnext host to add:  \c"
242*7c478bd9Sstevel@tonic-gate
243*7c478bd9Sstevel@tonic-gate		while read h ; test -n "$h"
244*7c478bd9Sstevel@tonic-gate		do
245*7c478bd9Sstevel@tonic-gate			if ( grep $h $hosts_file $hosts6_file > /dev/null )
246*7c478bd9Sstevel@tonic-gate			then
247*7c478bd9Sstevel@tonic-gate				echo $h >> $hf
248*7c478bd9Sstevel@tonic-gate				echo  "\tnext host to add:  \c"
249*7c478bd9Sstevel@tonic-gate			else
250*7c478bd9Sstevel@tonic-gate				echo "host $h not found in $hosts_file or $hosts6_file. Not added to the list"
251*7c478bd9Sstevel@tonic-gate				echo ""
252*7c478bd9Sstevel@tonic-gate				echo  "Do you wish to abort [y/n: y]  \c"
253*7c478bd9Sstevel@tonic-gate				read cont_ok
254*7c478bd9Sstevel@tonic-gate
255*7c478bd9Sstevel@tonic-gate				case $cont_ok in
256*7c478bd9Sstevel@tonic-gate				n*)	echo "\tnext host to add:  \c";;
257*7c478bd9Sstevel@tonic-gate				N*)	echo "\tnext host to add:  \c";;
258*7c478bd9Sstevel@tonic-gate				*)	exit 1;;
259*7c478bd9Sstevel@tonic-gate				esac
260*7c478bd9Sstevel@tonic-gate			fi
261*7c478bd9Sstevel@tonic-gate
262*7c478bd9Sstevel@tonic-gate		done
263*7c478bd9Sstevel@tonic-gate
264*7c478bd9Sstevel@tonic-gate		echo ""
265*7c478bd9Sstevel@tonic-gate		if [ -s $hf ]
266*7c478bd9Sstevel@tonic-gate		then
267*7c478bd9Sstevel@tonic-gate			echo "The current list of yp servers looks like this:"
268*7c478bd9Sstevel@tonic-gate			echo ""
269*7c478bd9Sstevel@tonic-gate			cat $hf
270*7c478bd9Sstevel@tonic-gate			echo ""
271*7c478bd9Sstevel@tonic-gate			echo "Is this correct?  [y/n: y]  \c"
272*7c478bd9Sstevel@tonic-gate		else
273*7c478bd9Sstevel@tonic-gate			echo "You have not added any server information."
274*7c478bd9Sstevel@tonic-gate			echo ""
275*7c478bd9Sstevel@tonic-gate			echo "Do you still wish to exit? [y/n: y]  \c"
276*7c478bd9Sstevel@tonic-gate		fi
277*7c478bd9Sstevel@tonic-gate
278*7c478bd9Sstevel@tonic-gate		read hlist_ok
279*7c478bd9Sstevel@tonic-gate
280*7c478bd9Sstevel@tonic-gate		case $hlist_ok in
281*7c478bd9Sstevel@tonic-gate		n*)	got_host_list=F
282*7c478bd9Sstevel@tonic-gate			first_time=F
283*7c478bd9Sstevel@tonic-gate			rm $hf
284*7c478bd9Sstevel@tonic-gate			echo "Let's try the whole thing again...";;
285*7c478bd9Sstevel@tonic-gate		N*)	got_host_list=F
286*7c478bd9Sstevel@tonic-gate			first_time=F
287*7c478bd9Sstevel@tonic-gate			rm $hf
288*7c478bd9Sstevel@tonic-gate			echo "Let's try the whole thing again...";;
289*7c478bd9Sstevel@tonic-gate		*)	got_host_list=T;;
290*7c478bd9Sstevel@tonic-gate		esac
291*7c478bd9Sstevel@tonic-gate	done
292*7c478bd9Sstevel@tonic-gate
293*7c478bd9Sstevel@tonic-gate	if [ -s $hf ]
294*7c478bd9Sstevel@tonic-gate	then
295*7c478bd9Sstevel@tonic-gate		cp  $hf $binding_file
296*7c478bd9Sstevel@tonic-gate	fi
297*7c478bd9Sstevel@tonic-gatefi
298*7c478bd9Sstevel@tonic-gate
299*7c478bd9Sstevel@tonic-gate#
300*7c478bd9Sstevel@tonic-gate# Start client service on next boot, unless we're establishing a slave
301*7c478bd9Sstevel@tonic-gate# server, in which case the binding is needed now (or should be
302*7c478bd9Sstevel@tonic-gate# preserved).
303*7c478bd9Sstevel@tonic-gate#
304*7c478bd9Sstevel@tonic-gateif [ $slavep = T ]
305*7c478bd9Sstevel@tonic-gatethen
306*7c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/client:default
307*7c478bd9Sstevel@tonic-gateelse
308*7c478bd9Sstevel@tonic-gate	enable_next_boot network/nis/client:default
309*7c478bd9Sstevel@tonic-gatefi
310*7c478bd9Sstevel@tonic-gate
311*7c478bd9Sstevel@tonic-gate#
312*7c478bd9Sstevel@tonic-gate# As a client, our configuration is correct once a binding file is
313*7c478bd9Sstevel@tonic-gate# established, and so we can exit (making sure we're no longer a server,
314*7c478bd9Sstevel@tonic-gate# of course).
315*7c478bd9Sstevel@tonic-gate#
316*7c478bd9Sstevel@tonic-gateif [ $clientp = T ]
317*7c478bd9Sstevel@tonic-gatethen
318*7c478bd9Sstevel@tonic-gate	rm $hf
319*7c478bd9Sstevel@tonic-gate	/usr/sbin/svcadm disable network/nis/server:default
320*7c478bd9Sstevel@tonic-gate	/usr/sbin/svcadm disable network/nis/xfr:default
321*7c478bd9Sstevel@tonic-gate	/usr/sbin/svcadm disable network/nis/passwd:default
322*7c478bd9Sstevel@tonic-gate	/usr/sbin/svcadm disable network/nis/update:default
323*7c478bd9Sstevel@tonic-gate	exit 0
324*7c478bd9Sstevel@tonic-gatefi
325*7c478bd9Sstevel@tonic-gate
326*7c478bd9Sstevel@tonic-gateif [ $slavep = T ]
327*7c478bd9Sstevel@tonic-gatethen
328*7c478bd9Sstevel@tonic-gate	if [ $host = $master ]
329*7c478bd9Sstevel@tonic-gate	then
330*7c478bd9Sstevel@tonic-gate		echo "\
331*7c478bd9Sstevel@tonic-gateThe host specified should be a running master yp server, not this machine."
332*7c478bd9Sstevel@tonic-gate		exit 1
333*7c478bd9Sstevel@tonic-gate	fi
334*7c478bd9Sstevel@tonic-gate
335*7c478bd9Sstevel@tonic-gate	maps=`ypwhich -m | egrep $master$| awk '{ printf("%s ",$1) }' -`
336*7c478bd9Sstevel@tonic-gate	if [ -z "$maps" ]
337*7c478bd9Sstevel@tonic-gate	then
338*7c478bd9Sstevel@tonic-gate		echo "Can't enumerate maps from $master. Please check that it is running."
339*7c478bd9Sstevel@tonic-gate		exit 1
340*7c478bd9Sstevel@tonic-gate	fi
341*7c478bd9Sstevel@tonic-gatefi
342*7c478bd9Sstevel@tonic-gate
343*7c478bd9Sstevel@tonic-gateecho ""
344*7c478bd9Sstevel@tonic-gate
345*7c478bd9Sstevel@tonic-gateecho "Installing the YP database will require that you answer a few questions."
346*7c478bd9Sstevel@tonic-gateecho "Questions will all be asked at the beginning of the procedure."
347*7c478bd9Sstevel@tonic-gateecho ""
348*7c478bd9Sstevel@tonic-gateecho "Do you want this procedure to quit on non-fatal errors? [y/n: n]  \c"
349*7c478bd9Sstevel@tonic-gateread doexit
350*7c478bd9Sstevel@tonic-gate
351*7c478bd9Sstevel@tonic-gatecase $doexit in
352*7c478bd9Sstevel@tonic-gatey*)	exit_on_error=T;;
353*7c478bd9Sstevel@tonic-gateY*)	exit_on_error=T;;
354*7c478bd9Sstevel@tonic-gate*)	echo "\
355*7c478bd9Sstevel@tonic-gateOK, please remember to go back and redo manually whatever fails.  If you"
356*7c478bd9Sstevel@tonic-gate	echo "\
357*7c478bd9Sstevel@tonic-gatedon't, some part of the system (perhaps the yp itself) won't work.";;
358*7c478bd9Sstevel@tonic-gateesac
359*7c478bd9Sstevel@tonic-gate
360*7c478bd9Sstevel@tonic-gateecho "The yp domain directory is $yproot_dir""/""$def_dom"
361*7c478bd9Sstevel@tonic-gate
362*7c478bd9Sstevel@tonic-gatefor dir in $yproot_dir/$def_dom
363*7c478bd9Sstevel@tonic-gatedo
364*7c478bd9Sstevel@tonic-gate
365*7c478bd9Sstevel@tonic-gate	if [ -d $dir ]; then
366*7c478bd9Sstevel@tonic-gate		echo  "Can we destroy the existing $dir and its contents? [y/n: n]  \c"
367*7c478bd9Sstevel@tonic-gate		read kill_old_dir
368*7c478bd9Sstevel@tonic-gate
369*7c478bd9Sstevel@tonic-gate		case $kill_old_dir in
370*7c478bd9Sstevel@tonic-gate		y*)	rm -r -f $dir
371*7c478bd9Sstevel@tonic-gate
372*7c478bd9Sstevel@tonic-gate			if [ $?  -ne 0 ]
373*7c478bd9Sstevel@tonic-gate			then
374*7c478bd9Sstevel@tonic-gate			echo "Can't clean up old directory $dir.  Fatal error."
375*7c478bd9Sstevel@tonic-gate				exit 1
376*7c478bd9Sstevel@tonic-gate			fi;;
377*7c478bd9Sstevel@tonic-gate
378*7c478bd9Sstevel@tonic-gate		Y*)	rm -r -f $dir
379*7c478bd9Sstevel@tonic-gate
380*7c478bd9Sstevel@tonic-gate			if [ $?  -ne 0 ]
381*7c478bd9Sstevel@tonic-gate			then
382*7c478bd9Sstevel@tonic-gate			echo "Can't clean up old directory $dir.  Fatal error."
383*7c478bd9Sstevel@tonic-gate				exit 1
384*7c478bd9Sstevel@tonic-gate			fi;;
385*7c478bd9Sstevel@tonic-gate
386*7c478bd9Sstevel@tonic-gate		*)    echo "OK, please clean it up by hand and start again.  Bye"
387*7c478bd9Sstevel@tonic-gate			exit 0;;
388*7c478bd9Sstevel@tonic-gate		esac
389*7c478bd9Sstevel@tonic-gate	fi
390*7c478bd9Sstevel@tonic-gate
391*7c478bd9Sstevel@tonic-gate	mkdir $dir
392*7c478bd9Sstevel@tonic-gate
393*7c478bd9Sstevel@tonic-gate	if [ $?  -ne 0 ]
394*7c478bd9Sstevel@tonic-gate	then
395*7c478bd9Sstevel@tonic-gate		echo "Can't make new directory $dir.  Fatal error."
396*7c478bd9Sstevel@tonic-gate		exit 1
397*7c478bd9Sstevel@tonic-gate	fi
398*7c478bd9Sstevel@tonic-gate
399*7c478bd9Sstevel@tonic-gatedone
400*7c478bd9Sstevel@tonic-gate
401*7c478bd9Sstevel@tonic-gateif [ $slavep = T ]
402*7c478bd9Sstevel@tonic-gatethen
403*7c478bd9Sstevel@tonic-gate	echo "\
404*7c478bd9Sstevel@tonic-gateThere will be no further questions. The remainder of the procedure should take"
405*7c478bd9Sstevel@tonic-gate	echo "a few minutes, to copy the data bases from $master."
406*7c478bd9Sstevel@tonic-gate
407*7c478bd9Sstevel@tonic-gate	for dom in  $real_def_dom
408*7c478bd9Sstevel@tonic-gate	do
409*7c478bd9Sstevel@tonic-gate		for map in $maps
410*7c478bd9Sstevel@tonic-gate		do
411*7c478bd9Sstevel@tonic-gate			echo "Transferring $map..."
412*7c478bd9Sstevel@tonic-gate			$XFR -h $master -c -d $dom $map
413*7c478bd9Sstevel@tonic-gate
414*7c478bd9Sstevel@tonic-gate			if [ $?  -ne 0 ]
415*7c478bd9Sstevel@tonic-gate			then
416*7c478bd9Sstevel@tonic-gate				errors_in_setup=T
417*7c478bd9Sstevel@tonic-gate
418*7c478bd9Sstevel@tonic-gate				if [ $exit_on_error = T ]
419*7c478bd9Sstevel@tonic-gate				then
420*7c478bd9Sstevel@tonic-gate					exit 1
421*7c478bd9Sstevel@tonic-gate				fi
422*7c478bd9Sstevel@tonic-gate			fi
423*7c478bd9Sstevel@tonic-gate		done
424*7c478bd9Sstevel@tonic-gate	done
425*7c478bd9Sstevel@tonic-gate
426*7c478bd9Sstevel@tonic-gate	echo ""
427*7c478bd9Sstevel@tonic-gate	echo  "${host}'s nis data base has been set up\n"
428*7c478bd9Sstevel@tonic-gate
429*7c478bd9Sstevel@tonic-gate	if [ $errors_in_setup = T ]
430*7c478bd9Sstevel@tonic-gate	then
431*7c478bd9Sstevel@tonic-gate		echo " with errors.  Please remember"
432*7c478bd9Sstevel@tonic-gate		echo "to figure out what went wrong, and fix it."
433*7c478bd9Sstevel@tonic-gate	else
434*7c478bd9Sstevel@tonic-gate		echo " without any errors."
435*7c478bd9Sstevel@tonic-gate	fi
436*7c478bd9Sstevel@tonic-gate
437*7c478bd9Sstevel@tonic-gate	# enable slave services
438*7c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/server:default
439*7c478bd9Sstevel@tonic-gate
440*7c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/client:default
441*7c478bd9Sstevel@tonic-gate
442*7c478bd9Sstevel@tonic-gate	exit 0
443*7c478bd9Sstevel@tonic-gateelse
444*7c478bd9Sstevel@tonic-gate
445*7c478bd9Sstevel@tonic-gate	rm -f $yproot_dir/*.time
446*7c478bd9Sstevel@tonic-gate
447*7c478bd9Sstevel@tonic-gate	echo "\
448*7c478bd9Sstevel@tonic-gateThere will be no further questions. The remainder of the procedure should take"
449*7c478bd9Sstevel@tonic-gate	echo "5 to 10 minutes."
450*7c478bd9Sstevel@tonic-gate
451*7c478bd9Sstevel@tonic-gate	echo "Building $yproot_dir/$def_dom/ypservers..."
452*7c478bd9Sstevel@tonic-gate	makedbm $hf $yproot_dir/$def_dom/$ypservers_map
453*7c478bd9Sstevel@tonic-gate
454*7c478bd9Sstevel@tonic-gate	if [ $?  -ne 0 ]
455*7c478bd9Sstevel@tonic-gate	then
456*7c478bd9Sstevel@tonic-gate		echo "\
457*7c478bd9Sstevel@tonic-gateCouldn't build yp data base $yproot_dir/$def_dom/$ypservers_map."
458*7c478bd9Sstevel@tonic-gate		errors_in_setup=T
459*7c478bd9Sstevel@tonic-gate
460*7c478bd9Sstevel@tonic-gate		if [ $exit_on_error = T ]
461*7c478bd9Sstevel@tonic-gate		then
462*7c478bd9Sstevel@tonic-gate			exit 1
463*7c478bd9Sstevel@tonic-gate		fi
464*7c478bd9Sstevel@tonic-gate	fi
465*7c478bd9Sstevel@tonic-gate
466*7c478bd9Sstevel@tonic-gate	rm $hf
467*7c478bd9Sstevel@tonic-gate
468*7c478bd9Sstevel@tonic-gate	in_pwd=`pwd`
469*7c478bd9Sstevel@tonic-gate	cd $yproot_dir
470*7c478bd9Sstevel@tonic-gate	echo  "Running \c"
471*7c478bd9Sstevel@tonic-gate	echo  $yproot_dir "\c"
472*7c478bd9Sstevel@tonic-gate	echo "/Makefile..."
473*7c478bd9Sstevel@tonic-gate	make NOPUSH=1
474*7c478bd9Sstevel@tonic-gate
475*7c478bd9Sstevel@tonic-gate	if [ $?  -ne 0 ]
476*7c478bd9Sstevel@tonic-gate	then
477*7c478bd9Sstevel@tonic-gate		echo "\
478*7c478bd9Sstevel@tonic-gateError running Makefile."
479*7c478bd9Sstevel@tonic-gate		errors_in_setup=T
480*7c478bd9Sstevel@tonic-gate
481*7c478bd9Sstevel@tonic-gate		if [ $exit_on_error = T ]
482*7c478bd9Sstevel@tonic-gate		then
483*7c478bd9Sstevel@tonic-gate			exit 1
484*7c478bd9Sstevel@tonic-gate		fi
485*7c478bd9Sstevel@tonic-gate	fi
486*7c478bd9Sstevel@tonic-gate
487*7c478bd9Sstevel@tonic-gate	cd $in_pwd
488*7c478bd9Sstevel@tonic-gate	echo ""
489*7c478bd9Sstevel@tonic-gate	echo  "\
490*7c478bd9Sstevel@tonic-gate$host has been set up as a yp master server\c"
491*7c478bd9Sstevel@tonic-gate
492*7c478bd9Sstevel@tonic-gate	if [ $errors_in_setup = T ]
493*7c478bd9Sstevel@tonic-gate	then
494*7c478bd9Sstevel@tonic-gate		echo " with errors.  Please remember"
495*7c478bd9Sstevel@tonic-gate		echo "to figure out what went wrong, and fix it."
496*7c478bd9Sstevel@tonic-gate	else
497*7c478bd9Sstevel@tonic-gate		echo " without any errors."
498*7c478bd9Sstevel@tonic-gate	fi
499*7c478bd9Sstevel@tonic-gate
500*7c478bd9Sstevel@tonic-gate	echo ""
501*7c478bd9Sstevel@tonic-gate	echo "\
502*7c478bd9Sstevel@tonic-gateIf there are running slave yp servers, run yppush now for any data bases"
503*7c478bd9Sstevel@tonic-gate	echo "\
504*7c478bd9Sstevel@tonic-gatewhich have been changed.  If there are no running slaves, run ypinit on"
505*7c478bd9Sstevel@tonic-gate	echo "\
506*7c478bd9Sstevel@tonic-gatethose hosts which are to be slave servers."
507*7c478bd9Sstevel@tonic-gate
508*7c478bd9Sstevel@tonic-gate	# enable master services
509*7c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/server:default
510*7c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/xfr:default
511*7c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/passwd:default
512*7c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/update:default
513*7c478bd9Sstevel@tonic-gate
514*7c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/client:default
515*7c478bd9Sstevel@tonic-gatefi
516