Add a ypinit script and man page (script lifted from OpenBSD and haqued
to work on FreeBSD, man page written by me.) Also change Makefile.yp a little to be more tolerane in the face of missing source files. Print a message if we can't find /var/yp/master.passwd telling the user what to do to fix things.
This commit is contained in:
parent
898263b85d
commit
7f52bb826f
@ -1,10 +1,10 @@
|
||||
# $Id$
|
||||
# $Id: Makefile,v 1.3 1997/11/10 21:22:17 wpaul Exp $
|
||||
|
||||
PROG= ypserv
|
||||
SRCS= yp_svc.c yp_server.c yp_dblookup.c yp_dnslookup.c \
|
||||
ypxfr_clnt.c yp_main.c yp_error.c yp_access.c yp_svc_udp.c
|
||||
|
||||
MAN8= ypserv.8
|
||||
MAN8= ypserv.8 ypinit.8
|
||||
|
||||
CFLAGS+= -I. -DDB_CACHE
|
||||
|
||||
@ -32,6 +32,8 @@ afterinstall:
|
||||
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 \
|
||||
${.CURDIR}/Makefile.yp \
|
||||
${DESTDIR}/var/yp/Makefile.dist
|
||||
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 555 \
|
||||
${.CURDIR}/ypinit.sh ${BINDIR}/ypinit
|
||||
@if [ ! -f ${DESTDIR}/var/yp/Makefile.dist ]; then \
|
||||
ln -s ${DESTDIR}/var/yp/Makefile.dist \
|
||||
${DESTDIR}/var/yp/Makefile; fi
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# Makefile for the NIS databases
|
||||
#
|
||||
# $Id$
|
||||
# $Id: Makefile.yp,v 1.2 1997/11/10 19:47:14 wpaul Exp $
|
||||
#
|
||||
# This Makefile should only be run on the NIS master server of a domain.
|
||||
# All updated maps will be pushed to all NIS slave servers listed in the
|
||||
@ -70,7 +70,11 @@ TMP = `$(RCAT) $(NFILE)`
|
||||
# support multiple domains, something like /src/dir/$DOMAIN
|
||||
# would work well.
|
||||
YPSRCDIR = /etc
|
||||
.if !defined(YP_DIR)
|
||||
YPDIR = /var/yp
|
||||
.else
|
||||
YPDIR = $(YP_DIR)
|
||||
.endif
|
||||
YPMAPDIR = $(YPDIR)/$(DOMAIN)
|
||||
|
||||
# These are the files from which the NIS databases are built. You may edit
|
||||
@ -115,22 +119,61 @@ PUBLICKEY = $(YPSRCDIR)/publickey
|
||||
NETID = $(YPSRCDIR)/netid
|
||||
AMDHOST = $(YPSRCDIR)/amd.host
|
||||
|
||||
# List of maps that are always built.
|
||||
# If you want to omit some of them, feel free to comment
|
||||
# them out from this list.
|
||||
TARGETS= servers hosts networks protocols rpc services group
|
||||
#TARGETS+= aliases
|
||||
|
||||
# Sanity checks: filter out targets we can't build
|
||||
# Note that we don't build the ethers or boorparams maps by default
|
||||
# since /etc/ethers and /etc/bootparams are not likely to be present
|
||||
# on all systems.
|
||||
.if exists($(ETHERS))
|
||||
TARGETS+= ethers
|
||||
.else
|
||||
ETHERS= /dev/null
|
||||
.endif
|
||||
|
||||
.if exists($(BOOTPARAMS))
|
||||
TARGETS+= bootparams
|
||||
.else
|
||||
BOOTPARAMS= /dev/null
|
||||
.endif
|
||||
|
||||
.if exists($(NETGROUP))
|
||||
TARGETS+= netgrp
|
||||
.else
|
||||
NETGROUP= /dev/null
|
||||
.endif
|
||||
|
||||
.if exists($(MASTER))
|
||||
TARGETS+= passwd master.passwd netid
|
||||
.else
|
||||
MASTER= /dev/null
|
||||
TARGETS+= nopass
|
||||
.endif
|
||||
|
||||
.if exists($(PUBLICKEY))
|
||||
TARGETS+= publickey
|
||||
.else
|
||||
PUBLICKEY= /dev/null
|
||||
.endif
|
||||
|
||||
.if exists($(AMDHOST))
|
||||
TARGETS+= amd.host
|
||||
.else
|
||||
AMDHOST= /dev/null
|
||||
.endif
|
||||
|
||||
target:
|
||||
@$(RM) $(NFILE)
|
||||
@if [ ! -d $(DOMAIN) ]; then mkdir $(DOMAIN); fi; \
|
||||
cd $(DOMAIN) ; echo "NIS Map update started on `date` for domain $(DOMAIN)" ; \
|
||||
make -f ../Makefile all; echo "NIS Map update completed."
|
||||
@$(RM) $(NFILE)
|
||||
|
||||
# If you don't want some of these maps built, feel free to comment
|
||||
# them out from this list.
|
||||
# Note that we don't build the ethers or boorparams maps by default
|
||||
# since /etc/ethers and /etc/bootparams are not likely to be present
|
||||
# on all systems.
|
||||
#
|
||||
|
||||
all: servers master.passwd passwd hosts group networks protocols rpc \
|
||||
services netid
|
||||
# aliases publickey netgrp ethers bootparam amd.host
|
||||
all: $(TARGETS)
|
||||
|
||||
ethers: ethers.byname ethers.byaddr
|
||||
bootparam: bootparams
|
||||
@ -163,6 +206,22 @@ pushpw:
|
||||
@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) passwd.byname ; fi
|
||||
@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) passwd.byuid ; fi
|
||||
|
||||
pushmap:
|
||||
@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $(PUSHMAP) ; fi
|
||||
|
||||
nopass:
|
||||
@echo ""
|
||||
@echo " ********WARNING********"
|
||||
@echo " Couldn't find the master.passwd source file. This file"
|
||||
@echo " is needed to generate the master.passwd and passwd maps."
|
||||
@echo " The default location is /var/yp/master.passwd. You should"
|
||||
@echo " edit /var/yp/Makefile and set the MASTER variable to point"
|
||||
@echo " to the source file you wish to use for building the passwd"
|
||||
@echo " maps, or else invoke make(1) in the following manner:"
|
||||
@echo "
|
||||
@echo " make MASTER_PASSWD=/path/to/master.passwd"
|
||||
@echo ""
|
||||
|
||||
mail.aliases: $(ALIASES)
|
||||
@echo "Updating $@..."
|
||||
@echo $@.$$$$ > $(NFILE)
|
||||
@ -189,6 +248,9 @@ ypservers: $(YPSERVERS)
|
||||
|
||||
ethers.byname: $(ETHERS)
|
||||
@echo "Updating $@..."
|
||||
.if ${ETHERS} == "/dev/null"
|
||||
@echo "Ethers source file not found -- skipping"
|
||||
.else
|
||||
@echo $@.$$$$ > $(NFILE)
|
||||
$(CAT) $(ETHERS) | \
|
||||
$(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \
|
||||
@ -198,10 +260,13 @@ ethers.byname: $(ETHERS)
|
||||
@$(DBLOAD) -c
|
||||
@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
|
||||
@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
|
||||
|
||||
.endif
|
||||
|
||||
ethers.byaddr: $(ETHERS)
|
||||
@echo "Updating $@..."
|
||||
.if ${ETHERS} == "/dev/null"
|
||||
@echo "Ethers source file not found -- skipping"
|
||||
.else
|
||||
@echo $@.$$$$ > $(NFILE)
|
||||
$(CAT) $(ETHERS) | \
|
||||
$(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \
|
||||
@ -211,10 +276,14 @@ ethers.byaddr: $(ETHERS)
|
||||
@$(DBLOAD) -c
|
||||
@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
|
||||
@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
|
||||
.endif
|
||||
|
||||
|
||||
bootparams: $(BOOTPARAMS)
|
||||
@echo "Updating $@..."
|
||||
.if ${BOOTPARAMS} == "/dev/null"
|
||||
@echo "Bootparams source file not found -- skipping"
|
||||
.else
|
||||
@echo $@.$$$$ > $(NFILE)
|
||||
$(CAT) $(BOOTPARAMS) | \
|
||||
$(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \
|
||||
@ -224,10 +293,14 @@ bootparams: $(BOOTPARAMS)
|
||||
@$(DBLOAD) -c
|
||||
@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
|
||||
@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
|
||||
.endif
|
||||
|
||||
|
||||
netgroup: $(NETGROUP) netgroup.byhost netgroup.byuser
|
||||
@echo "Updating $@..."
|
||||
.if ${NETGROUP} == "/dev/null"
|
||||
@echo "Netgroup source file not found -- skipping"
|
||||
.else
|
||||
@echo $@.$$$$ > $(NFILE)
|
||||
$(CAT) $(NETGROUP) | \
|
||||
$(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \
|
||||
@ -238,10 +311,14 @@ netgroup: $(NETGROUP) netgroup.byhost netgroup.byuser
|
||||
@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
|
||||
@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
|
||||
@$(MAKE) -f ../Makefile netid
|
||||
.endif
|
||||
|
||||
|
||||
netgroup.byhost: $(NETGROUP)
|
||||
@echo "Updating $@..."
|
||||
.if ${NETGROUP} == "/dev/null"
|
||||
@echo "Netgroup source file not found -- skipping"
|
||||
.else
|
||||
@echo $@.$$$$ > $(NFILE)
|
||||
$(CAT) $(NETGROUP) | $(REVNETGROUP) -h -f $(NETGROUP) | \
|
||||
$(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \
|
||||
@ -251,10 +328,14 @@ netgroup.byhost: $(NETGROUP)
|
||||
@$(DBLOAD) -c
|
||||
@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
|
||||
@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
|
||||
.endif
|
||||
|
||||
|
||||
netgroup.byuser: $(NETGROUP)
|
||||
@echo "Updating $@..."
|
||||
.if ${NETGROUP} == "/dev/null"
|
||||
@echo "Netgroup source file not found -- skipping"
|
||||
.else
|
||||
@echo $@.$$$$ > $(NFILE)
|
||||
$(CAT) $(NETGROUP) | $(REVNETGROUP) -u -f $(NETGROUP) | \
|
||||
$(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \
|
||||
@ -264,6 +345,7 @@ netgroup.byuser: $(NETGROUP)
|
||||
@$(DBLOAD) -c
|
||||
@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
|
||||
@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
|
||||
.endif
|
||||
|
||||
|
||||
hosts.byname: $(HOSTS)
|
||||
@ -394,6 +476,9 @@ services.byname: $(SERVICES)
|
||||
|
||||
publickey.byname: $(PUBLICKEY)
|
||||
@echo "Updating $@..."
|
||||
.if ${PUBLICKEY} == "/dev/null"
|
||||
@echo "Publickey source file not found -- skipping"
|
||||
.else
|
||||
@echo $@.$$$$ > $(NFILE)
|
||||
$(CAT) $(PUBLICKEY) | \
|
||||
$(AWK) '$$1 !~ "#" { print $$1"\t"$$2 }' $^ \
|
||||
@ -402,6 +487,7 @@ publickey.byname: $(PUBLICKEY)
|
||||
@$(DBLOAD) -c
|
||||
@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
|
||||
@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
|
||||
.endif
|
||||
|
||||
|
||||
$(PASSWD): $(MASTER)
|
||||
@ -480,6 +566,9 @@ netid.byname: $(GROUP) $(PASSWD)
|
||||
|
||||
master.passwd.byname: $(MASTER)
|
||||
@echo "Updating $@..."
|
||||
.if ${MASTER} == "/dev/null"
|
||||
@echo "Master.passwd source file not found -- skipping"
|
||||
.else
|
||||
@echo $@.$$$$ > $(NFILE)
|
||||
$(CAT) $(MASTER) | \
|
||||
$(AWK) -F: '{ if ($$1 != "+") print $$1"\t"$$0 }' $^ \
|
||||
@ -488,10 +577,14 @@ master.passwd.byname: $(MASTER)
|
||||
@$(DBLOAD) -c
|
||||
@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
|
||||
@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
|
||||
.endif
|
||||
|
||||
|
||||
master.passwd.byuid: $(MASTER)
|
||||
@echo "Updating $@..."
|
||||
.if ${MASTER} == "/dev/null"
|
||||
@echo "Master.passwd source file not found -- skipping"
|
||||
.else
|
||||
@echo $@.$$$$ > $(NFILE)
|
||||
$(CAT) $(MASTER) | \
|
||||
$(AWK) -F: '{ if ($$1 != "+") print $$3"\t"$$0 }' $^ \
|
||||
@ -500,6 +593,8 @@ master.passwd.byuid: $(MASTER)
|
||||
@$(DBLOAD) -c
|
||||
@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
|
||||
@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
|
||||
.endif
|
||||
|
||||
|
||||
amd.host: $(AMDHOST)
|
||||
@echo "Updating $@..."
|
||||
|
172
usr.sbin/ypserv/ypinit.8
Normal file
172
usr.sbin/ypserv/ypinit.8
Normal file
@ -0,0 +1,172 @@
|
||||
.\" Copyright (c) 1997
|
||||
.\" Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by Bill Paul.
|
||||
.\" 4. Neither the name of the author nor the names of any co-contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
|
||||
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
.\" THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $Id: ypinit.8,v 1.1 1997/11/10 20:59:09 wpaul Exp $
|
||||
.\"
|
||||
.Dd November 10, 1997
|
||||
.Dt YPINIT 1
|
||||
.Os FreeBSD 3.0
|
||||
.Sh NAME
|
||||
.Nm ypinit
|
||||
.Nd build and install NIS databases
|
||||
.Sh SYNOPSIS
|
||||
.Nm ypinit
|
||||
.Fl m
|
||||
.Op Ar domainname
|
||||
.Nm ypinit
|
||||
.Fl s
|
||||
.Ar master_server
|
||||
.Op Ar domainname
|
||||
.Nm ypinit
|
||||
.Fl u
|
||||
.Op Ar domainname
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
script sets up databases on a Network Information Service (NIS)
|
||||
master or slave server.
|
||||
.Pp
|
||||
On a master server,
|
||||
.Nm
|
||||
creates the
|
||||
.Pa /var/yp/$DOMAINNAME
|
||||
directory, the
|
||||
.Pa /var/yp/ypservers
|
||||
file, and calls
|
||||
.Pa /var/yp/Makefile
|
||||
to create and populate an initial set of NIS maps. The maps are
|
||||
created from local source files using the
|
||||
.Xr yp_mkdb 8
|
||||
command. The script will prompt the user for a list of servers
|
||||
that support the specified domain; this list is used to populate
|
||||
the ypservers map.
|
||||
.Pp
|
||||
On a slave server,
|
||||
.Nm
|
||||
creates the
|
||||
.Pa /var/yp/$DOMAINNAME
|
||||
populates it with copies of the NIS maps from the master. The maps
|
||||
are obtained from the master using the
|
||||
.Xr ypxfr 8
|
||||
command. The
|
||||
.Nm
|
||||
script obtains the list of maps to transfer in one of two ways: if
|
||||
the system is configured as an NIS client and is bound to the master
|
||||
server,
|
||||
.Nm
|
||||
is able to use the
|
||||
.Xr ypwhich 8
|
||||
command to obtain a list of maps exported by the master server.
|
||||
If the system is not configured as a client of the NIS master,
|
||||
.Nm
|
||||
uses a hardcoded list of maps, some of which may or may not actually
|
||||
exist on the master. The system administrator can edit the script and
|
||||
modify the map list if necessary. Otherwise, indivudual maps can
|
||||
be transfered manually from the master using
|
||||
.Xr ypxfr 8 .
|
||||
.Pp
|
||||
.Sh OPTIONS
|
||||
.Nm
|
||||
supports the following options:
|
||||
.Bl -tag -width Fl
|
||||
.It Fl m Op Ar domainname
|
||||
Set up a master server. By default, the script sets up a server for
|
||||
the system default domain. The user can override this default by specifying
|
||||
.Ar domainname
|
||||
explicitly.
|
||||
Maps are constructed from scratch using local files as templates using
|
||||
the
|
||||
.Xr yp_mkdb 8
|
||||
command.
|
||||
.It Fl s Ar master_server Op Ar domainname
|
||||
Set up a slave server using
|
||||
.Ar master_name
|
||||
as the master. Maps are copied from
|
||||
.Ar master_server
|
||||
to the slave using
|
||||
.Xr ypxfr 8 .
|
||||
By default, the script sets up a server for
|
||||
the system default domain. The user can override this default by specifying
|
||||
.Ar domainname
|
||||
explicitly.
|
||||
.It Fl u Op Ar domainname
|
||||
Update the ypservers map on the master server. When a new slave
|
||||
server is added to a domain, its hostname must be added to the
|
||||
ypservers map so that
|
||||
.Xr yppush 8
|
||||
can propagate updates on the master to all of the slaves.
|
||||
.Sh FILES
|
||||
.Bl -tag -width /var/yp/master.passwd -compact
|
||||
.It Pa /etc/bootparams
|
||||
Bootparams source file
|
||||
.It Pa /etc/ethers
|
||||
Ethers data source file
|
||||
.It Pa /etc/group
|
||||
Group source file
|
||||
.It Pa /etc/hosts
|
||||
Hostname/IP address source file
|
||||
.It Pa /etc/netid
|
||||
RPC netid source file
|
||||
.It Pa /etc/networks
|
||||
Networks source file
|
||||
.It Pa /etc/protocols
|
||||
Protocols source file
|
||||
.It Pa /etc/publickey
|
||||
RPC public key/secret key source file
|
||||
.It Pa /etc/services
|
||||
Services data source file
|
||||
.It Pa /var/yp/master.passwd
|
||||
Passwd database source file
|
||||
.It Pa /var/yp/netgroup
|
||||
Netgroup data source file
|
||||
.It Pa /var/yp/ypservers
|
||||
Ypservers source file (generated by
|
||||
.Nm ypinit )
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr mknetid 8 ,
|
||||
.Xr revnetgroup 8 ,
|
||||
.Xr yp 4 ,
|
||||
.Xr yp_mkdb 8 ,
|
||||
.Xr yppush 8 ,
|
||||
.Xr ypserv 8 ,
|
||||
.Xr ypxfr 8
|
||||
.Sh HISTORY
|
||||
This version of
|
||||
.Nm
|
||||
is based on the
|
||||
.Nm
|
||||
script in OpenBSD. It first appeared in FreeBSD in
|
||||
.Fx 3.0 .
|
||||
.Sh AUTHOR
|
||||
The original script was written by
|
||||
.An Mats O Jansson Aq moj@stacken.kth.se .
|
||||
It was modified for FreeBSD by
|
||||
.An Bill Paul Aq wpaul@ctr.columbia.edu .
|
390
usr.sbin/ypserv/ypinit.sh
Normal file
390
usr.sbin/ypserv/ypinit.sh
Normal file
@ -0,0 +1,390 @@
|
||||
#!/bin/sh
|
||||
# $Id: ypinit.sh,v 1.3 1997/11/10 20:48:54 wpaul Exp $
|
||||
#
|
||||
# ypinit.sh - setup an master or slave server.
|
||||
# (Taken from OpenBSD and modified for FreeBSD.)
|
||||
#
|
||||
DOMAINNAME=/bin/domainname
|
||||
HOSTNAME=/bin/hostname
|
||||
YPWHICH=/usr/bin/ypwhich
|
||||
YPXFR=/usr/libexec/ypxfr
|
||||
YP_DIR=/var/yp
|
||||
MAKEDBM=/usr/sbin/yp_mkdb
|
||||
MAPLIST="master.passwd.byname master.passwd.byuid passwd.byname passwd.byuid \
|
||||
group.byname group.bygid hosts.byname hosts.byaddr services.byname \
|
||||
rpc.byname rpc.bynumber networks.byname networks.byaddr netgroup \
|
||||
netgroup.byuser netgroup.byhost netid.byname publickey.byname \
|
||||
bootparams ethers.byname ethers.byaddr amd.host mail.aliases \
|
||||
ypservers protocols.byname protocols.bynumber netmasks.byaddr"
|
||||
|
||||
ERROR_EXISTS="NO"
|
||||
umask 077
|
||||
|
||||
#set -xv
|
||||
|
||||
ERROR=USAGE # assume usage error
|
||||
|
||||
if [ $# -eq 1 ]
|
||||
then
|
||||
if [ $1 = "-m" ] # ypinit -m
|
||||
then
|
||||
DOMAIN=`${DOMAINNAME}`
|
||||
SERVERTYPE=MASTER
|
||||
ERROR=
|
||||
fi
|
||||
|
||||
if [ $1 = "-u" ] # ypinit -u
|
||||
then
|
||||
DOMAIN=`${DOMAINNAME}`
|
||||
SERVERTYPE=UPDATE
|
||||
ERROR=
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $# -eq 2 ]
|
||||
then
|
||||
if [ $1 = "-m" ] # ypinit -m domainname
|
||||
then
|
||||
DOMAIN=${2}
|
||||
SERVERTYPE=MASTER
|
||||
ERROR=
|
||||
fi
|
||||
|
||||
if [ $1 = "-s" ] # ypinit -s master_server
|
||||
then
|
||||
DOMAIN=`${DOMAINNAME}`
|
||||
SERVERTYPE=SLAVE
|
||||
MASTER=${2}
|
||||
ERROR=
|
||||
fi
|
||||
|
||||
if [ $1 = "-u" ] # ypinit -u domainname
|
||||
then
|
||||
DOMAIN=${2}
|
||||
SERVERTYPE=UPDATE
|
||||
ERROR=
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $# -eq 3 ]
|
||||
then
|
||||
if [ $1 = "-s" ] # ypinit -s master_server domainname
|
||||
then
|
||||
DOMAIN=${3}
|
||||
SERVERTYPE=SLAVE
|
||||
MASTER=${2}
|
||||
ERROR=
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${ERROR}" = "USAGE" ]; then
|
||||
cat << \__usage 1>&2
|
||||
usage: ypinit -m [domainname]
|
||||
ypinit -s master_server [domainname]
|
||||
ypinit -u [domainname]
|
||||
|
||||
The `-m' flag builds a master YP server, and the `-s' flag builds
|
||||
a slave YP server. When building a slave YP server, `master_server'
|
||||
must be an existing, reachable YP server.
|
||||
The `-u' is for updating the ypservers map on a master server.
|
||||
__usage
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if domainname is set, don't accept an empty domainname
|
||||
if [ -z "${DOMAIN}" ]; then
|
||||
cat << \__no_domain 1>&2
|
||||
The local host's YP domain name has not been set. Please set it with
|
||||
the domainname(8) command or pass the domain as an argument to ypinit(8).
|
||||
__no_domain
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if hostname is set, don't accept an empty hostname
|
||||
HOST=`${HOSTNAME}`
|
||||
if [ -z "${HOST}" ]; then
|
||||
cat << \__no_hostname 1>&2
|
||||
The local host's hostname has not been set. Please set it with the
|
||||
hostname(8) command.
|
||||
__no_hostname
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if we have contact with master.
|
||||
# If we can't list the maps on the master, then we fake it with a
|
||||
# hard-coded list of maps. The FreeBSD ypxfr command will work even
|
||||
# if ypbind isn't running or if we are bound to ourselves instead of
|
||||
# the master (the slave should be bound to itself, but since it has
|
||||
# no maps yet, we can't get a maplist from it).
|
||||
if [ "${SERVERTYPE}" = "SLAVE" ];
|
||||
then
|
||||
COUNT=`${YPWHICH} -d ${DOMAIN} -m 2>/dev/null | grep -i ${MASTER} | wc -l | tr -d " "`
|
||||
if [ "$COUNT" = "0" ]
|
||||
then
|
||||
echo "Can't enumerate maps from ${MASTER}. Please check that it is running." 1>&2
|
||||
echo "Note: using hardcoded maplist for map transfers." 1>&2
|
||||
YPMAPLIST=${MAPLIST}
|
||||
else
|
||||
YPMAPLIST=`${YPWHICH} -d ${DOMAIN} -m | cut -d\ -f1`
|
||||
fi
|
||||
echo "" 1>&2
|
||||
fi
|
||||
|
||||
# Check if user is root
|
||||
ID=`id -u`
|
||||
if [ "${ID}" != "0" ]; then
|
||||
echo "You have to be the superuser to run this. Please login as root." 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the YP directory exists.
|
||||
|
||||
if [ ! -d ${YP_DIR} -o -f ${YP_DIR} ]
|
||||
then
|
||||
echo "The directory ${YP_DIR} doesn't exist. Restore it from the distribution." 1>&2
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
echo -n "Server Type: ${SERVERTYPE} Domain: ${DOMAIN}"
|
||||
if [ "${SERVERTYPE}" = "SLAVE" ]; then
|
||||
echo -n " Master: ${MASTER}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
if [ "${SERVERTYPE}" != "UPDATE" ];
|
||||
then
|
||||
cat << \__notice1
|
||||
|
||||
Creating an YP server will require that you answer a few questions.
|
||||
Questions will all be asked at the beginning of the procedure.
|
||||
|
||||
__notice1
|
||||
|
||||
echo -n "Do you want this procedure to quit on non-fatal errors? [y/n: n] "
|
||||
read DOEXIT
|
||||
|
||||
case ${DOEXIT} in
|
||||
y*|Y*)
|
||||
ERROR_EXIT="YES"
|
||||
;;
|
||||
|
||||
*) ERROR_EXIT="NO"
|
||||
echo ""
|
||||
echo "Ok, please remember to go back and redo manually whatever fails."
|
||||
echo "If you don't, something might not work. "
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -d "${YP_DIR}/${DOMAIN}" ]; then
|
||||
echo ""
|
||||
echo -n "Can we destroy the existing ${YP_DIR}/${DOMAIN} and its contents? [y/n: n] "
|
||||
read KILL
|
||||
|
||||
ERROR=
|
||||
case ${KILL} in
|
||||
y*|Y*)
|
||||
ERROR="DELETE"
|
||||
;;
|
||||
|
||||
*) ERROR=
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "${ERROR}" = "DELETE" ]; then
|
||||
if ! rm -rf ${YP_DIR}/${DOMAIN}; then
|
||||
echo "Can't clean up old directory ${YP_DIR}/${DOMAIN}." 1>&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "OK, please clean it up by hand and start again. Bye"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if ! mkdir "${YP_DIR}/${DOMAIN}"; then
|
||||
echo "Can't make new directory ${YP_DIR}/${DOMAIN}." 1>&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${SERVERTYPE}" = "MASTER" ];
|
||||
then
|
||||
|
||||
if [ ! -f ${YP_DIR}/Makefile ]
|
||||
then
|
||||
if [ ! -f ${YP_DIR}/Makefile.dist ]
|
||||
then
|
||||
echo "Can't find ${YP_DIR}/Makefile.dist. " 1>&2
|
||||
exit 1
|
||||
fi
|
||||
cp ${YP_DIR}/Makefile.dist ${YP_DIR}/Makefile
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if [ "${SERVERTYPE}" = "SLAVE" ];
|
||||
then
|
||||
|
||||
echo "There will be no further questions. The remainder of the procedure"
|
||||
echo "should take a few minutes, to copy the databases from ${MASTER}."
|
||||
|
||||
for MAP in ${YPMAPLIST}
|
||||
do
|
||||
echo "Transfering ${MAP}..."
|
||||
if ! ${YPXFR} -p ${YP_DIR} -h ${MASTER} -c -d ${DOMAIN} ${MAP}; then
|
||||
echo "Can't transfer map ${MAP}." 1>&2
|
||||
ERROR_EXISTS="YES"
|
||||
if [ "${ERROR_EXIT}" = "YES" ]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
if [ "${ERROR_EXISTS}" = "YES" ]; then
|
||||
echo "${HOST} has been setup as an YP slave server with errors. " 1>&2
|
||||
echo "Please remember fix any problem that occurred." 1>&2
|
||||
else
|
||||
echo "${HOST} has been setup as an YP slave server without any errors. "
|
||||
fi
|
||||
|
||||
echo "Don't forget to update map ypservers on ${MASTER}."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
LIST_OK="NO"
|
||||
|
||||
while [ "${LIST_OK}" = "NO" ];
|
||||
do
|
||||
|
||||
if [ "${SERVERTYPE}" = "MASTER" ];
|
||||
then
|
||||
HOST_LIST="${HOST}"
|
||||
echo ""
|
||||
echo "At this point, we have to construct a list of this domains YP servers."
|
||||
echo "${HOST} is already known as master server."
|
||||
echo "Please continue to add any slave servers, one per line. When you are"
|
||||
echo "done with the list, type a <control D>."
|
||||
echo " master server : ${HOST}"
|
||||
fi
|
||||
|
||||
if [ "${SERVERTYPE}" = "UPDATE" ];
|
||||
then
|
||||
HOST_LIST="${HOST}"
|
||||
NEW_LIST=""
|
||||
MASTER_NAME=""
|
||||
SHORT_HOST=`echo ${HOST} | cut -d. -f1`
|
||||
if [ -f ${YP_DIR}/${DOMAIN}/ypservers ];
|
||||
then
|
||||
for srv in `${MAKEDBM} -u ${YP_DIR}/${DOMAIN}/ypservers | grep -v "^YP" | tr "\t" " " | cut -d\ -f1`;
|
||||
do
|
||||
short_srv=`echo ${srv} | cut -d. -f1`
|
||||
if [ "${SHORT_HOST}" != "${short_srv}" ]
|
||||
then
|
||||
if [ "${NEW_LIST}" = "" ];
|
||||
then
|
||||
NEW_LIST="${srv}"
|
||||
else
|
||||
NEW_LIST="${NEW_LIST} ${srv}"
|
||||
fi
|
||||
fi
|
||||
done;
|
||||
MASTER_NAME=`${MAKEDBM} -u ${YP_DIR}/${DOMAIN}/ypservers | grep "^YP_MASTER_NAME" | tr "\t" " " | cut -d\ -f2`
|
||||
fi
|
||||
echo ""
|
||||
echo "Update the list of hosts running YP servers in domain ${DOMAIN}."
|
||||
echo "Master for this domain is ${MASTER_NAME}."
|
||||
echo ""
|
||||
echo "First verify old servers, type \\ to remove a server."
|
||||
echo "Then add new servers, one per line. When done type a <control D>."
|
||||
echo ""
|
||||
echo " master server : ${HOST}"
|
||||
if [ "${NEW_LIST}" != "" ]; then
|
||||
for node in $NEW_LIST; do
|
||||
echo -n " verify host : [${node}] "
|
||||
read verify
|
||||
if [ "${verify}" != "\\" ]; then
|
||||
HOST_LIST="${HOST_LIST} ${node}"
|
||||
fi
|
||||
done;
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -n " next host to add: "
|
||||
|
||||
while read h
|
||||
do
|
||||
echo -n " next host to add: "
|
||||
HOST_LIST="${HOST_LIST} ${h}"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "The current list of NIS servers looks like this:"
|
||||
echo ""
|
||||
|
||||
for h in `echo ${HOST_LIST}`;
|
||||
do
|
||||
echo ${h}
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo -n "Is this correct? [y/n: y] "
|
||||
read hlist_ok
|
||||
|
||||
case $hlist_ok in
|
||||
n*) echo "Let's try the whole thing again...";;
|
||||
N*) echo "Let's try the whole thing again...";;
|
||||
*) LIST_OK="YES";;
|
||||
esac
|
||||
|
||||
done
|
||||
|
||||
echo "Building ${YP_DIR}/${DOMAIN}/ypservers..."
|
||||
rm -f ${YP_DIR}/ypservers
|
||||
touch -f ${YP_DIR}/ypservers
|
||||
rm -f ${YP_DIR}/${DOMAIN}/ypservers
|
||||
for host in ${HOST_LIST};
|
||||
do
|
||||
echo "${host} ${host}" >> ${YP_DIR}/ypservers
|
||||
echo "${host} ${host}"
|
||||
done | ${MAKEDBM} - ${YP_DIR}/${DOMAIN}/ypservers
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "" 1>&2
|
||||
echo "Couldn't build yp data base ${YP_DIR}/${DOMAIN}/ypservers." 1>&2
|
||||
ERROR_EXISTS="YES"
|
||||
if [ "${ERROR_EXIT}" = "YES" ]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${SERVERTYPE}" = "MASTER" ]; then
|
||||
|
||||
CUR_PWD=`pwd`
|
||||
cd ${YP_DIR}
|
||||
echo "Running ${YP_DIR}/Makefile..."
|
||||
if ! make NOPUSH=True UPDATE_DOMAIN=${DOMAIN} YP_DIR=${YP_DIR}; then
|
||||
echo "" 1>&2
|
||||
echo "Error running Makefile." 1>&2
|
||||
ERROR_EXISTS="YES"
|
||||
if [ "${ERROR_EXIT}" = "YES" ]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
cd ${CUR_PWD}
|
||||
|
||||
echo ""
|
||||
if [ "${ERROR_EXISTS}" = "YES" ]; then
|
||||
echo "${HOST} has been setup as an YP master server with errors. " 1>&2
|
||||
echo "Please remember fix any problem that occurred." 1>&2
|
||||
else
|
||||
echo "${HOST} has been setup as an YP master server without any errors. "
|
||||
fi
|
||||
|
||||
fi
|
Loading…
Reference in New Issue
Block a user