Subject: some new sanity checks for etc's Makefile
To: None <netbsd-users@NetBSD.org>
From: VaX#n8 <vax@linkdead.gangsta.local>
List: netbsd-users
Date: 06/25/2003 18:45:39
Hi, the Makefile for the etc project I keep under CVS has a few handy
targets that I thought you might find useful (and maybe include in
future revs?).  The only caveat is that they may only be current
as of NetBSD-1.3 or NetBSD-1.4 --- in particular, it is my understanding
that the master.passwd format changed.

====snip====
#! /usr/bin/make -f

# [...]

# Try to make all changes active by reloading or restarting everything.
afterinstall: realinstall
.if !defined(DESTDIR)
	# NOTE: run in bg b/c sometimes it takes a LONG time
	newaliases &
	test -r /var/run/mountd.pid && kill -s HUP `cat /var/run/mountd.pid`
	test -r /var/run/syslog.pid && kill -s HUP `cat /var/run/syslog.pid`
	kill -s HUP `cat /var/run/inetd.pid`
	ndc reload
	-swapon -a
	-umount -A
	-ccdconfig -U
	-ccdconfig -C
	mount -a
	. ./rc.conf && { \
		cp /etc/ttys.$$console /etc/ttys; \
		kill -s HUP 1; \
		ttyflags -a; \
	}
	pwd_mkdb -p /etc/master.passwd
.endif

.PHONY: print_disklabels

print_disklabels:
	for d in $$(cut -f 1 -d\  < fstab | sed -ne 's!/dev/\(sd[0-9]\)[a-z]!\1!p' | sort -u); do disklabel $$d; echo; done | lpr -c

.PHONY: print_mounts

print_mounts:
	(echo mount:; echo; mount; echo; echo fstab:; echo; cat fstab) | lpr -c

.PHONY: print

print: print_disklabels print_mounts

.PHONY: store_disklabels

store_disklabels:
	for d in $$(cut -f 1 -d\  < fstab | sed -ne 's!/dev/\(sd[0-9]\)[a-z]!\1!p' | sort -u); do disklabel $$d > /etc/disklabels/$$(disklabel $$d | grep label: | cut -f 2 -d\ ); done

.PHONY: test_newsyslog

test_newsyslog:
	(while read line; do case "$$line" in \#*);; "");; *) set -f; set -- $$line; set +f; case "$$# $$2" in 5\ *|6\ *.*) m="$$2"; n="$$3";; 6\ *|7\ *) m="$$3"; n="$$4"; z="$${7##B}"; z="$${z%%B}";; *) echo "error: line has odd number of fields; $$#: $$line" >&2;; esac; f="$$1"; if test "$$n" != '*'; then while n=$$(($$n + 1)); test -e $${f}.$${n}.$${z:+gz}; do echo "$${f}.$${n}.$${z:+gz}"; n=$$(($$n + 1)); done; fi;; esac; done) < newsyslog.conf

.PHONY: test_ftpusers

test_ftpusers:
	# ftpusers test
	(while read line; do IFS=":"; set -f; set -- $$line; set +f; if test "$$#" -eq 7; then if test "$$3" -eq "0" && ftpd -c . -C "$$1"; then echo "user $$0 has uid 0 but is not in ftpusers" >&2; exit 1; fi; else echo "bad passwd line: $$line" >&2; exit 1; fi; done) < /etc/passwd
	test -r /etc/master.passwd && (ex=0; noftpck() { if ftpd -c . -C "$$1"; then echo "user $$1 should probably be in ftpusers" >&2; ex=1; fi; return 0; }; while read line; do IFS=":"; set -f; set -- $$line; set +f; if test "$$#" -eq 10; then if test "$$3" -eq "0"; then noftpck "$$1"; else :; case "$$1" in \*) noftpck "$$1";; esac; fi; else echo "bad passwd line: $$line" >&2; exit 1; fi; done; exit $$ex) < /etc/master.passwd

.PHONY: test

test: test_ftpusers test_newsyslog