checkflist revision 1.33
1#! /bin/sh --
2#
3#	$NetBSD: checkflist,v 1.33 2006/09/11 22:16:10 dbj Exp $
4#
5# Verify output of makeflist against contents of ${DESTDIR} and ${metalog}.
6
7if [ -z "${DESTDIR}" ]; then
8	echo "DESTDIR must be set"
9	exit 1
10fi
11
12prog="${0##*/}"
13rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
14. "${rundir}/sets.subr"
15
16SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
17
18es=0
19cleanup()
20{
21	/bin/rm -rf "${SDIR}"
22	if [ ${es} -gt 255 ]; then
23		es=255
24	fi
25	exit ${es}
26}
27trap cleanup 0 2 3 13		# EXIT INT QUIT PIPE
28
29origin=.
30xargs=""
31dargs=""
32metalog=
33allowextra=false
34allowmissing=false
35
36# handle args
37while getopts xbM:em ch; do
38	case ${ch} in
39	x)
40		xargs="-x"
41		origin="./etc/X11 ./etc/fonts ./usr/X11R6"
42		;;
43	b)
44		xargs="-b"
45		;;
46	M)
47		metalog="${OPTARG}"
48		;;
49	e)
50		allowextra=true
51		;;
52	m)
53		allowmissing=true
54		;;
55	*)
56		cat 1>&2 <<USAGE
57Usage: ${prog} [-x|-b] [-M metalog] [-e] [-m]
58	-x		check only x11 lists
59	-b		check netbsd + x11 lists
60	-M metalog	metalog file
61	-e		extra files are not considered an error
62	-m		missing files are not considered an error
63USAGE
64		exit 1
65		;;
66	esac
67done
68shift $((${OPTIND} - 1))
69
70#
71# Exceptions to flist checking (all begin with "./"):
72#
73# * ignore var/db/syspkg and its contents
74# * ignore ${metalog}
75# * ignore METALOG
76# * ignore etc/mtree/set.*
77#
78IGNORE_REGEXP="^\./var/db/syspkg(\$|/)"
79if [ -n "${metalog}" ]; then
80	ml="${metalog#${DESTDIR}/}"
81	ml2="METALOG"
82	IGNORE_REGEXP="${IGNORE_REGEXP}|^\./${ml}\$|^\./${ml2}\$"
83	IGNORE_REGEXP="${IGNORE_REGEXP}|^\./etc/mtree/set\.[a-z]*\$"
84fi
85
86#
87# Here would be a good place to add custom exceptions to flist checking.
88#
89
90#
91# Make three lists:
92# * ${SDIR}/files: files present in DESTDIR.
93# * ${SDIR}/flist: files mentioned in flist;
94# * ${SDIR}/mlist: files mentioned in metalog;
95#
96( cd "${DESTDIR}" && ${FIND} ${origin} \
97	\( -type d -o -type f -o -type l \) -print ) \
98	| ${SORT} -u | ${EGREP} -v -e "${IGNORE_REGEXP}" >"${SDIR}/files"
99${HOST_SH} "${rundir}/makeflist" ${xargs} ${dargs} \
100	| ${SORT} -u | ${EGREP} -v -e "${IGNORE_REGEXP}" >"${SDIR}/flist"
101if [ -n "${metalog}" ]; then
102	${AWK} '{print $1}' <"${metalog}" \
103	| ${SORT} -u | ${EGREP} -v -e "${IGNORE_REGEXP}" >"${SDIR}/mlist"
104fi
105
106#
107# compare DESTDIR with METALOG, and report on differences.
108#
109# XXX: Temporarily disabled due to problems with obsolete files in metalog
110#
111if false && [ -n "${metalog}" ]; then
112    ${COMM} -23 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/missing"
113    ${COMM} -13 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/extra"
114
115    # Handle case insensitive filesystems
116    mv -f "${SDIR}/extra" "${SDIR}/extra.all"
117    while read f; do
118	[ -f "${DESTDIR}/${f}" ] || \
119	    [ -d "${DESTDIR}/${f}" ] || \
120	    [ -L "${DESTDIR}/${f}" ] || echo "$f"
121    done < "${SDIR}/extra.all" > "${SDIR}/extra"
122
123    if [ -s "${SDIR}/extra" ]; then
124	count="$(${AWK} 'END {print NR}' "${SDIR}/extra")"
125	echo ""
126	echo "=======  ${count} extra files in METALOG  ========="
127	echo "Files in METALOG but missing from DESTDIR."
128	echo "File was deleted after installation ?"
129	echo "------------------------------------------"
130	cat "${SDIR}/extra"
131	echo "=========  end of ${count} extra files  ==========="
132	echo ""
133	es=1 # this is fatal even if ${allowextra} is true
134    fi
135
136    if [ -s "${SDIR}/missing" ]; then
137	count="$(${AWK} 'END {print NR}' "${SDIR}/missing")"
138	echo ""
139	echo "======  ${count} missing files in METALOG  ========"
140	echo "Files in DESTDIR but missing from METALOG."
141	echo "File installed but not registered in METALOG ?"
142	echo "------------------------------------------"
143	cat "${SDIR}/missing"
144	echo "========  end of ${count} missing files  =========="
145	echo ""
146	es=1 # this is fatal even if ${allowmissing} is true
147    fi
148fi
149
150#
151# compare flist with DESTDIR, and report on differences.
152#
153${COMM} -23 "${SDIR}/flist" "${SDIR}/files" > "${SDIR}/missing"
154${COMM} -13 "${SDIR}/flist" "${SDIR}/files" > "${SDIR}/extra"
155
156# Handle case insensitive filesystems
157mv -f "${SDIR}/missing" "${SDIR}/missing.all"
158while read f; do
159    [ -f "${DESTDIR}/${f}" ] || \
160	[ -d "${DESTDIR}/${f}" ] || \
161	[ -L "${DESTDIR}/${f}" ] || echo "$f"
162done < "${SDIR}/missing.all" > "${SDIR}/missing"
163
164if [ -s "${SDIR}/extra" ]; then
165	count="$(${AWK} 'END {print NR}' "${SDIR}/extra")"
166	echo ""
167	echo "=======  ${count} extra files in DESTDIR  ========="
168	echo "Files in DESTDIR but missing from flist."
169	echo "File is obsolete or flist is out of date ?"
170	if ${allowextra}; then
171		echo "This is non-fatal, due to '-e' option."
172	else
173		es=1
174	fi
175	echo "------------------------------------------"
176	cat "${SDIR}/extra"
177	echo "=========  end of ${count} extra files  ==========="
178	echo ""
179fi
180
181if [ -s "${SDIR}/missing" ]; then
182	count="$(${AWK} 'END {print NR}' "${SDIR}/missing")"
183	echo ""
184	echo "======  ${count} missing files in DESTDIR  ========"
185	echo "Files in flist but missing from DESTDIR."
186	echo "File wasn't installed ?"
187	if ${allowmissing}; then
188		echo "This is non-fatal, due to '-m' option."
189	else
190		es=1
191	fi
192	echo "------------------------------------------"
193	cat "${SDIR}/missing"
194	echo "========  end of ${count} missing files  =========="
195	echo ""
196fi
197
198exit 0		# cleanup will exit with ${es}
199