#      @(#)make.script	4.3 System V NFS  source
#      SCCS IDENTIFICATION
#	System V NFS - Release 3.2.4
#
#	Copyright 1986, 1987, 1988, 1989 Lachman Associates, Incorporated (LAI)
#
#	All Rights Reserved.
#
#	The copyright above and this notice must be preserved in all
#	copies of this source code.  The copyright above does not
#	evidence any actual or intended publication of this source
#	code.
#
#	This is unpublished proprietary trade secret source code of
#	Lachman Associates.  This source code may not be copied,
#	disclosed, distributed, demonstrated or licensed except as
#	expressly authorized by Lachman Associates.
#

#      @(#)make.script	4.8 Lachman System V NFS  source

#
#	@(#)make.script 1.1 86/02/05 SMI
#

DIR = /etc
DOM = `/usr/bin/domainname`
NOPUSH = ""
SILENT = ""
PASSWD = $(DIR)/passwd
YPPASSWD = $(DIR)/passwd.yp
GROUP = $(DIR)/group.yp
ALIASES=/usr/lib/mail/aliases
AWK = oawk

all: passwd group hosts ethers networks rpc services protocols \
	netgroup aliases

passwd.time: $(PASSWD)
	-@if [ `grep -c "passwd.nam" /etc/yp/YP_MAP_X_LATE ` != "0" ]; then \
		`/etc/yp/ypsecure` ;\
		if [  $$?  = 0 ] ; then \
		    `/etc/yp/ypshad2pwd /etc/passwd /etc/shadow /etc/passwd.yp` ;\
		    if [ -f $(YPPASSWD) ]; then \
			    $(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ { print $$1, $$0 }' \
			      $(YPPASSWD)  | /etc/yp/makedbm - /etc/yp/$(DOM)/passwd.nam; \
			    $(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ { print $$3, $$0 }' \
			      $(YPPASSWD) | /etc/yp/makedbm - /etc/yp/$(DOM)/passwd.uid; \
			    touch passwd.time; \
			    sync ; \
			    sync ; \
			    if [ ! $(SILENT) ]; then \
				    echo "updated passwd"; \
			    fi;\
			    if [ ! $(NOPUSH) ]; then \
				    /etc/yp/yppush passwd.uid; \
				    /etc/yp/yppush passwd.nam; \
				    if [ ! $(SILENT) ]; then \
					    echo "pushed passwd"; \
				    fi;\
			    else \
				    : ; \
			    fi; \
			    if [ -f /etc/yp/map2ascii/passwd.nam ]; then \
				    /etc/yp/map2ascii/passwd.nam; \
			    fi \
		    else \
			    echo "couldn't find $(YPPASSWD)"; \
		    fi \
		else \
			echo "couldn't propgate map due to security level" ; \
		fi \
	else \
		: ; \
	fi

group.time: $(GROUP)
	-@if [ `grep -c "group.nam" /etc/yp/YP_MAP_X_LATE ` != 0 ]; then \
		`/etc/yp/ypsecure` ;\
		if [ $$?  = 0 ] ; then \
		    if [ -f $(GROUP) ]; then \
			    $(AWK) 'BEGIN { FS=":"; OFS="\t"; } { print $$1, $$0 }' \
				$(GROUP) | /etc/yp/makedbm - /etc/yp/$(DOM)/group.nam; \
			    $(AWK) 'BEGIN { FS=":"; OFS="\t"; } { print $$3, $$0 }' \
				$(GROUP) | /etc/yp/makedbm - /etc/yp/$(DOM)/group.gid; \
			    touch group.time; \
			    echo "updated group"; \
			    if [ ! $(NOPUSH) ]; then \
				    /etc/yp/yppush group.nam; \
				    /etc/yp/yppush group.gid; \
				    echo "pushed group"; \
			    else \
				    : ; \
			    fi; \
			    if [ -f /etc/yp/map2ascii/group.nam ]; then \
				    /etc/yp/map2ascii/group.nam; \
			    fi \
		    else \
			    echo "couldn't find $(GROUP)"; \
		    fi \
		else \
			echo "couldn't propgate map due to security level" ; \
		fi \
	else \
		: ; \
	fi

hosts.time: $(DIR)/hosts
	-@if [ `grep -c "hosts.adr" /etc/yp/YP_MAP_X_LATE ` != "0" ]; then \
		if [ -f $(DIR)/hosts ]; then \
			sed -e "/^#/d" -e s/#.*$$// $(DIR)/hosts | /etc/yp/stdhosts \
			    | $(AWK) '{for (i = 2; i <= NF; i++) print $$i, $$0}' \
			    | /etc/yp/makedbm - /etc/yp/$(DOM)/hosts.nam; \
			/etc/yp/stdhosts $(DIR)/hosts | \
			    $(AWK) 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$1, $$0 }' \
			    | /etc/yp/makedbm - /etc/yp/$(DOM)/hosts.adr; \
			touch hosts.time; \
			echo "updated hosts"; \
			if [ ! $(NOPUSH) ]; then \
				/etc/yp/yppush hosts.nam; \
				/etc/yp/yppush hosts.adr; \
				echo "pushed hosts"; \
			else \
				: ; \
			fi \
		else \
			echo "couldn't find $(DIR)/hosts"; \
		fi \
	else \
		: ; \
	fi

