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 6*19c77476Spwernau# Common Development and Distribution License (the "License"). 7*19c77476Spwernau# 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# 227c478bd9Sstevel@tonic-gate# 23*19c77476Spwernau# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate# Use is subject to license terms. 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T 277c478bd9Sstevel@tonic-gate# All Rights Reserved 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate# Portions of this source code were derived from Berkeley 4.3 BSD 307c478bd9Sstevel@tonic-gate# under license from the Regents of the University of California. 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate#ident "%Z%%M% %I% %E% SMI" 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate# set -xv 357c478bd9Sstevel@tonic-gateYPXFR=/usr/lib/netsvc/yp/ypxfr 367c478bd9Sstevel@tonic-gateMAKEPATH=/usr/ccs/bin 377c478bd9Sstevel@tonic-gatemaps="publickey publickey.byname" 387c478bd9Sstevel@tonic-gateyproot_dir=/var/yp 397c478bd9Sstevel@tonic-gateyproot_exe=/usr/sbin/yp 407c478bd9Sstevel@tonic-gatehf=/var/run/ypservers.$$ 417c478bd9Sstevel@tonic-gateXFR=${YPXFR} 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gatehosts_file=/etc/hosts 447c478bd9Sstevel@tonic-gatehosts6_file=/etc/inet/ipnodes 457c478bd9Sstevel@tonic-gateclientp=F 467c478bd9Sstevel@tonic-gatemasterp=F 477c478bd9Sstevel@tonic-gateslavep=F 487c478bd9Sstevel@tonic-gatehost="" 497c478bd9Sstevel@tonic-gatedef_dom="" 507c478bd9Sstevel@tonic-gatemaster="" 517c478bd9Sstevel@tonic-gategot_host_list=F 527c478bd9Sstevel@tonic-gatefirst_time=T 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 69*19c77476Spwernauis_valid_ipaddr () { 70*19c77476Spwernau test -n "`echo $1 | awk 'NF != 1 {exit} \ 71*19c77476Spwernau $1 !~ /[0-9]/ || /[;-~]/ || /!--/ || /\// {exit} \ 72*19c77476Spwernau $1 !~ /\./ {exit} {print}'`" || \ 73*19c77476Spwernau test -n "`echo $1 | awk 'NF != 1 {exit} \ 74*19c77476Spwernau ($1 !~ /[0-9]/ && $1 !~ /[A-F]/ && \ 75*19c77476Spwernau $1 !~ /[a-f]/) || \ 76*19c77476Spwernau /[;-@]/ || /[G-\`]/ || /[g-~]/ || /!--/ || \ 77*19c77476Spwernau /\// {exit} \ 78*19c77476Spwernau $1 !~ /:/ {exit} {print}'`" 79*19c77476Spwernau} 80*19c77476Spwernau 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 877c478bd9Sstevel@tonic-gatecase $# in 887c478bd9Sstevel@tonic-gate1) case $1 in 897c478bd9Sstevel@tonic-gate -c) clientp=T;; 907c478bd9Sstevel@tonic-gate -m) masterp=T;; 917c478bd9Sstevel@tonic-gate *) echo 'usage:' 927c478bd9Sstevel@tonic-gate echo ' ypinit -c' 937c478bd9Sstevel@tonic-gate echo ' ypinit -m' 947c478bd9Sstevel@tonic-gate echo ' ypinit -s master_server' 957c478bd9Sstevel@tonic-gate echo "" 967c478bd9Sstevel@tonic-gate echo "\ 977c478bd9Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master " 987c478bd9Sstevel@tonic-gate echo "\ 997c478bd9Sstevel@tonic-gateyp server data base, and -s is used for a slave data base." 1007c478bd9Sstevel@tonic-gate echo "\ 1017c478bd9Sstevel@tonic-gatemaster_server must be an existing reachable yp server." 1027c478bd9Sstevel@tonic-gate exit 1;; 1037c478bd9Sstevel@tonic-gate esac;; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate2) case $1 in 1067c478bd9Sstevel@tonic-gate -s) slavep=T; master=$2; 1077c478bd9Sstevel@tonic-gate if ( grep $master $hosts_file $hosts6_file > /dev/null ) 1087c478bd9Sstevel@tonic-gate then 1097c478bd9Sstevel@tonic-gate echo "" 1107c478bd9Sstevel@tonic-gate else 1117c478bd9Sstevel@tonic-gate echo "server not found in $hosts_file or $hosts6_file" 1127c478bd9Sstevel@tonic-gate exit 1 1137c478bd9Sstevel@tonic-gate fi;; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate *) echo 'usage:' 1167c478bd9Sstevel@tonic-gate echo ' ypinit -c' 1177c478bd9Sstevel@tonic-gate echo ' ypinit -m' 1187c478bd9Sstevel@tonic-gate echo ' ypinit -s master_server' 1197c478bd9Sstevel@tonic-gate echo "" 1207c478bd9Sstevel@tonic-gate echo "\ 1217c478bd9Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master " 1227c478bd9Sstevel@tonic-gate echo "\ 1237c478bd9Sstevel@tonic-gateyp server data base, and -s is used for a slave data base." 1247c478bd9Sstevel@tonic-gate echo "\ 1257c478bd9Sstevel@tonic-gatemaster_server must be an existing reachable yp server." 1267c478bd9Sstevel@tonic-gate exit 1;; 1277c478bd9Sstevel@tonic-gate esac;; 1287c478bd9Sstevel@tonic-gate3) case $1 in 1297c478bd9Sstevel@tonic-gate -c) clientp=T;; 1307c478bd9Sstevel@tonic-gate *) echo 'usage:' 1317c478bd9Sstevel@tonic-gate echo ' ypinit -c' 1327c478bd9Sstevel@tonic-gate echo ' ypinit -m' 1337c478bd9Sstevel@tonic-gate echo ' ypinit -s master_server' 1347c478bd9Sstevel@tonic-gate echo "" 1357c478bd9Sstevel@tonic-gate echo "\ 1367c478bd9Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master " 1377c478bd9Sstevel@tonic-gate echo "\ 1387c478bd9Sstevel@tonic-gateyp server data base, and -s is used for a slave data base." 1397c478bd9Sstevel@tonic-gate echo "\ 1407c478bd9Sstevel@tonic-gatemaster_server must be an existing reachable yp server." 1417c478bd9Sstevel@tonic-gate exit 1;; 1427c478bd9Sstevel@tonic-gate esac;; 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate*) echo 'usage:' 1457c478bd9Sstevel@tonic-gate echo ' ypinit -c' 1467c478bd9Sstevel@tonic-gate echo ' ypinit -m' 1477c478bd9Sstevel@tonic-gate echo ' ypinit -s master_server' 1487c478bd9Sstevel@tonic-gate echo "" 1497c478bd9Sstevel@tonic-gate echo "\ 1507c478bd9Sstevel@tonic-gatewhere -c is used to set up a yp client, -m is used to build a master " 1517c478bd9Sstevel@tonic-gate echo "\ 1527c478bd9Sstevel@tonic-gateyp server data base, and -s is used for a slave data base." 1537c478bd9Sstevel@tonic-gate echo "\ 1547c478bd9Sstevel@tonic-gatemaster_server must be an existing reachable yp server." 1557c478bd9Sstevel@tonic-gate exit 1;; 1567c478bd9Sstevel@tonic-gateesac 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gateif [ $? -ne 0 ] 1597c478bd9Sstevel@tonic-gatethen 1607c478bd9Sstevel@tonic-gate echo "\ 1617c478bd9Sstevel@tonic-gateYou have to be the superuser to run this. Please log in as root." 1627c478bd9Sstevel@tonic-gate exit 1 1637c478bd9Sstevel@tonic-gatefi 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gatehost=`uname -n` 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gateif [ $? -ne 0 ] 1687c478bd9Sstevel@tonic-gatethen 1697c478bd9Sstevel@tonic-gate echo "Can't get local host's name. Please check your path." 1707c478bd9Sstevel@tonic-gate exit 1 1717c478bd9Sstevel@tonic-gatefi 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gateif [ -z "$host" ] 1747c478bd9Sstevel@tonic-gatethen 1757c478bd9Sstevel@tonic-gate echo "The local host's name hasn't been set. Please set it." 1767c478bd9Sstevel@tonic-gate exit 1 1777c478bd9Sstevel@tonic-gatefi 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gatedef_dom=`domainname` 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gateif [ $? -ne 0 ] 1827c478bd9Sstevel@tonic-gatethen 1837c478bd9Sstevel@tonic-gate echo "Can't get local host's domain name. Please check your path." 1847c478bd9Sstevel@tonic-gate exit 1 1857c478bd9Sstevel@tonic-gatefi 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gateif [ -z "$def_dom" ] 1887c478bd9Sstevel@tonic-gatethen 1897c478bd9Sstevel@tonic-gate echo "The local host's domain name hasn't been set. Please set it." 1907c478bd9Sstevel@tonic-gate exit 1 1917c478bd9Sstevel@tonic-gatefi 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gatedomainname $def_dom 1947c478bd9Sstevel@tonic-gatereal_def_dom=$def_dom 1957c478bd9Sstevel@tonic-gate#def_dom=`ypalias -d $def_dom` 1967c478bd9Sstevel@tonic-gateypservers_map=`ypalias ypservers` 1977c478bd9Sstevel@tonic-gatedomain_dir="$yproot_dir""/""$def_dom" 1987c478bd9Sstevel@tonic-gatebinding_dir="$yproot_dir""/binding/""$def_dom" 1997c478bd9Sstevel@tonic-gatebinding_file="$yproot_dir""/binding/""$def_dom""/ypservers" 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gateif [ ! -d $yproot_dir -o -f $yproot_dir ] 2027c478bd9Sstevel@tonic-gatethen 2037c478bd9Sstevel@tonic-gate echo "\ 2047c478bd9Sstevel@tonic-gateThe directory $yproot_dir doesn't exist. Restore it from the distribution." 2057c478bd9Sstevel@tonic-gate exit 1 2067c478bd9Sstevel@tonic-gatefi 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate# add domainname and ypservers aliases to aliases file 2097c478bd9Sstevel@tonic-gateecho ypservers $ypservers_map >> $yproot_dir/aliases 2107c478bd9Sstevel@tonic-gateecho $real_def_dom $def_dom >> $yproot_dir/aliases 2117c478bd9Sstevel@tonic-gatesort $yproot_dir/aliases | uniq > /var/run/.ypaliases; mv /var/run/.ypaliases $yproot_dir/aliases 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gateif [ ! -d "$yproot_dir"/binding ] 2147c478bd9Sstevel@tonic-gatethen 2157c478bd9Sstevel@tonic-gate mkdir "$yproot_dir"/binding 2167c478bd9Sstevel@tonic-gatefi 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gateif [ ! -d $binding_dir ] 2197c478bd9Sstevel@tonic-gatethen 2207c478bd9Sstevel@tonic-gate mkdir "$binding_dir" 2217c478bd9Sstevel@tonic-gatefi 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gateif [ $slavep = F ] 2247c478bd9Sstevel@tonic-gatethen 2257c478bd9Sstevel@tonic-gate while [ $got_host_list = F ]; do 2267c478bd9Sstevel@tonic-gate touch $hf # make sure file exists 2277c478bd9Sstevel@tonic-gate echo "" 2287c478bd9Sstevel@tonic-gate echo "\ 2297c478bd9Sstevel@tonic-gateIn order for NIS to operate sucessfully, we have to construct a list of the " 2307c478bd9Sstevel@tonic-gate echo "\ 2317c478bd9Sstevel@tonic-gateNIS servers. Please continue to add the names for YP servers in order of" 2327c478bd9Sstevel@tonic-gate echo "\ 2337c478bd9Sstevel@tonic-gatepreference, one per line. When you are done with the list, type a <control D>" 2347c478bd9Sstevel@tonic-gate echo "\ 2357c478bd9Sstevel@tonic-gateor a return on a line by itself." 2367c478bd9Sstevel@tonic-gate if [ $masterp = T ] 2377c478bd9Sstevel@tonic-gate then 2387c478bd9Sstevel@tonic-gate echo $host > $hf 2397c478bd9Sstevel@tonic-gate echo "\tnext host to add: $host" 2407c478bd9Sstevel@tonic-gate elif [ -f $binding_file ] 2417c478bd9Sstevel@tonic-gate then 2427c478bd9Sstevel@tonic-gate if [ $first_time = T ] 2437c478bd9Sstevel@tonic-gate then 2447c478bd9Sstevel@tonic-gate for h in `cat $binding_file` 2457c478bd9Sstevel@tonic-gate do 2467c478bd9Sstevel@tonic-gate echo $h >> $hf 2477c478bd9Sstevel@tonic-gate echo "\tnext host to add: $h" 2487c478bd9Sstevel@tonic-gate done 2497c478bd9Sstevel@tonic-gate fi 2507c478bd9Sstevel@tonic-gate fi 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate echo "\tnext host to add: \c" 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate while read h ; test -n "$h" 2557c478bd9Sstevel@tonic-gate do 256*19c77476Spwernau # 257*19c77476Spwernau # Host should be in the v4 or v6 hosts file or 258*19c77476Spwernau # reasonably resemble an IP address. We'll do a 259*19c77476Spwernau # sanity check that a v4 addr is one word consisting 260*19c77476Spwernau # of only numbers and the "." character, 261*19c77476Spwernau # which should guard against fully qualified 262*19c77476Spwernau # hostnames and most malformed entries. IPv6 263*19c77476Spwernau # addresses can be numbers, hex letters, and have 264*19c77476Spwernau # at least one ":" character and possibly one or 265*19c77476Spwernau # more "." characters for embedded v4 addresses 266*19c77476Spwernau # 267*19c77476Spwernau if ( grep $h $hosts_file $hosts6_file > /dev/null ) || \ 268*19c77476Spwernau ( test $clientp = T && `is_valid_ipaddr $h` ) 2697c478bd9Sstevel@tonic-gate then 2707c478bd9Sstevel@tonic-gate echo $h >> $hf 2717c478bd9Sstevel@tonic-gate echo "\tnext host to add: \c" 2727c478bd9Sstevel@tonic-gate else 273*19c77476Spwernau echo "host $h not found in $hosts_file or" \ 274*19c77476Spwernau "$hosts6_file.\nNot added to the list." 2757c478bd9Sstevel@tonic-gate echo "" 2767c478bd9Sstevel@tonic-gate echo "Do you wish to abort [y/n: y] \c" 2777c478bd9Sstevel@tonic-gate read cont_ok 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate case $cont_ok in 2807c478bd9Sstevel@tonic-gate n*) echo "\tnext host to add: \c";; 2817c478bd9Sstevel@tonic-gate N*) echo "\tnext host to add: \c";; 2827c478bd9Sstevel@tonic-gate *) exit 1;; 2837c478bd9Sstevel@tonic-gate esac 2847c478bd9Sstevel@tonic-gate fi 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate done 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate echo "" 2897c478bd9Sstevel@tonic-gate if [ -s $hf ] 2907c478bd9Sstevel@tonic-gate then 2917c478bd9Sstevel@tonic-gate echo "The current list of yp servers looks like this:" 2927c478bd9Sstevel@tonic-gate echo "" 2937c478bd9Sstevel@tonic-gate cat $hf 2947c478bd9Sstevel@tonic-gate echo "" 2957c478bd9Sstevel@tonic-gate echo "Is this correct? [y/n: y] \c" 2967c478bd9Sstevel@tonic-gate else 2977c478bd9Sstevel@tonic-gate echo "You have not added any server information." 2987c478bd9Sstevel@tonic-gate echo "" 2997c478bd9Sstevel@tonic-gate echo "Do you still wish to exit? [y/n: y] \c" 3007c478bd9Sstevel@tonic-gate fi 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate read hlist_ok 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate case $hlist_ok in 3057c478bd9Sstevel@tonic-gate n*) got_host_list=F 3067c478bd9Sstevel@tonic-gate first_time=F 3077c478bd9Sstevel@tonic-gate rm $hf 3087c478bd9Sstevel@tonic-gate echo "Let's try the whole thing again...";; 3097c478bd9Sstevel@tonic-gate N*) got_host_list=F 3107c478bd9Sstevel@tonic-gate first_time=F 3117c478bd9Sstevel@tonic-gate rm $hf 3127c478bd9Sstevel@tonic-gate echo "Let's try the whole thing again...";; 3137c478bd9Sstevel@tonic-gate *) got_host_list=T;; 3147c478bd9Sstevel@tonic-gate esac 3157c478bd9Sstevel@tonic-gate done 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate if [ -s $hf ] 3187c478bd9Sstevel@tonic-gate then 3197c478bd9Sstevel@tonic-gate cp $hf $binding_file 3207c478bd9Sstevel@tonic-gate fi 3217c478bd9Sstevel@tonic-gatefi 3227c478bd9Sstevel@tonic-gate 3237c478bd9Sstevel@tonic-gate# 3247c478bd9Sstevel@tonic-gate# Start client service on next boot, unless we're establishing a slave 3257c478bd9Sstevel@tonic-gate# server, in which case the binding is needed now (or should be 3267c478bd9Sstevel@tonic-gate# preserved). 3277c478bd9Sstevel@tonic-gate# 3287c478bd9Sstevel@tonic-gateif [ $slavep = T ] 3297c478bd9Sstevel@tonic-gatethen 3307c478bd9Sstevel@tonic-gate enable_this_boot network/nis/client:default 3317c478bd9Sstevel@tonic-gateelse 3327c478bd9Sstevel@tonic-gate enable_next_boot network/nis/client:default 3337c478bd9Sstevel@tonic-gatefi 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate# 3367c478bd9Sstevel@tonic-gate# As a client, our configuration is correct once a binding file is 3377c478bd9Sstevel@tonic-gate# established, and so we can exit (making sure we're no longer a server, 3387c478bd9Sstevel@tonic-gate# of course). 3397c478bd9Sstevel@tonic-gate# 3407c478bd9Sstevel@tonic-gateif [ $clientp = T ] 3417c478bd9Sstevel@tonic-gatethen 3427c478bd9Sstevel@tonic-gate rm $hf 3437c478bd9Sstevel@tonic-gate /usr/sbin/svcadm disable network/nis/server:default 3447c478bd9Sstevel@tonic-gate /usr/sbin/svcadm disable network/nis/xfr:default 3457c478bd9Sstevel@tonic-gate /usr/sbin/svcadm disable network/nis/passwd:default 3467c478bd9Sstevel@tonic-gate /usr/sbin/svcadm disable network/nis/update:default 3477c478bd9Sstevel@tonic-gate exit 0 3487c478bd9Sstevel@tonic-gatefi 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gateif [ $slavep = T ] 3517c478bd9Sstevel@tonic-gatethen 3527c478bd9Sstevel@tonic-gate if [ $host = $master ] 3537c478bd9Sstevel@tonic-gate then 3547c478bd9Sstevel@tonic-gate echo "\ 3557c478bd9Sstevel@tonic-gateThe host specified should be a running master yp server, not this machine." 3567c478bd9Sstevel@tonic-gate exit 1 3577c478bd9Sstevel@tonic-gate fi 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate maps=`ypwhich -m | egrep $master$| awk '{ printf("%s ",$1) }' -` 3607c478bd9Sstevel@tonic-gate if [ -z "$maps" ] 3617c478bd9Sstevel@tonic-gate then 3627c478bd9Sstevel@tonic-gate echo "Can't enumerate maps from $master. Please check that it is running." 3637c478bd9Sstevel@tonic-gate exit 1 3647c478bd9Sstevel@tonic-gate fi 3657c478bd9Sstevel@tonic-gatefi 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gateecho "" 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gateecho "Installing the YP database will require that you answer a few questions." 3707c478bd9Sstevel@tonic-gateecho "Questions will all be asked at the beginning of the procedure." 3717c478bd9Sstevel@tonic-gateecho "" 3727c478bd9Sstevel@tonic-gateecho "Do you want this procedure to quit on non-fatal errors? [y/n: n] \c" 3737c478bd9Sstevel@tonic-gateread doexit 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gatecase $doexit in 3767c478bd9Sstevel@tonic-gatey*) exit_on_error=T;; 3777c478bd9Sstevel@tonic-gateY*) exit_on_error=T;; 3787c478bd9Sstevel@tonic-gate*) echo "\ 3797c478bd9Sstevel@tonic-gateOK, please remember to go back and redo manually whatever fails. If you" 3807c478bd9Sstevel@tonic-gate echo "\ 3817c478bd9Sstevel@tonic-gatedon't, some part of the system (perhaps the yp itself) won't work.";; 3827c478bd9Sstevel@tonic-gateesac 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gateecho "The yp domain directory is $yproot_dir""/""$def_dom" 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gatefor dir in $yproot_dir/$def_dom 3877c478bd9Sstevel@tonic-gatedo 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate if [ -d $dir ]; then 3907c478bd9Sstevel@tonic-gate echo "Can we destroy the existing $dir and its contents? [y/n: n] \c" 3917c478bd9Sstevel@tonic-gate read kill_old_dir 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate case $kill_old_dir in 3947c478bd9Sstevel@tonic-gate y*) rm -r -f $dir 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate if [ $? -ne 0 ] 3977c478bd9Sstevel@tonic-gate then 3987c478bd9Sstevel@tonic-gate echo "Can't clean up old directory $dir. Fatal error." 3997c478bd9Sstevel@tonic-gate exit 1 4007c478bd9Sstevel@tonic-gate fi;; 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate Y*) rm -r -f $dir 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate if [ $? -ne 0 ] 4057c478bd9Sstevel@tonic-gate then 4067c478bd9Sstevel@tonic-gate echo "Can't clean up old directory $dir. Fatal error." 4077c478bd9Sstevel@tonic-gate exit 1 4087c478bd9Sstevel@tonic-gate fi;; 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate *) echo "OK, please clean it up by hand and start again. Bye" 4117c478bd9Sstevel@tonic-gate exit 0;; 4127c478bd9Sstevel@tonic-gate esac 4137c478bd9Sstevel@tonic-gate fi 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate mkdir $dir 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate if [ $? -ne 0 ] 4187c478bd9Sstevel@tonic-gate then 4197c478bd9Sstevel@tonic-gate echo "Can't make new directory $dir. Fatal error." 4207c478bd9Sstevel@tonic-gate exit 1 4217c478bd9Sstevel@tonic-gate fi 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gatedone 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gateif [ $slavep = T ] 4267c478bd9Sstevel@tonic-gatethen 4277c478bd9Sstevel@tonic-gate echo "\ 4287c478bd9Sstevel@tonic-gateThere will be no further questions. The remainder of the procedure should take" 4297c478bd9Sstevel@tonic-gate echo "a few minutes, to copy the data bases from $master." 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate for dom in $real_def_dom 4327c478bd9Sstevel@tonic-gate do 4337c478bd9Sstevel@tonic-gate for map in $maps 4347c478bd9Sstevel@tonic-gate do 4357c478bd9Sstevel@tonic-gate echo "Transferring $map..." 4367c478bd9Sstevel@tonic-gate $XFR -h $master -c -d $dom $map 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate if [ $? -ne 0 ] 4397c478bd9Sstevel@tonic-gate then 4407c478bd9Sstevel@tonic-gate errors_in_setup=T 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate if [ $exit_on_error = T ] 4437c478bd9Sstevel@tonic-gate then 4447c478bd9Sstevel@tonic-gate exit 1 4457c478bd9Sstevel@tonic-gate fi 4467c478bd9Sstevel@tonic-gate fi 4477c478bd9Sstevel@tonic-gate done 4487c478bd9Sstevel@tonic-gate done 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate echo "" 4517c478bd9Sstevel@tonic-gate echo "${host}'s nis data base has been set up\n" 4527c478bd9Sstevel@tonic-gate 4537c478bd9Sstevel@tonic-gate if [ $errors_in_setup = T ] 4547c478bd9Sstevel@tonic-gate then 4557c478bd9Sstevel@tonic-gate echo " with errors. Please remember" 4567c478bd9Sstevel@tonic-gate echo "to figure out what went wrong, and fix it." 4577c478bd9Sstevel@tonic-gate else 4587c478bd9Sstevel@tonic-gate echo " without any errors." 4597c478bd9Sstevel@tonic-gate fi 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate # enable slave services 4627c478bd9Sstevel@tonic-gate enable_this_boot network/nis/server:default 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate enable_this_boot network/nis/client:default 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate exit 0 4677c478bd9Sstevel@tonic-gateelse 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate rm -f $yproot_dir/*.time 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate echo "\ 4727c478bd9Sstevel@tonic-gateThere will be no further questions. The remainder of the procedure should take" 4737c478bd9Sstevel@tonic-gate echo "5 to 10 minutes." 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate echo "Building $yproot_dir/$def_dom/ypservers..." 4767c478bd9Sstevel@tonic-gate makedbm $hf $yproot_dir/$def_dom/$ypservers_map 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate if [ $? -ne 0 ] 4797c478bd9Sstevel@tonic-gate then 4807c478bd9Sstevel@tonic-gate echo "\ 4817c478bd9Sstevel@tonic-gateCouldn't build yp data base $yproot_dir/$def_dom/$ypservers_map." 4827c478bd9Sstevel@tonic-gate errors_in_setup=T 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate if [ $exit_on_error = T ] 4857c478bd9Sstevel@tonic-gate then 4867c478bd9Sstevel@tonic-gate exit 1 4877c478bd9Sstevel@tonic-gate fi 4887c478bd9Sstevel@tonic-gate fi 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate rm $hf 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate in_pwd=`pwd` 4937c478bd9Sstevel@tonic-gate cd $yproot_dir 4947c478bd9Sstevel@tonic-gate echo "Running \c" 4957c478bd9Sstevel@tonic-gate echo $yproot_dir "\c" 4967c478bd9Sstevel@tonic-gate echo "/Makefile..." 4977c478bd9Sstevel@tonic-gate make NOPUSH=1 4987c478bd9Sstevel@tonic-gate 4997c478bd9Sstevel@tonic-gate if [ $? -ne 0 ] 5007c478bd9Sstevel@tonic-gate then 5017c478bd9Sstevel@tonic-gate echo "\ 5027c478bd9Sstevel@tonic-gateError running Makefile." 5037c478bd9Sstevel@tonic-gate errors_in_setup=T 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate if [ $exit_on_error = T ] 5067c478bd9Sstevel@tonic-gate then 5077c478bd9Sstevel@tonic-gate exit 1 5087c478bd9Sstevel@tonic-gate fi 5097c478bd9Sstevel@tonic-gate fi 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate cd $in_pwd 5127c478bd9Sstevel@tonic-gate echo "" 5137c478bd9Sstevel@tonic-gate echo "\ 5147c478bd9Sstevel@tonic-gate$host has been set up as a yp master server\c" 5157c478bd9Sstevel@tonic-gate 5167c478bd9Sstevel@tonic-gate if [ $errors_in_setup = T ] 5177c478bd9Sstevel@tonic-gate then 5187c478bd9Sstevel@tonic-gate echo " with errors. Please remember" 5197c478bd9Sstevel@tonic-gate echo "to figure out what went wrong, and fix it." 5207c478bd9Sstevel@tonic-gate else 5217c478bd9Sstevel@tonic-gate echo " without any errors." 5227c478bd9Sstevel@tonic-gate fi 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate echo "" 5257c478bd9Sstevel@tonic-gate echo "\ 5267c478bd9Sstevel@tonic-gateIf there are running slave yp servers, run yppush now for any data bases" 5277c478bd9Sstevel@tonic-gate echo "\ 5287c478bd9Sstevel@tonic-gatewhich have been changed. If there are no running slaves, run ypinit on" 5297c478bd9Sstevel@tonic-gate echo "\ 5307c478bd9Sstevel@tonic-gatethose hosts which are to be slave servers." 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate # enable master services 5337c478bd9Sstevel@tonic-gate enable_this_boot network/nis/server:default 5347c478bd9Sstevel@tonic-gate enable_this_boot network/nis/xfr:default 5357c478bd9Sstevel@tonic-gate enable_this_boot network/nis/passwd:default 5367c478bd9Sstevel@tonic-gate enable_this_boot network/nis/update:default 5377c478bd9Sstevel@tonic-gate 5387c478bd9Sstevel@tonic-gate enable_this_boot network/nis/client:default 5397c478bd9Sstevel@tonic-gatefi 540