checkflist revision 1.36
11.3Smikel#! /bin/sh --
21.3Smikel#
31.35Suebayasi#	$NetBSD: checkflist,v 1.36 2009/12/10 16:01:06 uebayasi Exp $
41.3Smikel#
51.30Sapb# Verify output of makeflist against contents of ${DESTDIR} and ${metalog}.
61.1Scgd
71.29Sapbif [ -z "${DESTDIR}" ]; then
81.15Slukem	echo "DESTDIR must be set"
91.1Scgd	exit 1
101.15Slukemfi
111.15Slukem
121.29Sapbprog="${0##*/}"
131.27Sapbrundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
141.27Sapb. "${rundir}/sets.subr"
151.1Scgd
161.29SapbSDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
171.20Slukem
181.20Slukemes=0
191.20Slukemcleanup()
201.20Slukem{
211.29Sapb	/bin/rm -rf "${SDIR}"
221.32Sapb	if [ ${es} -gt 255 ]; then
231.20Slukem		es=255
241.20Slukem	fi
251.29Sapb	exit ${es}
261.20Slukem}
271.20Slukemtrap cleanup 0 2 3 13		# EXIT INT QUIT PIPE
281.20Slukem
291.9Srossorigin=.
301.10Sperryxargs=""
311.10Sperrydargs=""
321.15Slukemmetalog=
331.22Slukemallowextra=false
341.22Slukemallowmissing=false
351.10Sperry
361.10Sperry# handle args
371.35Suebayasiwhile getopts xybL:M:em ch; do
381.24Slukem	case ${ch} in
391.24Slukem	x)
401.10Sperry		xargs="-x"
411.18Stron		origin="./etc/X11 ./etc/fonts ./usr/X11R6"
421.10Sperry		;;
431.35Suebayasi	y)
441.35Suebayasi		xargs="-y"
451.35Suebayasi		origin="./etc/ext ./usr/ext"
461.35Suebayasi		;;
471.35Suebayasi	# backward compat
481.24Slukem	b)
491.10Sperry		xargs="-b"
501.10Sperry		;;
511.35Suebayasi	L)
521.35Suebayasi		xargs="-L ${OPTARG}"
531.35Suebayasi		;;
541.24Slukem	M)
551.29Sapb		metalog="${OPTARG}"
561.15Slukem		;;
571.24Slukem	e)
581.22Slukem		allowextra=true
591.22Slukem		;;
601.24Slukem	m)
611.22Slukem		allowmissing=true
621.22Slukem		;;
631.24Slukem	*)
641.10Sperry		cat 1>&2 <<USAGE
651.35SuebayasiUsage: ${prog} [-x|-y|-b|-L lists] [-M metalog] [-e] [-m]
661.24Slukem	-x		check only x11 lists
671.35Suebayasi	-y		check only extsrc lists
681.24Slukem	-b		check netbsd + x11 lists
691.35Suebayasi	-L base,x,ext	check specified lists
701.15Slukem	-M metalog	metalog file
711.22Slukem	-e		extra files are not considered an error
721.22Slukem	-m		missing files are not considered an error
731.10SperryUSAGE
741.10Sperry		exit 1
751.10Sperry		;;
761.10Sperry	esac
771.10Sperrydone
781.24Slukemshift $((${OPTIND} - 1))
791.10Sperry
801.30Sapb#
811.30Sapb# Exceptions to flist checking (all begin with "./"):
821.30Sapb#
831.30Sapb# * ignore var/db/syspkg and its contents
841.34Sapb# * ignore METALOG and METALOG.*
851.30Sapb# * ignore etc/mtree/set.*
861.30Sapb#
871.36Suebayasiignore_exceptions()
881.36Suebayasi{
891.30SapbIGNORE_REGEXP="^\./var/db/syspkg(\$|/)"
901.34SapbIGNORE_REGEXP="${IGNORE_REGEXP}|^\./METALOG(\..*)?\$"
911.34SapbIGNORE_REGEXP="${IGNORE_REGEXP}|^\./etc/mtree/set\.[a-z]*\$"
921.36Suebayasi	${EGREP} -v -e "${IGNORE_REGEXP}"
931.36Suebayasi}
941.15Slukem
951.30Sapb#
961.30Sapb# Here would be a good place to add custom exceptions to flist checking.
971.30Sapb#
981.15Slukem
991.30Sapb#
1001.30Sapb# Make three lists:
1011.30Sapb# * ${SDIR}/files: files present in DESTDIR.
1021.30Sapb# * ${SDIR}/flist: files mentioned in flist;
1031.30Sapb# * ${SDIR}/mlist: files mentioned in metalog;
1041.30Sapb#
1051.34Sapb# All three lists are filtered against ${IGNORE_REGEXP}.
1061.34Sapb#
1071.36Suebayasi
1081.36Suebayasigenerate_files()
1091.36Suebayasi{
1101.30Sapb( cd "${DESTDIR}" && ${FIND} ${origin} \
1111.30Sapb	\( -type d -o -type f -o -type l \) -print ) \
1121.36Suebayasi	| ${SORT} -u | ignore_exceptions >"${SDIR}/files"
1131.36Suebayasi}
1141.36Suebayasi
1151.36Suebayasigenerate_flist()
1161.36Suebayasi{
1171.30Sapb${HOST_SH} "${rundir}/makeflist" ${xargs} ${dargs} \
1181.36Suebayasi	| ${SORT} -u | ignore_exceptions >"${SDIR}/flist"
1191.36Suebayasi}
1201.36Suebayasi
1211.36Suebayasigenerate_mlist()
1221.36Suebayasi{
1231.30Sapbif [ -n "${metalog}" ]; then
1241.30Sapb	${AWK} '{print $1}' <"${metalog}" \
1251.36Suebayasi	| ${SORT} -u | ignore_exceptions >"${SDIR}/mlist"
1261.30Sapbfi
1271.36Suebayasi}
1281.36Suebayasi
1291.36Suebayasigenerate_missing()
1301.36Suebayasi{
1311.36Suebayasi	${COMM} -23 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/missing"
1321.36Suebayasi}
1331.36Suebayasi
1341.36Suebayasigenerate_extra()
1351.36Suebayasi{
1361.36Suebayasi	${COMM} -13 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/extra"
1371.36Suebayasi}
1381.36Suebayasi
1391.36Suebayasigenerate_files
1401.36Suebayasigenerate_flist
1411.36Suebayasigenerate_mlist
1421.10Sperry
1431.30Sapb#
1441.30Sapb# compare DESTDIR with METALOG, and report on differences.
1451.30Sapb#
1461.31Sapb# XXX: Temporarily disabled due to problems with obsolete files in metalog
1471.31Sapb#
1481.31Sapbif false && [ -n "${metalog}" ]; then
1491.36Suebayasi    generate_missing
1501.36Suebayasi    generate_extra
1511.15Slukem
1521.33Sdbj    # Handle case insensitive filesystems
1531.33Sdbj    mv -f "${SDIR}/extra" "${SDIR}/extra.all"
1541.33Sdbj    while read f; do
1551.33Sdbj	[ -f "${DESTDIR}/${f}" ] || \
1561.33Sdbj	    [ -d "${DESTDIR}/${f}" ] || \
1571.33Sdbj	    [ -L "${DESTDIR}/${f}" ] || echo "$f"
1581.33Sdbj    done < "${SDIR}/extra.all" > "${SDIR}/extra"
1591.33Sdbj
1601.30Sapb    if [ -s "${SDIR}/extra" ]; then
1611.30Sapb	count="$(${AWK} 'END {print NR}' "${SDIR}/extra")"
1621.30Sapb	echo ""
1631.30Sapb	echo "=======  ${count} extra files in METALOG  ========="
1641.30Sapb	echo "Files in METALOG but missing from DESTDIR."
1651.30Sapb	echo "File was deleted after installation ?"
1661.30Sapb	echo "------------------------------------------"
1671.30Sapb	cat "${SDIR}/extra"
1681.30Sapb	echo "=========  end of ${count} extra files  ==========="
1691.30Sapb	echo ""
1701.30Sapb	es=1 # this is fatal even if ${allowextra} is true
1711.30Sapb    fi
1721.30Sapb
1731.30Sapb    if [ -s "${SDIR}/missing" ]; then
1741.30Sapb	count="$(${AWK} 'END {print NR}' "${SDIR}/missing")"
1751.30Sapb	echo ""
1761.30Sapb	echo "======  ${count} missing files in METALOG  ========"
1771.30Sapb	echo "Files in DESTDIR but missing from METALOG."
1781.30Sapb	echo "File installed but not registered in METALOG ?"
1791.30Sapb	echo "------------------------------------------"
1801.30Sapb	cat "${SDIR}/missing"
1811.30Sapb	echo "========  end of ${count} missing files  =========="
1821.30Sapb	echo ""
1831.30Sapb	es=1 # this is fatal even if ${allowmissing} is true
1841.30Sapb    fi
1851.30Sapbfi
1861.30Sapb
1871.30Sapb#
1881.30Sapb# compare flist with DESTDIR, and report on differences.
1891.30Sapb#
1901.36Suebayasigenerate_missing
1911.36Suebayasigenerate_extra
1921.15Slukem
1931.33Sdbj# Handle case insensitive filesystems
1941.33Sdbjmv -f "${SDIR}/missing" "${SDIR}/missing.all"
1951.33Sdbjwhile read f; do
1961.33Sdbj    [ -f "${DESTDIR}/${f}" ] || \
1971.33Sdbj	[ -d "${DESTDIR}/${f}" ] || \
1981.33Sdbj	[ -L "${DESTDIR}/${f}" ] || echo "$f"
1991.33Sdbjdone < "${SDIR}/missing.all" > "${SDIR}/missing"
2001.33Sdbj
2011.29Sapbif [ -s "${SDIR}/extra" ]; then
2021.29Sapb	count="$(${AWK} 'END {print NR}' "${SDIR}/extra")"
2031.20Slukem	echo ""
2041.30Sapb	echo "=======  ${count} extra files in DESTDIR  ========="
2051.20Slukem	echo "Files in DESTDIR but missing from flist."
2061.20Slukem	echo "File is obsolete or flist is out of date ?"
2071.22Slukem	if ${allowextra}; then
2081.30Sapb		echo "This is non-fatal, due to '-e' option."
2091.22Slukem	else
2101.22Slukem		es=1
2111.22Slukem	fi
2121.20Slukem	echo "------------------------------------------"
2131.29Sapb	cat "${SDIR}/extra"
2141.25Slukem	echo "=========  end of ${count} extra files  ==========="
2151.20Slukem	echo ""
2161.20Slukemfi
2171.20Slukem
2181.29Sapbif [ -s "${SDIR}/missing" ]; then
2191.29Sapb	count="$(${AWK} 'END {print NR}' "${SDIR}/missing")"
2201.20Slukem	echo ""
2211.30Sapb	echo "======  ${count} missing files in DESTDIR  ========"
2221.20Slukem	echo "Files in flist but missing from DESTDIR."
2231.20Slukem	echo "File wasn't installed ?"
2241.22Slukem	if ${allowmissing}; then
2251.30Sapb		echo "This is non-fatal, due to '-m' option."
2261.22Slukem	else
2271.22Slukem		es=1
2281.22Slukem	fi
2291.20Slukem	echo "------------------------------------------"
2301.29Sapb	cat "${SDIR}/missing"
2311.25Slukem	echo "========  end of ${count} missing files  =========="
2321.20Slukem	echo ""
2331.15Slukemfi
2341.20Slukem
2351.29Sapbexit 0		# cleanup will exit with ${es}
236