ethers.time: $(DIR)/ethers
	-@if [ `grep -c "ethers.adr" /etc/yp/YP_MAP_X_LATE ` != "0" ]; then \
		if [ -f $(DIR)/ethers ]; then \
			sed -e "/^#/d" -e s/#.*$$// $(DIR)/ethers \
			| $(AWK) 'BEGIN { X["A"]="a"; X["B"]="b"; X["C"]="c"; X["D"]="d";X["E"]="e"; X["F"]="f"; } \
			    { for (i = 1; i <= length($$1); i++) \
			      if (substr($$1, i, 1) >= "A" && substr($$1, i, 1) <= "Z") \
				printf("%s", X[substr($$1, i, 1)]) ; \
			      else \
				printf("%s", substr($$1, i, 1)); printf(" "); \
			    print $$2}' \
			|$(AWK) '{print $$1, $$0; for (i = 3;i <= NF;i++) print $$i,$$0}' \
			| /etc/yp/makedbm - /etc/yp/$(DOM)/ethers.adr; \
			$(AWK) 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$2, $$0 }' \
			   $(DIR)/ethers | \
			/etc/yp/makedbm - /etc/yp/$(DOM)/ethers.nam;\
			touch ethers.time; \
			echo "updated ethers"; \
			if [ ! $(NOPUSH) ]; then \
				/etc/yp/yppush ethers.nam; \
				/etc/yp/yppush ethers.adr; \
				echo "pushed ethers"; \
			else \
				: ; \
			fi \
		else \
			echo "couldn't find $(DIR)/ethers"; \
		fi \
	else \
		: ; \
	fi

networks.time: $(DIR)/networks
	-@if [ `grep -c "netwks.nam" /etc/yp/YP_MAP_X_LATE ` != "0" ]; then \
		if [ -f $(DIR)/networks ]; then \
			sed -e "/^#/d" -e s/#.*$$// $(DIR)/networks | $(AWK) \
			    '{print $$1, $$0; for (i = 3;i <= NF;i++) print $$i,$$0}' \
			    | /etc/yp/makedbm - /etc/yp/$(DOM)/netwks.nam; \
			$(AWK) 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$2, $$0 }' \
			   $(DIR)/networks | /etc/yp/makedbm - /etc/yp/$(DOM)/netwks.adr;\
			touch networks.time; \
			echo "updated networks"; \
			if [ ! $(NOPUSH) ]; then \
				/etc/yp/yppush netwks.nam; \
				/etc/yp/yppush netwks.adr; \
				echo "pushed networks"; \
			else \
				: ; \
			fi \
		else \
			echo "couldn't find $(DIR)/networks"; \
		fi \
	else \
		: ; \
	fi

services.time: $(DIR)/services
	-@if [ `grep -c "srvcs.nam" /etc/yp/YP_MAP_X_LATE ` != "0" ]; then \
		if [ -f $(DIR)/services ]; then \
			$(AWK) 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$2, $$0 }' \
			    $(DIR)/services| /etc/yp/makedbm - /etc/yp/$(DOM)/srvcs.nam;\
			touch services.time; \
			echo "updated services"; \
			if [ ! $(NOPUSH) ]; then \
				/etc/yp/yppush srvcs.nam; \
				echo "pushed services"; \
			else \
				: ; \
			fi \
		else \
			echo "couldn't find $(DIR)/services"; \
		fi \
	else \
		: ; \
	fi

rpc.time: $(DIR)/rpc
	-@if [ `grep -c "rpc.no" /etc/yp/YP_MAP_X_LATE ` != "0" ]; then \
		if [ -f $(DIR)/rpc ]; then \
			$(AWK) 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$2, $$0 }' \
			    $(DIR)/rpc| /etc/yp/makedbm - /etc/yp/$(DOM)/rpc.no;\
			touch rpc.time; \
			echo "updated rpc"; \
			if [ ! $(NOPUSH) ]; then \
				/etc/yp/yppush rpc.no; \
				echo "pushed rpc"; \
			else \
				: ; \
			fi \
		else \
			echo "couldn't find $(DIR)/rpc"; \
		fi \
	else \
		: ; \
	fi

