199 lines
5.0 KiB
Bash
Executable File
199 lines
5.0 KiB
Bash
Executable File
#! /bin/sh --
|
|
#
|
|
# $NetBSD: checkflist,v 1.33 2006/09/11 22:16:10 dbj Exp $
|
|
#
|
|
# Verify output of makeflist against contents of ${DESTDIR} and ${metalog}.
|
|
|
|
if [ -z "${DESTDIR}" ]; then
|
|
echo "DESTDIR must be set"
|
|
exit 1
|
|
fi
|
|
|
|
prog="${0##*/}"
|
|
rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
|
|
. "${rundir}/sets.subr"
|
|
|
|
SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
|
|
|
|
es=0
|
|
cleanup()
|
|
{
|
|
/bin/rm -rf "${SDIR}"
|
|
if [ ${es} -gt 255 ]; then
|
|
es=255
|
|
fi
|
|
exit ${es}
|
|
}
|
|
trap cleanup 0 2 3 13 # EXIT INT QUIT PIPE
|
|
|
|
origin=.
|
|
xargs=""
|
|
dargs=""
|
|
metalog=
|
|
allowextra=false
|
|
allowmissing=false
|
|
|
|
# handle args
|
|
while getopts xbM:em ch; do
|
|
case ${ch} in
|
|
x)
|
|
xargs="-x"
|
|
origin="./etc/X11 ./etc/fonts ./usr/X11R6"
|
|
;;
|
|
b)
|
|
xargs="-b"
|
|
;;
|
|
M)
|
|
metalog="${OPTARG}"
|
|
;;
|
|
e)
|
|
allowextra=true
|
|
;;
|
|
m)
|
|
allowmissing=true
|
|
;;
|
|
*)
|
|
cat 1>&2 <<USAGE
|
|
Usage: ${prog} [-x|-b] [-M metalog] [-e] [-m]
|
|
-x check only x11 lists
|
|
-b check netbsd + x11 lists
|
|
-M metalog metalog file
|
|
-e extra files are not considered an error
|
|
-m missing files are not considered an error
|
|
USAGE
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
shift $((${OPTIND} - 1))
|
|
|
|
#
|
|
# Exceptions to flist checking (all begin with "./"):
|
|
#
|
|
# * ignore var/db/syspkg and its contents
|
|
# * ignore ${metalog}
|
|
# * ignore METALOG
|
|
# * ignore etc/mtree/set.*
|
|
#
|
|
IGNORE_REGEXP="^\./var/db/syspkg(\$|/)"
|
|
if [ -n "${metalog}" ]; then
|
|
ml="${metalog#${DESTDIR}/}"
|
|
ml2="METALOG"
|
|
IGNORE_REGEXP="${IGNORE_REGEXP}|^\./${ml}\$|^\./${ml2}\$"
|
|
IGNORE_REGEXP="${IGNORE_REGEXP}|^\./etc/mtree/set\.[a-z]*\$"
|
|
fi
|
|
|
|
#
|
|
# Here would be a good place to add custom exceptions to flist checking.
|
|
#
|
|
|
|
#
|
|
# Make three lists:
|
|
# * ${SDIR}/files: files present in DESTDIR.
|
|
# * ${SDIR}/flist: files mentioned in flist;
|
|
# * ${SDIR}/mlist: files mentioned in metalog;
|
|
#
|
|
( cd "${DESTDIR}" && ${FIND} ${origin} \
|
|
\( -type d -o -type f -o -type l \) -print ) \
|
|
| ${SORT} -u | ${EGREP} -v -e "${IGNORE_REGEXP}" >"${SDIR}/files"
|
|
${HOST_SH} "${rundir}/makeflist" ${xargs} ${dargs} \
|
|
| ${SORT} -u | ${EGREP} -v -e "${IGNORE_REGEXP}" >"${SDIR}/flist"
|
|
if [ -n "${metalog}" ]; then
|
|
${AWK} '{print $1}' <"${metalog}" \
|
|
| ${SORT} -u | ${EGREP} -v -e "${IGNORE_REGEXP}" >"${SDIR}/mlist"
|
|
fi
|
|
|
|
#
|
|
# compare DESTDIR with METALOG, and report on differences.
|
|
#
|
|
# XXX: Temporarily disabled due to problems with obsolete files in metalog
|
|
#
|
|
if false && [ -n "${metalog}" ]; then
|
|
${COMM} -23 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/missing"
|
|
${COMM} -13 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/extra"
|
|
|
|
# Handle case insensitive filesystems
|
|
mv -f "${SDIR}/extra" "${SDIR}/extra.all"
|
|
while read f; do
|
|
[ -f "${DESTDIR}/${f}" ] || \
|
|
[ -d "${DESTDIR}/${f}" ] || \
|
|
[ -L "${DESTDIR}/${f}" ] || echo "$f"
|
|
done < "${SDIR}/extra.all" > "${SDIR}/extra"
|
|
|
|
if [ -s "${SDIR}/extra" ]; then
|
|
count="$(${AWK} 'END {print NR}' "${SDIR}/extra")"
|
|
echo ""
|
|
echo "======= ${count} extra files in METALOG ========="
|
|
echo "Files in METALOG but missing from DESTDIR."
|
|
echo "File was deleted after installation ?"
|
|
echo "------------------------------------------"
|
|
cat "${SDIR}/extra"
|
|
echo "========= end of ${count} extra files ==========="
|
|
echo ""
|
|
es=1 # this is fatal even if ${allowextra} is true
|
|
fi
|
|
|
|
if [ -s "${SDIR}/missing" ]; then
|
|
count="$(${AWK} 'END {print NR}' "${SDIR}/missing")"
|
|
echo ""
|
|
echo "====== ${count} missing files in METALOG ========"
|
|
echo "Files in DESTDIR but missing from METALOG."
|
|
echo "File installed but not registered in METALOG ?"
|
|
echo "------------------------------------------"
|
|
cat "${SDIR}/missing"
|
|
echo "======== end of ${count} missing files =========="
|
|
echo ""
|
|
es=1 # this is fatal even if ${allowmissing} is true
|
|
fi
|
|
fi
|
|
|
|
#
|
|
# compare flist with DESTDIR, and report on differences.
|
|
#
|
|
${COMM} -23 "${SDIR}/flist" "${SDIR}/files" > "${SDIR}/missing"
|
|
${COMM} -13 "${SDIR}/flist" "${SDIR}/files" > "${SDIR}/extra"
|
|
|
|
# Handle case insensitive filesystems
|
|
mv -f "${SDIR}/missing" "${SDIR}/missing.all"
|
|
while read f; do
|
|
[ -f "${DESTDIR}/${f}" ] || \
|
|
[ -d "${DESTDIR}/${f}" ] || \
|
|
[ -L "${DESTDIR}/${f}" ] || echo "$f"
|
|
done < "${SDIR}/missing.all" > "${SDIR}/missing"
|
|
|
|
if [ -s "${SDIR}/extra" ]; then
|
|
count="$(${AWK} 'END {print NR}' "${SDIR}/extra")"
|
|
echo ""
|
|
echo "======= ${count} extra files in DESTDIR ========="
|
|
echo "Files in DESTDIR but missing from flist."
|
|
echo "File is obsolete or flist is out of date ?"
|
|
if ${allowextra}; then
|
|
echo "This is non-fatal, due to '-e' option."
|
|
else
|
|
es=1
|
|
fi
|
|
echo "------------------------------------------"
|
|
cat "${SDIR}/extra"
|
|
echo "========= end of ${count} extra files ==========="
|
|
echo ""
|
|
fi
|
|
|
|
if [ -s "${SDIR}/missing" ]; then
|
|
count="$(${AWK} 'END {print NR}' "${SDIR}/missing")"
|
|
echo ""
|
|
echo "====== ${count} missing files in DESTDIR ========"
|
|
echo "Files in flist but missing from DESTDIR."
|
|
echo "File wasn't installed ?"
|
|
if ${allowmissing}; then
|
|
echo "This is non-fatal, due to '-m' option."
|
|
else
|
|
es=1
|
|
fi
|
|
echo "------------------------------------------"
|
|
cat "${SDIR}/missing"
|
|
echo "======== end of ${count} missing files =========="
|
|
echo ""
|
|
fi
|
|
|
|
exit 0 # cleanup will exit with ${es}
|