xref: /illumos-gate/usr/src/cmd/ypcmd/ypinit.sh (revision 9c307210)
17c478bd9Sstevel@tonic-gate#!/sbin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
619c77476Spwernau# Common Development and Distribution License (the "License").
719c77476Spwernau# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
22*9c307210SEugene Khudyakoff# Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate#
2419c77476Spwernau# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate# Use is subject to license terms.
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
287c478bd9Sstevel@tonic-gate#	  All Rights Reserved
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate# Portions of this source code were derived from Berkeley 4.3 BSD
317c478bd9Sstevel@tonic-gate# under license from the Regents of the University of California.
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate# set -xv
347c478bd9Sstevel@tonic-gateYPXFR=/usr/lib/netsvc/yp/ypxfr
357c478bd9Sstevel@tonic-gateMAKEPATH=/usr/ccs/bin
367c478bd9Sstevel@tonic-gatemaps="publickey publickey.byname"
377c478bd9Sstevel@tonic-gateyproot_dir=/var/yp
387c478bd9Sstevel@tonic-gateyproot_exe=/usr/sbin/yp
397c478bd9Sstevel@tonic-gatehf=/var/run/ypservers.$$
407c478bd9Sstevel@tonic-gateXFR=${YPXFR}
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gatehosts_file=/etc/hosts
437c478bd9Sstevel@tonic-gatehosts6_file=/etc/inet/ipnodes
447c478bd9Sstevel@tonic-gateclientp=F
457c478bd9Sstevel@tonic-gatemasterp=F
467c478bd9Sstevel@tonic-gateslavep=F
477c478bd9Sstevel@tonic-gatehost=""
487c478bd9Sstevel@tonic-gatedef_dom=""
497c478bd9Sstevel@tonic-gatemaster=""
507c478bd9Sstevel@tonic-gategot_host_list=F
517c478bd9Sstevel@tonic-gatefirst_time=T
52*9c307210SEugene Khudyakoffnon_interactive=F
537c478bd9Sstevel@tonic-gateexit_on_error=F
547c478bd9Sstevel@tonic-gateerrors_in_setup=F
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gateenable_next_boot () {
577c478bd9Sstevel@tonic-gate	/usr/sbin/svcadm disable -t $1
587c478bd9Sstevel@tonic-gate	[ $? = 0 ] || echo "ypinit: unable to temporarily disable $1"
597c478bd9Sstevel@tonic-gate	/usr/sbin/svccfg -s $1 \
607c478bd9Sstevel@tonic-gate	    setprop general/enabled = true
617c478bd9Sstevel@tonic-gate	[ $? = 0 ] || echo "ypinit: unable to enable $1 for next boot"
627c478bd9Sstevel@tonic-gate}
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gateenable_this_boot () {
657c478bd9Sstevel@tonic-gate	/usr/sbin/svcadm enable $1
667c478bd9Sstevel@tonic-gate	[ $? = 0 ] || echo "ypinit: unable to enable $1"
677c478bd9Sstevel@tonic-gate}
687c478bd9Sstevel@tonic-gate
6919c77476Spwernauis_valid_ipaddr () {
7019c77476Spwernau	test -n "`echo $1 | awk 'NF != 1 {exit} \
7119c77476Spwernau	    $1 !~ /[0-9]/ || /[;-~]/ || /!--/ || /\// {exit} \
7219c77476Spwernau	    $1 !~ /\./ {exit} {print}'`" || \
7319c77476Spwernau	test -n "`echo $1 | awk 'NF != 1 {exit} \
7419c77476Spwernau	    ($1 !~ /[0-9]/ && $1 !~ /[A-F]/ && \
7519c77476Spwernau	    $1 !~ /[a-f]/) || \
7619c77476Spwernau	    /[;-@]/ || /[G-\`]/ || /[g-~]/ || /!--/ || \
7719c77476Spwernau	    /\// {exit} \
7819c77476Spwernau	    $1 !~ /:/ {exit} {print}'`"
7919c77476Spwernau}
8019c77476Spwernau
817c478bd9Sstevel@tonic-gatePATH=/bin:/usr/bin:/usr/etc:/usr/sbin:$yproot_exe:$MAKEPATH:$PATH
827c478bd9Sstevel@tonic-gateexport PATH
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate# To do cleanup
857c478bd9Sstevel@tonic-gatetrap '/usr/bin/rm -f $hf' 0 1 2 3 15
867c478bd9Sstevel@tonic-gate
87*9c307210SEugene Khudyakoff# Check out total number of arguments
887c478bd9Sstevel@tonic-gatecase $# in
897c478bd9Sstevel@tonic-gate1)	case $1 in
907c478bd9Sstevel@tonic-gate	-c)	clientp=T;;
917c478bd9Sstevel@tonic-gate	-m)	masterp=T;;
927c478bd9Sstevel@tonic-gate	*)	echo 'usage:'
93*9c307210SEugene Khudyakoff		echo '	ypinit -c [server_name...]'
947c478bd9Sstevel@tonic-gate		echo '	ypinit -m'
957c478bd9Sstevel@tonic-gate		echo '	ypinit -s master_server'
967c478bd9Sstevel@tonic-gate		echo ""
977c478bd9Sstevel@tonic-gate		echo "\
987c478bd9Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master "
997c478bd9Sstevel@tonic-gate                echo "\
1007c478bd9Sstevel@tonic-gateyp server data base, and -s is used for a slave data base."
1017c478bd9Sstevel@tonic-gate		echo "\
1027c478bd9Sstevel@tonic-gatemaster_server must be an existing reachable yp server."
1037c478bd9Sstevel@tonic-gate		exit 1;;
1047c478bd9Sstevel@tonic-gate	esac;;
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate2)	case $1 in
1077c478bd9Sstevel@tonic-gate	-s)	slavep=T; master=$2;
1087c478bd9Sstevel@tonic-gate		if ( grep $master $hosts_file $hosts6_file > /dev/null )
1097c478bd9Sstevel@tonic-gate		then
1107c478bd9Sstevel@tonic-gate			echo ""
1117c478bd9Sstevel@tonic-gate		else
1127c478bd9Sstevel@tonic-gate			echo "server not found in $hosts_file or $hosts6_file"
1137c478bd9Sstevel@tonic-gate			exit 1
1147c478bd9Sstevel@tonic-gate		fi;;
1157c478bd9Sstevel@tonic-gate
116*9c307210SEugene Khudyakoff	# the case with more than one argument with the '-c' option
117*9c307210SEugene Khudyakoff	# is a subject to enter non-interactive mode
118*9c307210SEugene Khudyakoff	-c)	clientp=T; non_interactive=T;
119*9c307210SEugene Khudyakoff		;;
1207c478bd9Sstevel@tonic-gate	*)	echo 'usage:'
121*9c307210SEugene Khudyakoff		echo '	ypinit -c [server_name...]'
1227c478bd9Sstevel@tonic-gate		echo '	ypinit -m'
1237c478bd9Sstevel@tonic-gate		echo '	ypinit -s master_server'
1247c478bd9Sstevel@tonic-gate		echo ""
1257c478bd9Sstevel@tonic-gate		echo "\
1267c478bd9Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master "
1277c478bd9Sstevel@tonic-gate                echo "\
1287c478bd9Sstevel@tonic-gateyp server data base, and -s is used for a slave data base."
1297c478bd9Sstevel@tonic-gate		echo "\
1307c478bd9Sstevel@tonic-gatemaster_server must be an existing reachable yp server."
1317c478bd9Sstevel@tonic-gate		exit 1;;
1327c478bd9Sstevel@tonic-gate	esac;;
133*9c307210SEugene Khudyakoff*)	case $1 in
1347c478bd9Sstevel@tonic-gate
135*9c307210SEugene Khudyakoff	# the case with more than one argument with the '-c' option
136*9c307210SEugene Khudyakoff	# is a subject to enter non-interactive mode
137*9c307210SEugene Khudyakoff	-c)	clientp=T; non_interactive=T;
138*9c307210SEugene Khudyakoff		;;
1397c478bd9Sstevel@tonic-gate	*)	echo 'usage:'
140*9c307210SEugene Khudyakoff		echo '	ypinit -c [server_name...]'
1417c478bd9Sstevel@tonic-gate		echo '	ypinit -m'
1427c478bd9Sstevel@tonic-gate		echo '	ypinit -s master_server'
1437c478bd9Sstevel@tonic-gate		echo ""
1447c478bd9Sstevel@tonic-gate		echo "\
1457c478bd9Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master "
1467c478bd9Sstevel@tonic-gate                echo "\
1477c478bd9Sstevel@tonic-gateyp server data base, and -s is used for a slave data base."
1487c478bd9Sstevel@tonic-gate		echo "\
1497c478bd9Sstevel@tonic-gatemaster_server must be an existing reachable yp server."
1507c478bd9Sstevel@tonic-gate		exit 1;;
151*9c307210SEugene Khudyakoff	esac;;
1527c478bd9Sstevel@tonic-gateesac
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gateif [ $? -ne 0 ]
1557c478bd9Sstevel@tonic-gatethen
1567c478bd9Sstevel@tonic-gate	echo "\
1577c478bd9Sstevel@tonic-gateYou have to be the superuser to run this.  Please log in as root."
1587c478bd9Sstevel@tonic-gate	exit 1
1597c478bd9Sstevel@tonic-gatefi
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gatehost=`uname -n`
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gateif [ $? -ne 0 ]
1647c478bd9Sstevel@tonic-gatethen
1657c478bd9Sstevel@tonic-gate	echo "Can't get local host's name.  Please check your path."
1667c478bd9Sstevel@tonic-gate	exit 1
1677c478bd9Sstevel@tonic-gatefi
1687c478bd9Sstevel@tonic-gate
1697c478bd9Sstevel@tonic-gateif [ -z "$host" ]
1707c478bd9Sstevel@tonic-gatethen
1717c478bd9Sstevel@tonic-gate	echo "The local host's name hasn't been set.  Please set it."
1727c478bd9Sstevel@tonic-gate	exit 1
1737c478bd9Sstevel@tonic-gatefi
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gatedef_dom=`domainname`
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gateif [ $? -ne 0 ]
1787c478bd9Sstevel@tonic-gatethen
1797c478bd9Sstevel@tonic-gate	echo "Can't get local host's domain name.  Please check your path."
1807c478bd9Sstevel@tonic-gate	exit 1
1817c478bd9Sstevel@tonic-gatefi
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gateif [ -z "$def_dom" ]
1847c478bd9Sstevel@tonic-gatethen
1857c478bd9Sstevel@tonic-gate	echo "The local host's domain name hasn't been set.  Please set it."
1867c478bd9Sstevel@tonic-gate	exit 1
1877c478bd9Sstevel@tonic-gatefi
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gatedomainname $def_dom
1907c478bd9Sstevel@tonic-gatereal_def_dom=$def_dom
1917c478bd9Sstevel@tonic-gate#def_dom=`ypalias -d $def_dom`
1927c478bd9Sstevel@tonic-gateypservers_map=`ypalias ypservers`
1937c478bd9Sstevel@tonic-gatedomain_dir="$yproot_dir""/""$def_dom"
1947c478bd9Sstevel@tonic-gatebinding_dir="$yproot_dir""/binding/""$def_dom"
1957c478bd9Sstevel@tonic-gatebinding_file="$yproot_dir""/binding/""$def_dom""/ypservers"
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gateif [ ! -d $yproot_dir -o -f $yproot_dir ]
1987c478bd9Sstevel@tonic-gatethen
1997c478bd9Sstevel@tonic-gate    echo "\
2007c478bd9Sstevel@tonic-gateThe directory $yproot_dir doesn't exist.  Restore it from the distribution."
2017c478bd9Sstevel@tonic-gate	exit 1
2027c478bd9Sstevel@tonic-gatefi
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate# add domainname and ypservers aliases to aliases file
2057c478bd9Sstevel@tonic-gateecho ypservers $ypservers_map >> $yproot_dir/aliases
2067c478bd9Sstevel@tonic-gateecho $real_def_dom $def_dom >> $yproot_dir/aliases
2077c478bd9Sstevel@tonic-gatesort $yproot_dir/aliases | uniq > /var/run/.ypaliases; mv /var/run/.ypaliases $yproot_dir/aliases
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gateif [ ! -d "$yproot_dir"/binding ]
2107c478bd9Sstevel@tonic-gatethen
2117c478bd9Sstevel@tonic-gate	mkdir "$yproot_dir"/binding
2127c478bd9Sstevel@tonic-gatefi
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gateif [ ! -d  $binding_dir ]
2157c478bd9Sstevel@tonic-gatethen
2167c478bd9Sstevel@tonic-gate	mkdir  "$binding_dir"
2177c478bd9Sstevel@tonic-gatefi
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gateif [ $slavep = F ]
2207c478bd9Sstevel@tonic-gatethen
221*9c307210SEugene Khudyakoff	if [ $non_interactive = F ]
222*9c307210SEugene Khudyakoff	then
2237c478bd9Sstevel@tonic-gate		while [ $got_host_list = F ]; do
2247c478bd9Sstevel@tonic-gate			touch $hf    # make sure file exists
2257c478bd9Sstevel@tonic-gate			echo ""
2267c478bd9Sstevel@tonic-gate			echo "\
2277c478bd9Sstevel@tonic-gateIn order for NIS to operate sucessfully, we have to construct a list of the "
2287c478bd9Sstevel@tonic-gate			echo "\
2297c478bd9Sstevel@tonic-gateNIS servers.  Please continue to add the names for YP servers in order of"
2307c478bd9Sstevel@tonic-gate			echo "\
2317c478bd9Sstevel@tonic-gatepreference, one per line.  When you are done with the list, type a <control D>"
2327c478bd9Sstevel@tonic-gate			echo "\
2337c478bd9Sstevel@tonic-gateor a return on a line by itself."
2347c478bd9Sstevel@tonic-gate			if [ $masterp = T ]
2357c478bd9Sstevel@tonic-gate			then
2367c478bd9Sstevel@tonic-gate				echo $host > $hf
2377c478bd9Sstevel@tonic-gate				echo "\tnext host to add:  $host"
2387c478bd9Sstevel@tonic-gate			elif [ -f $binding_file ]
2397c478bd9Sstevel@tonic-gate			then
2407c478bd9Sstevel@tonic-gate				if [ $first_time = T ]
2417c478bd9Sstevel@tonic-gate				then
2427c478bd9Sstevel@tonic-gate					for h in `cat $binding_file`
2437c478bd9Sstevel@tonic-gate					do
2447c478bd9Sstevel@tonic-gate						echo $h >> $hf
2457c478bd9Sstevel@tonic-gate						echo "\tnext host to add:  $h"
2467c478bd9Sstevel@tonic-gate					done
2477c478bd9Sstevel@tonic-gate				fi
2487c478bd9Sstevel@tonic-gate			fi
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate			echo  "\tnext host to add:  \c"
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate			while read h ; test -n "$h"
2537c478bd9Sstevel@tonic-gate			do
25419c77476Spwernau				#
25519c77476Spwernau				# Host should be in the v4 or v6 hosts file or
25619c77476Spwernau				# reasonably resemble an IP address.  We'll do a
25719c77476Spwernau				# sanity check that a v4 addr is one word consisting
25819c77476Spwernau				# of only numbers and the "." character,
25919c77476Spwernau				# which should guard against fully qualified
26019c77476Spwernau				# hostnames and most malformed entries.  IPv6
26119c77476Spwernau				# addresses can be numbers, hex letters, and have
26219c77476Spwernau				# at least one ":" character and possibly one or
26319c77476Spwernau				# more "." characters for embedded v4 addresses
26419c77476Spwernau				#
26519c77476Spwernau				if ( grep $h $hosts_file $hosts6_file > /dev/null ) || \
26619c77476Spwernau				    ( test $clientp = T && `is_valid_ipaddr $h` )
2677c478bd9Sstevel@tonic-gate				then
2687c478bd9Sstevel@tonic-gate					echo $h >> $hf
2697c478bd9Sstevel@tonic-gate					echo  "\tnext host to add:  \c"
2707c478bd9Sstevel@tonic-gate				else
27119c77476Spwernau					echo "host $h not found in $hosts_file or" \
27219c77476Spwernau					    "$hosts6_file.\nNot added to the list."
2737c478bd9Sstevel@tonic-gate					echo ""
2747c478bd9Sstevel@tonic-gate					echo  "Do you wish to abort [y/n: y]  \c"
2757c478bd9Sstevel@tonic-gate					read cont_ok
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate					case $cont_ok in
2787c478bd9Sstevel@tonic-gate					n*)	echo "\tnext host to add:  \c";;
2797c478bd9Sstevel@tonic-gate					N*)	echo "\tnext host to add:  \c";;
2807c478bd9Sstevel@tonic-gate					*)	exit 1;;
2817c478bd9Sstevel@tonic-gate					esac
2827c478bd9Sstevel@tonic-gate				fi
2837c478bd9Sstevel@tonic-gate			done
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate			echo ""
2867c478bd9Sstevel@tonic-gate			if [ -s $hf ]
2877c478bd9Sstevel@tonic-gate			then
2887c478bd9Sstevel@tonic-gate				echo "The current list of yp servers looks like this:"
2897c478bd9Sstevel@tonic-gate				echo ""
2907c478bd9Sstevel@tonic-gate				cat $hf
2917c478bd9Sstevel@tonic-gate				echo ""
2927c478bd9Sstevel@tonic-gate				echo "Is this correct?  [y/n: y]  \c"
2937c478bd9Sstevel@tonic-gate			else
2947c478bd9Sstevel@tonic-gate				echo "You have not added any server information."
2957c478bd9Sstevel@tonic-gate				echo ""
2967c478bd9Sstevel@tonic-gate				echo "Do you still wish to exit? [y/n: y]  \c"
2977c478bd9Sstevel@tonic-gate			fi
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate			read hlist_ok
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate			case $hlist_ok in
3027c478bd9Sstevel@tonic-gate			n*)	got_host_list=F
3037c478bd9Sstevel@tonic-gate				first_time=F
3047c478bd9Sstevel@tonic-gate				rm $hf
3057c478bd9Sstevel@tonic-gate				echo "Let's try the whole thing again...";;
3067c478bd9Sstevel@tonic-gate			N*)	got_host_list=F
3077c478bd9Sstevel@tonic-gate				first_time=F
3087c478bd9Sstevel@tonic-gate				rm $hf
3097c478bd9Sstevel@tonic-gate				echo "Let's try the whole thing again...";;
3107c478bd9Sstevel@tonic-gate			*)	got_host_list=T;;
3117c478bd9Sstevel@tonic-gate			esac
3127c478bd9Sstevel@tonic-gate		done
313*9c307210SEugene Khudyakoff	else
314*9c307210SEugene Khudyakoff		shift
315*9c307210SEugene Khudyakoff		> $hf
316*9c307210SEugene Khudyakoff		while [[ $# > 0 ]]; do
317*9c307210SEugene Khudyakoff			if ( grep $1 $hosts_file $hosts6_file > /dev/null ) || \
318*9c307210SEugene Khudyakoff			    ( `is_valid_ipaddr $1` )
319*9c307210SEugene Khudyakoff			then
320*9c307210SEugene Khudyakoff				echo $1 >> $hf
321*9c307210SEugene Khudyakoff			else
322*9c307210SEugene Khudyakoff				echo "host $1 not found in $hosts_file or" \
323*9c307210SEugene Khudyakoff				    "$hosts6_file.\nNot added to the list."
324*9c307210SEugene Khudyakoff				echo ""
325*9c307210SEugene Khudyakoff			fi
326*9c307210SEugene Khudyakoff			shift
327*9c307210SEugene Khudyakoff		done
328*9c307210SEugene Khudyakoff	fi
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate	if [ -s $hf ]
3317c478bd9Sstevel@tonic-gate	then
3327c478bd9Sstevel@tonic-gate		cp  $hf $binding_file
3337c478bd9Sstevel@tonic-gate	fi
3347c478bd9Sstevel@tonic-gatefi
3357c478bd9Sstevel@tonic-gate
3367c478bd9Sstevel@tonic-gate#
3377c478bd9Sstevel@tonic-gate# Start client service on next boot, unless we're establishing a slave
3387c478bd9Sstevel@tonic-gate# server, in which case the binding is needed now (or should be
3397c478bd9Sstevel@tonic-gate# preserved).
3407c478bd9Sstevel@tonic-gate#
3417c478bd9Sstevel@tonic-gateif [ $slavep = T ]
3427c478bd9Sstevel@tonic-gatethen
3437c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/client:default
3447c478bd9Sstevel@tonic-gateelse
3457c478bd9Sstevel@tonic-gate	enable_next_boot network/nis/client:default
3467c478bd9Sstevel@tonic-gatefi
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate#
3497c478bd9Sstevel@tonic-gate# As a client, our configuration is correct once a binding file is
3507c478bd9Sstevel@tonic-gate# established, and so we can exit (making sure we're no longer a server,
3517c478bd9Sstevel@tonic-gate# of course).
3527c478bd9Sstevel@tonic-gate#
3537c478bd9Sstevel@tonic-gateif [ $clientp = T ]
3547c478bd9Sstevel@tonic-gatethen
3557c478bd9Sstevel@tonic-gate	rm $hf
3567c478bd9Sstevel@tonic-gate	/usr/sbin/svcadm disable network/nis/server:default
3577c478bd9Sstevel@tonic-gate	/usr/sbin/svcadm disable network/nis/xfr:default
3587c478bd9Sstevel@tonic-gate	/usr/sbin/svcadm disable network/nis/passwd:default
3597c478bd9Sstevel@tonic-gate	/usr/sbin/svcadm disable network/nis/update:default
3607c478bd9Sstevel@tonic-gate	exit 0
3617c478bd9Sstevel@tonic-gatefi
3627c478bd9Sstevel@tonic-gate
3637c478bd9Sstevel@tonic-gateif [ $slavep = T ]
3647c478bd9Sstevel@tonic-gatethen
3657c478bd9Sstevel@tonic-gate	if [ $host = $master ]
3667c478bd9Sstevel@tonic-gate	then
3677c478bd9Sstevel@tonic-gate		echo "\
3687c478bd9Sstevel@tonic-gateThe host specified should be a running master yp server, not this machine."
3697c478bd9Sstevel@tonic-gate		exit 1
3707c478bd9Sstevel@tonic-gate	fi
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate	maps=`ypwhich -m | egrep $master$| awk '{ printf("%s ",$1) }' -`
3737c478bd9Sstevel@tonic-gate	if [ -z "$maps" ]
3747c478bd9Sstevel@tonic-gate	then
3757c478bd9Sstevel@tonic-gate		echo "Can't enumerate maps from $master. Please check that it is running."
3767c478bd9Sstevel@tonic-gate		exit 1
3777c478bd9Sstevel@tonic-gate	fi
3787c478bd9Sstevel@tonic-gatefi
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gateecho ""
3817c478bd9Sstevel@tonic-gate
3827c478bd9Sstevel@tonic-gateecho "Installing the YP database will require that you answer a few questions."
3837c478bd9Sstevel@tonic-gateecho "Questions will all be asked at the beginning of the procedure."
3847c478bd9Sstevel@tonic-gateecho ""
3857c478bd9Sstevel@tonic-gateecho "Do you want this procedure to quit on non-fatal errors? [y/n: n]  \c"
3867c478bd9Sstevel@tonic-gateread doexit
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gatecase $doexit in
3897c478bd9Sstevel@tonic-gatey*)	exit_on_error=T;;
3907c478bd9Sstevel@tonic-gateY*)	exit_on_error=T;;
3917c478bd9Sstevel@tonic-gate*)	echo "\
3927c478bd9Sstevel@tonic-gateOK, please remember to go back and redo manually whatever fails.  If you"
3937c478bd9Sstevel@tonic-gate	echo "\
3947c478bd9Sstevel@tonic-gatedon't, some part of the system (perhaps the yp itself) won't work.";;
3957c478bd9Sstevel@tonic-gateesac
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gateecho "The yp domain directory is $yproot_dir""/""$def_dom"
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gatefor dir in $yproot_dir/$def_dom
4007c478bd9Sstevel@tonic-gatedo
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate	if [ -d $dir ]; then
4037c478bd9Sstevel@tonic-gate		echo  "Can we destroy the existing $dir and its contents? [y/n: n]  \c"
4047c478bd9Sstevel@tonic-gate		read kill_old_dir
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate		case $kill_old_dir in
4077c478bd9Sstevel@tonic-gate		y*)	rm -r -f $dir
4087c478bd9Sstevel@tonic-gate
4097c478bd9Sstevel@tonic-gate			if [ $?  -ne 0 ]
4107c478bd9Sstevel@tonic-gate			then
4117c478bd9Sstevel@tonic-gate			echo "Can't clean up old directory $dir.  Fatal error."
4127c478bd9Sstevel@tonic-gate				exit 1
4137c478bd9Sstevel@tonic-gate			fi;;
4147c478bd9Sstevel@tonic-gate
4157c478bd9Sstevel@tonic-gate		Y*)	rm -r -f $dir
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate			if [ $?  -ne 0 ]
4187c478bd9Sstevel@tonic-gate			then
4197c478bd9Sstevel@tonic-gate			echo "Can't clean up old directory $dir.  Fatal error."
4207c478bd9Sstevel@tonic-gate				exit 1
4217c478bd9Sstevel@tonic-gate			fi;;
4227c478bd9Sstevel@tonic-gate
4237c478bd9Sstevel@tonic-gate		*)    echo "OK, please clean it up by hand and start again.  Bye"
4247c478bd9Sstevel@tonic-gate			exit 0;;
4257c478bd9Sstevel@tonic-gate		esac
4267c478bd9Sstevel@tonic-gate	fi
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate	mkdir $dir
4297c478bd9Sstevel@tonic-gate
4307c478bd9Sstevel@tonic-gate	if [ $?  -ne 0 ]
4317c478bd9Sstevel@tonic-gate	then
4327c478bd9Sstevel@tonic-gate		echo "Can't make new directory $dir.  Fatal error."
4337c478bd9Sstevel@tonic-gate		exit 1
4347c478bd9Sstevel@tonic-gate	fi
4357c478bd9Sstevel@tonic-gate
4367c478bd9Sstevel@tonic-gatedone
4377c478bd9Sstevel@tonic-gate
4387c478bd9Sstevel@tonic-gateif [ $slavep = T ]
4397c478bd9Sstevel@tonic-gatethen
4407c478bd9Sstevel@tonic-gate	echo "\
4417c478bd9Sstevel@tonic-gateThere will be no further questions. The remainder of the procedure should take"
4427c478bd9Sstevel@tonic-gate	echo "a few minutes, to copy the data bases from $master."
4437c478bd9Sstevel@tonic-gate
4447c478bd9Sstevel@tonic-gate	for dom in  $real_def_dom
4457c478bd9Sstevel@tonic-gate	do
4467c478bd9Sstevel@tonic-gate		for map in $maps
4477c478bd9Sstevel@tonic-gate		do
4487c478bd9Sstevel@tonic-gate			echo "Transferring $map..."
4497c478bd9Sstevel@tonic-gate			$XFR -h $master -c -d $dom $map
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate			if [ $?  -ne 0 ]
4527c478bd9Sstevel@tonic-gate			then
4537c478bd9Sstevel@tonic-gate				errors_in_setup=T
4547c478bd9Sstevel@tonic-gate
4557c478bd9Sstevel@tonic-gate				if [ $exit_on_error = T ]
4567c478bd9Sstevel@tonic-gate				then
4577c478bd9Sstevel@tonic-gate					exit 1
4587c478bd9Sstevel@tonic-gate				fi
4597c478bd9Sstevel@tonic-gate			fi
4607c478bd9Sstevel@tonic-gate		done
4617c478bd9Sstevel@tonic-gate	done
4627c478bd9Sstevel@tonic-gate
4637c478bd9Sstevel@tonic-gate	echo ""
4647c478bd9Sstevel@tonic-gate	echo  "${host}'s nis data base has been set up\n"
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate	if [ $errors_in_setup = T ]
4677c478bd9Sstevel@tonic-gate	then
4687c478bd9Sstevel@tonic-gate		echo " with errors.  Please remember"
4697c478bd9Sstevel@tonic-gate		echo "to figure out what went wrong, and fix it."
4707c478bd9Sstevel@tonic-gate	else
4717c478bd9Sstevel@tonic-gate		echo " without any errors."
4727c478bd9Sstevel@tonic-gate	fi
4737c478bd9Sstevel@tonic-gate
4747c478bd9Sstevel@tonic-gate	# enable slave services
4757c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/server:default
4767c478bd9Sstevel@tonic-gate
4777c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/client:default
4787c478bd9Sstevel@tonic-gate
4797c478bd9Sstevel@tonic-gate	exit 0
4807c478bd9Sstevel@tonic-gateelse
4817c478bd9Sstevel@tonic-gate
4827c478bd9Sstevel@tonic-gate	rm -f $yproot_dir/*.time
4837c478bd9Sstevel@tonic-gate
4847c478bd9Sstevel@tonic-gate	echo "\
4857c478bd9Sstevel@tonic-gateThere will be no further questions. The remainder of the procedure should take"
4867c478bd9Sstevel@tonic-gate	echo "5 to 10 minutes."
4877c478bd9Sstevel@tonic-gate
4887c478bd9Sstevel@tonic-gate	echo "Building $yproot_dir/$def_dom/ypservers..."
4897c478bd9Sstevel@tonic-gate	makedbm $hf $yproot_dir/$def_dom/$ypservers_map
4907c478bd9Sstevel@tonic-gate
4917c478bd9Sstevel@tonic-gate	if [ $?  -ne 0 ]
4927c478bd9Sstevel@tonic-gate	then
4937c478bd9Sstevel@tonic-gate		echo "\
4947c478bd9Sstevel@tonic-gateCouldn't build yp data base $yproot_dir/$def_dom/$ypservers_map."
4957c478bd9Sstevel@tonic-gate		errors_in_setup=T
4967c478bd9Sstevel@tonic-gate
4977c478bd9Sstevel@tonic-gate		if [ $exit_on_error = T ]
4987c478bd9Sstevel@tonic-gate		then
4997c478bd9Sstevel@tonic-gate			exit 1
5007c478bd9Sstevel@tonic-gate		fi
5017c478bd9Sstevel@tonic-gate	fi
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate	rm $hf
5047c478bd9Sstevel@tonic-gate
5057c478bd9Sstevel@tonic-gate	in_pwd=`pwd`
5067c478bd9Sstevel@tonic-gate	cd $yproot_dir
5077c478bd9Sstevel@tonic-gate	echo  "Running \c"
5087c478bd9Sstevel@tonic-gate	echo  $yproot_dir "\c"
5097c478bd9Sstevel@tonic-gate	echo "/Makefile..."
5107c478bd9Sstevel@tonic-gate	make NOPUSH=1
5117c478bd9Sstevel@tonic-gate
5127c478bd9Sstevel@tonic-gate	if [ $?  -ne 0 ]
5137c478bd9Sstevel@tonic-gate	then
5147c478bd9Sstevel@tonic-gate		echo "\
5157c478bd9Sstevel@tonic-gateError running Makefile."
5167c478bd9Sstevel@tonic-gate		errors_in_setup=T
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gate		if [ $exit_on_error = T ]
5197c478bd9Sstevel@tonic-gate		then
5207c478bd9Sstevel@tonic-gate			exit 1
5217c478bd9Sstevel@tonic-gate		fi
5227c478bd9Sstevel@tonic-gate	fi
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate	cd $in_pwd
5257c478bd9Sstevel@tonic-gate	echo ""
5267c478bd9Sstevel@tonic-gate	echo  "\
5277c478bd9Sstevel@tonic-gate$host has been set up as a yp master server\c"
5287c478bd9Sstevel@tonic-gate
5297c478bd9Sstevel@tonic-gate	if [ $errors_in_setup = T ]
5307c478bd9Sstevel@tonic-gate	then
5317c478bd9Sstevel@tonic-gate		echo " with errors.  Please remember"
5327c478bd9Sstevel@tonic-gate		echo "to figure out what went wrong, and fix it."
5337c478bd9Sstevel@tonic-gate	else
5347c478bd9Sstevel@tonic-gate		echo " without any errors."
5357c478bd9Sstevel@tonic-gate	fi
5367c478bd9Sstevel@tonic-gate
5377c478bd9Sstevel@tonic-gate	echo ""
5387c478bd9Sstevel@tonic-gate	echo "\
5397c478bd9Sstevel@tonic-gateIf there are running slave yp servers, run yppush now for any data bases"
5407c478bd9Sstevel@tonic-gate	echo "\
5417c478bd9Sstevel@tonic-gatewhich have been changed.  If there are no running slaves, run ypinit on"
5427c478bd9Sstevel@tonic-gate	echo "\
5437c478bd9Sstevel@tonic-gatethose hosts which are to be slave servers."
5447c478bd9Sstevel@tonic-gate
5457c478bd9Sstevel@tonic-gate	# enable master services
5467c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/server:default
5477c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/xfr:default
5487c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/passwd:default
5497c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/update:default
5507c478bd9Sstevel@tonic-gate
5517c478bd9Sstevel@tonic-gate	enable_this_boot network/nis/client:default
5527c478bd9Sstevel@tonic-gatefi
553