protocols.time: $(DIR)/protocols
	-@if [ `grep -c "proto.nam" /etc/yp/YP_MAP_X_LATE ` != "0" ]; then \
		if [ -f $(DIR)/protocols ]; then \
			$(AWK) 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$2, $$0 }' \
			    $(DIR)/protocols | /etc/yp/makedbm - \
			    /etc/yp/$(DOM)/proto.no; \
			sed -e "/^#/d" -e s/#.*$$// $(DIR)/protocols | $(AWK) \
			    '{print $$1,$$0; for (i = 3;i <= NF;i++) print $$i, $$0}' \
			    | /etc/yp/makedbm - /etc/yp/$(DOM)/proto.nam; \
			touch protocols.time; \
			echo "updated protocols"; \
			if [ ! $(NOPUSH) ]; then \
				/etc/yp/yppush proto.nam; \
				/etc/yp/yppush proto.no; \
				echo "pushed protocols"; \
				else \
				: ; \
			fi \
		else \
			echo "couldn't find $(DIR)/protocols"; \
		fi \
	else \
		: ; \
	fi

netgroup.time: $(DIR)/netgroup
	-@if [ `grep -c "netgrp.hst" /etc/yp/YP_MAP_X_LATE ` != "0" ] ; then \
		if [ -f $(DIR)/netgroup ]; then \
			/etc/yp/makedbm $(DIR)/netgroup /etc/yp/$(DOM)/netgroup; \
			/etc/yp/revnetgroup -u | /etc/yp/makedbm - /etc/yp/$(DOM)/netgrp.usr; \
			/etc/yp/revnetgroup -h | /etc/yp/makedbm - /etc/yp/$(DOM)/netgrp.hst; \
			touch netgroup.time; \
			echo "updated netgroup"; \
			if [ ! $(NOPUSH) ]; then \
				/etc/yp/yppush netgroup; \
				/etc/yp/yppush netgrp.usr; \
				/etc/yp/yppush netgrp.hst; \
				echo "pushed netgroup"; \
			else \
				: ; \
			fi \
		else \
			echo "couldn't find $(DIR)/netgroup"; \
		fi \
	else \
		: ; \
	fi

aliases.time: $(ALIASES)
		-@if [ `grep -c "mail.alias" /etc/yp/YP_MAP_X_LATE ` != "0" ]; then \
		  if [ -f $(ALIASES) ]; then \
			cp $(ALIASES) /etc/yp/$(DOM)/mail.alias; \
			/usr/lib/sendmail -bi -oA/etc/yp/$(DOM)/mail.alias; \
			rm /etc/yp/$(DOM)/mail.alias; \
			touch aliases.time; \
			echo "updated aliases"; \
			if [ ! $(NOPUSH) ]; then \
				/etc/yp/yppush mail.alias; \
				echo "pushed aliases"; \
			else \
				: ; \
			fi \
		else \
			echo "couldn't find $(ALIASES)"; \
		fi \
	else \
		: ; \
	fi

auto.mstr.time:  $(DIR)/auto.master
	-@if [ `grep -c "auto.mstr" /etc/yp/YP_MAP_X_LATE ` != "0" ]; then \
		if [ -f $(DIR)/auto.master ]; then \
			sed -e "/^#/d" -e s/#.*$$// $(DIR)/auto.master \
			| /etc/yp/makedbm - /etc/yp/$(DOM)/auto.mstr; \
			touch auto.mstr.time; \
			echo "updated auto.master"; \
			if [ ! $(NOPUSH) ]; then \
				/etc/yp/yppush auto.mstr; \
				echo "pushed auto.master"; \
			else \
			: ; \
			fi \
		else \
			echo "couldn't find $(DIR)/auto.master"; \
		fi \
	fi

auto.home.time:  $(DIR)/auto.home
	-@if [ `grep -c "auto.home" /etc/yp/YP_MAP_X_LATE ` != "0" ]; then \
		if [ -f $(DIR)/auto.home ]; then \
			sed -e "/^#/d" -e s/#.*$$// $(DIR)/auto.home \
			| /etc/yp/makedbm - /etc/yp/$(DOM)/auto.home; \
			touch auto.home.time; \
			echo "updated auto.home"; \
			if [ ! $(NOPUSH) ]; then \
				/etc/yp/yppush auto.home; \
				echo "pushed auto.home"; \
			else \
			: ; \
			fi \
		else \
			echo "couldn't find $(DIR)/auto.home"; \
		fi \
	fi

passwd: passwd.time
group: group.time
hosts: hosts.time
ethers: ethers.time
networks: networks.time
rpc: rpc.time
services: services.time
protocols: protocols.time
netgroup: netgroup.time
aliases: aliases.time
auto.home: auto.home.time
auto.master: auto.mstr.time
$(PASSWD):
$(GROUP):
$(DIR)/hosts:
$(DIR)/ethers:
$(DIR)/networks:
$(DIR)/rpc:
$(DIR)/services:
$(DIR)/protocols:
$(DIR)/netgroup:
$(DIR)/auto.master:
$(DIR)/auto.home:
$(ALIASES):
