checkflist revision 1.20
1#! /bin/sh --
2#
3#	$NetBSD: checkflist,v 1.20 2003/08/12 04:20:08 lukem Exp $
4#
5# Verify output of makeflist against contents of $DESTDIR.
6
7if [ -z "$DESTDIR" ]; then
8	echo "DESTDIR must be set"
9	exit 1
10fi
11
12prog=${0##*/}
13
14
15# Make sure we don't loop forever if mkdir will always fail.
16if [ ! -d /tmp ]; then
17	echo /tmp is not a directory
18	exit 1
19fi
20
21if [ ! -w /tmp ]; then
22	echo /tmp is not writable
23	exit 1
24fi
25
26SDIR_BASE=/tmp/checkflist.$$
27SDIR_SERIAL=0
28
29while true; do
30	SDIR=${SDIR_BASE}.${SDIR_SERIAL}
31	mkdir -m 0700 ${SDIR} && break
32	SDIR_SERIAL=$((${SDIR_SERIAL} + 1))
33done    
34
35es=0
36cleanup()
37{
38	/bin/rm -rf $SDIR
39	if [ $es -gt 255 ] ; then
40		es=255
41	fi
42	exit $es
43}
44trap cleanup 0 2 3 13		# EXIT INT QUIT PIPE
45
46
47origin=.
48xargs=""
49dargs=""
50metalog=
51
52# handle args
53while : ; do
54	case $1 in
55	-x11)
56		xargs="-x"
57		origin="./etc/X11 ./etc/fonts ./usr/X11R6"
58		;;
59	-both)
60		xargs="-b"
61		;;
62	-M*)
63		metalog=$2; shift
64		;;
65	-*)
66		cat 1>&2 <<USAGE
67Usage: ${prog} [-x11|-both] [-M metalog]
68	-x11		check only x11 lists
69	-both		check netbsd + x11 lists
70	-M metalog	metalog file
71USAGE
72		exit 1
73		;;
74	*)
75		break
76		;;
77	esac
78	shift
79done
80
81if [ -n "$metalog" ]; then
82	case "$metalog" in
83	${DESTDIR}/*)
84		# Metalog would be noticed, so make sure it gets
85		# ignored.
86		metalog="./${metalog#${DESTDIR}/}"
87		;;
88	*)
89		metalog=""
90	esac
91fi
92
93
94sh makeflist $xargs $dargs > $SDIR/flist
95
96(
97	cd $DESTDIR
98	find $origin \( -type d -o -type f -o -type l \)
99) | (
100	while read line; do
101		case "$line" in
102		$metalog)
103			;;
104		*)
105			echo $line
106			;;
107		esac
108	done
109) | sort > $SDIR/files
110
111comm -23 $SDIR/flist $SDIR/files > $SDIR/missing
112comm -13 $SDIR/flist $SDIR/files > $SDIR/extra
113
114if [ -s $SDIR/extra ]; then
115	echo ""
116	echo "============  extra files  ==============="
117	echo "Files in DESTDIR but missing from flist."
118	echo "File is obsolete or flist is out of date ?"
119	echo "This is non-fatal."
120	echo "------------------------------------------"
121	cat $SDIR/extra
122	echo "=========  end of extra files  ==========="
123	echo ""
124fi
125
126if [ -s $SDIR/missing ]; then
127	echo ""
128	echo "===========  missing files  =============="
129	echo "Files in flist but missing from DESTDIR."
130	echo "File wasn't installed ?"
131	echo "------------------------------------------"
132	cat $SDIR/missing
133	echo "========  end of missing files  =========="
134	echo ""
135	es=1
136fi
137
138exit 0		# cleanup will exit with $es
139