checkflist revision 1.34
1#! /bin/sh --
2#
3#	$NetBSD: checkflist,v 1.34 2009/04/23 09:30:56 apb 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 and METALOG.*
75# * ignore etc/mtree/set.*
76#
77IGNORE_REGEXP="^\./var/db/syspkg(\$|/)"
78IGNORE_REGEXP="${IGNORE_REGEXP}|^\./METALOG(\..*)?\$"
79IGNORE_REGEXP="${IGNORE_REGEXP}|^\./etc/mtree/set\.[a-z]*\$"
80
81#
82# Here would be a good place to add custom exceptions to flist checking.
83#
84
85#
86# Make three lists:
87# * ${SDIR}/files: files present in DESTDIR.
88# * ${SDIR}/flist: files mentioned in flist;
89# * ${SDIR}/mlist: files mentioned in metalog;
90#
91# All three lists are filtered against ${IGNORE_REGEXP}.
92#
93( cd "${DESTDIR}" && ${FIND} ${origin} \
94	\( -type d -o -type f -o -type l \) -print ) \
95	| ${SORT} -u | ${EGREP} -v -e "${IGNORE_REGEXP}" >"${SDIR}/files"
96${HOST_SH} "${rundir}/makeflist" ${xargs} ${dargs} \
97	| ${SORT} -u | ${EGREP} -v -e "${IGNORE_REGEXP}" >"${SDIR}/flist"
98if [ -n "${metalog}" ]; then
99	${AWK} '{print $1}' <"${metalog}" \
100	| ${SORT} -u | ${EGREP} -v -e "${IGNORE_REGEXP}" >"${SDIR}/mlist"
101fi
102
103#
104# compare DESTDIR with METALOG, and report on differences.
105#
106# XXX: Temporarily disabled due to problems with obsolete files in metalog
107#
108if false && [ -n "${metalog}" ]; then
109    ${COMM} -23 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/missing"
110    ${COMM} -13 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/extra"
111
112    # Handle case insensitive filesystems
113    mv -f "${SDIR}/extra" "${SDIR}/extra.all"
114    while read f; do
115	[ -f "${DESTDIR}/${f}" ] || \
116	    [ -d "${DESTDIR}/${f}" ] || \
117	    [ -L "${DESTDIR}/${f}" ] || echo "$f"
118    done < "${SDIR}/extra.all" > "${SDIR}/extra"
119
120    if [ -s "${SDIR}/extra" ]; then
121	count="$(${AWK} 'END {print NR}' "${SDIR}/extra")"
122	echo ""
123	echo "=======  ${count} extra files in METALOG  ========="
124	echo "Files in METALOG but missing from DESTDIR."
125	echo "File was deleted after installation ?"
126	echo "------------------------------------------"
127	cat "${SDIR}/extra"
128	echo "=========  end of ${count} extra files  ==========="
129	echo ""
130	es=1 # this is fatal even if ${allowextra} is true
131    fi
132
133    if [ -s "${SDIR}/missing" ]; then
134	count="$(${AWK} 'END {print NR}' "${SDIR}/missing")"
135	echo ""
136	echo "======  ${count} missing files in METALOG  ========"
137	echo "Files in DESTDIR but missing from METALOG."
138	echo "File installed but not registered in METALOG ?"
139	echo "------------------------------------------"
140	cat "${SDIR}/missing"
141	echo "========  end of ${count} missing files  =========="
142	echo ""
143	es=1 # this is fatal even if ${allowmissing} is true
144    fi
145fi
146
147#
148# compare flist with DESTDIR, and report on differences.
149#
150${COMM} -23 "${SDIR}/flist" "${SDIR}/files" > "${SDIR}/missing"
151${COMM} -13 "${SDIR}/flist" "${SDIR}/files" > "${SDIR}/extra"
152
153# Handle case insensitive filesystems
154mv -f "${SDIR}/missing" "${SDIR}/missing.all"
155while read f; do
156    [ -f "${DESTDIR}/${f}" ] || \
157	[ -d "${DESTDIR}/${f}" ] || \
158	[ -L "${DESTDIR}/${f}" ] || echo "$f"
159done < "${SDIR}/missing.all" > "${SDIR}/missing"
160
161if [ -s "${SDIR}/extra" ]; then
162	count="$(${AWK} 'END {print NR}' "${SDIR}/extra")"
163	echo ""
164	echo "=======  ${count} extra files in DESTDIR  ========="
165	echo "Files in DESTDIR but missing from flist."
166	echo "File is obsolete or flist is out of date ?"
167	if ${allowextra}; then
168		echo "This is non-fatal, due to '-e' option."
169	else
170		es=1
171	fi
172	echo "------------------------------------------"
173	cat "${SDIR}/extra"
174	echo "=========  end of ${count} extra files  ==========="
175	echo ""
176fi
177
178if [ -s "${SDIR}/missing" ]; then
179	count="$(${AWK} 'END {print NR}' "${SDIR}/missing")"
180	echo ""
181	echo "======  ${count} missing files in DESTDIR  ========"
182	echo "Files in flist but missing from DESTDIR."
183	echo "File wasn't installed ?"
184	if ${allowmissing}; then
185		echo "This is non-fatal, due to '-m' option."
186	else
187		es=1
188	fi
189	echo "------------------------------------------"
190	cat "${SDIR}/missing"
191	echo "========  end of ${count} missing files  =========="
192	echo ""
193fi
194
195exit 0		# cleanup will exit with ${es}
196