Home | History | Annotate | Line # | Download | only in sets
checkflist revision 1.42.6.2
      1       1.3     mikel #! /bin/sh --
      2       1.3     mikel #
      3  1.42.6.2      yamt #	$NetBSD: checkflist,v 1.42.6.2 2014/05/22 12:01:31 yamt Exp $
      4       1.3     mikel #
      5      1.30       apb # Verify output of makeflist against contents of ${DESTDIR} and ${metalog}.
      6       1.1       cgd 
      7      1.29       apb if [ -z "${DESTDIR}" ]; then
      8      1.15     lukem 	echo "DESTDIR must be set"
      9       1.1       cgd 	exit 1
     10      1.15     lukem fi
     11      1.15     lukem 
     12      1.29       apb prog="${0##*/}"
     13      1.27       apb rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
     14      1.27       apb . "${rundir}/sets.subr"
     15       1.1       cgd 
     16      1.42  uebayasi #
     17      1.42  uebayasi # * ${SETS_DLIST}: files present in DESTDIR.
     18      1.42  uebayasi # * ${SETS_FLIST}: files mentioned in flist;
     19      1.42  uebayasi # * ${SETS_MLIST}: files mentioned in metalog;
     20      1.42  uebayasi #
     21      1.42  uebayasi SETS_DLIST="${DESTDIR}/SETS.dlist"
     22      1.42  uebayasi SETS_FLIST="${DESTDIR}/SETS.flist"
     23      1.42  uebayasi SETS_MLIST="${DESTDIR}/SETS.mlist"
     24      1.42  uebayasi 
     25      1.42  uebayasi #
     26      1.42  uebayasi # * ${SETS_METALOG_EXTRA}: Files in METALOG but missing from DESTDIR."
     27      1.42  uebayasi # * ${SETS_METALOG_MISSING}: Files in DESTDIR but missing from METALOG."
     28      1.42  uebayasi # * ${SETS_DESTDIR_EXTRA}: Files in DESTDIR but missing from setlist."
     29      1.42  uebayasi # * ${SETS_DESTDIR_MISSING}: Files in setlist but missing from DESTDIR."
     30      1.42  uebayasi #
     31      1.42  uebayasi SETS_METALOG_EXTRA="${DESTDIR}/SETS.metalog.extra"
     32      1.42  uebayasi SETS_METALOG_MISSING="${DESTDIR}/SETS.metalog.missing"
     33      1.42  uebayasi SETS_DESTDIR_EXTRA="${DESTDIR}/SETS.destdir.extra"
     34      1.42  uebayasi SETS_DESTDIR_MISSING="${DESTDIR}/SETS.destdir.missing"
     35      1.20     lukem 
     36      1.20     lukem es=0
     37      1.20     lukem cleanup()
     38      1.20     lukem {
     39      1.32       apb 	if [ ${es} -gt 255 ]; then
     40      1.20     lukem 		es=255
     41      1.20     lukem 	fi
     42      1.29       apb 	exit ${es}
     43      1.20     lukem }
     44      1.20     lukem trap cleanup 0 2 3 13		# EXIT INT QUIT PIPE
     45      1.20     lukem 
     46       1.9      ross origin=.
     47      1.10     perry xargs=""
     48      1.10     perry dargs=""
     49      1.15     lukem metalog=
     50      1.22     lukem allowextra=false
     51      1.22     lukem allowmissing=false
     52      1.10     perry 
     53      1.10     perry # handle args
     54      1.35  uebayasi while getopts xybL:M:em ch; do
     55      1.24     lukem 	case ${ch} in
     56      1.24     lukem 	x)
     57      1.10     perry 		xargs="-x"
     58  1.42.6.2      yamt 		origin="./etc/X11 ./etc/fonts ./usr/X11R6 ./usr/X11R7"
     59      1.10     perry 		;;
     60      1.35  uebayasi 	y)
     61      1.35  uebayasi 		xargs="-y"
     62      1.35  uebayasi 		origin="./etc/ext ./usr/ext"
     63      1.35  uebayasi 		;;
     64      1.35  uebayasi 	# backward compat
     65      1.24     lukem 	b)
     66      1.10     perry 		xargs="-b"
     67      1.10     perry 		;;
     68      1.35  uebayasi 	L)
     69      1.35  uebayasi 		xargs="-L ${OPTARG}"
     70      1.35  uebayasi 		;;
     71      1.24     lukem 	M)
     72      1.29       apb 		metalog="${OPTARG}"
     73      1.15     lukem 		;;
     74      1.24     lukem 	e)
     75      1.22     lukem 		allowextra=true
     76      1.22     lukem 		;;
     77      1.24     lukem 	m)
     78      1.22     lukem 		allowmissing=true
     79      1.22     lukem 		;;
     80      1.24     lukem 	*)
     81      1.10     perry 		cat 1>&2 <<USAGE
     82      1.35  uebayasi Usage: ${prog} [-x|-y|-b|-L lists] [-M metalog] [-e] [-m]
     83      1.24     lukem 	-x		check only x11 lists
     84      1.35  uebayasi 	-y		check only extsrc lists
     85      1.24     lukem 	-b		check netbsd + x11 lists
     86      1.35  uebayasi 	-L base,x,ext	check specified lists
     87      1.15     lukem 	-M metalog	metalog file
     88      1.22     lukem 	-e		extra files are not considered an error
     89      1.22     lukem 	-m		missing files are not considered an error
     90      1.10     perry USAGE
     91      1.10     perry 		exit 1
     92      1.10     perry 		;;
     93      1.10     perry 	esac
     94      1.10     perry done
     95      1.24     lukem shift $((${OPTIND} - 1))
     96      1.10     perry 
     97      1.30       apb #
     98      1.30       apb # Exceptions to flist checking (all begin with "./"):
     99      1.30       apb #
    100      1.30       apb # * ignore var/db/syspkg and its contents
    101      1.34       apb # * ignore METALOG and METALOG.*
    102      1.30       apb # * ignore etc/mtree/set.*
    103      1.30       apb #
    104      1.36  uebayasi ignore_exceptions()
    105      1.36  uebayasi {
    106      1.40  uebayasi IGNORE_REGEXP_SYSPKG="^\./var/db/syspkg(\$|/)"
    107      1.40  uebayasi IGNORE_REGEXP_METALOG="^\./METALOG(\..*)?\$"
    108      1.42  uebayasi IGNORE_REGEXP_SETS="^\./SETS\..*\$"
    109      1.40  uebayasi IGNORE_REGEXP_MTREE="^\./etc/mtree/set\.[a-z]*\$"
    110      1.40  uebayasi 
    111      1.40  uebayasi 	${EGREP} -v \
    112      1.40  uebayasi 		-e "${IGNORE_REGEXP_SYSPKG}" \
    113      1.40  uebayasi 		-e "${IGNORE_REGEXP_METALOG}" \
    114      1.42  uebayasi 		-e "${IGNORE_REGEXP_SETS}" \
    115      1.40  uebayasi 		-e "${IGNORE_REGEXP_MTREE}"
    116      1.36  uebayasi }
    117      1.15     lukem 
    118      1.30       apb #
    119      1.30       apb # Here would be a good place to add custom exceptions to flist checking.
    120      1.30       apb #
    121      1.15     lukem 
    122      1.30       apb #
    123      1.30       apb # Make three lists:
    124      1.30       apb #
    125      1.34       apb # All three lists are filtered against ${IGNORE_REGEXP}.
    126      1.34       apb #
    127      1.36  uebayasi 
    128      1.42  uebayasi generate_dlist()
    129      1.36  uebayasi {
    130      1.30       apb ( cd "${DESTDIR}" && ${FIND} ${origin} \
    131      1.30       apb 	\( -type d -o -type f -o -type l \) -print ) \
    132      1.42  uebayasi 	| ${SORT} -u | ignore_exceptions >"${SETS_DLIST}"
    133      1.36  uebayasi }
    134      1.36  uebayasi 
    135      1.36  uebayasi generate_flist()
    136      1.36  uebayasi {
    137      1.30       apb ${HOST_SH} "${rundir}/makeflist" ${xargs} ${dargs} \
    138      1.42  uebayasi 	| ${SORT} -u | ignore_exceptions >"${SETS_FLIST}"
    139      1.36  uebayasi }
    140      1.36  uebayasi 
    141      1.36  uebayasi generate_mlist()
    142      1.36  uebayasi {
    143      1.30       apb if [ -n "${metalog}" ]; then
    144      1.30       apb 	${AWK} '{print $1}' <"${metalog}" \
    145      1.42  uebayasi 	| ${SORT} -u | ignore_exceptions >"${SETS_MLIST}"
    146  1.42.6.1      yamt else
    147  1.42.6.1      yamt 	SETS_MLIST=/dev/null
    148      1.30       apb fi
    149      1.36  uebayasi }
    150      1.36  uebayasi 
    151      1.41  uebayasi generate_mlist_missing()
    152      1.36  uebayasi {
    153      1.42  uebayasi 	${COMM} -23 "${SETS_DLIST}" "${SETS_MLIST}" > "${SETS_METALOG_MISSING}"
    154      1.36  uebayasi }
    155      1.36  uebayasi 
    156      1.41  uebayasi generate_mlist_extra()
    157      1.36  uebayasi {
    158      1.42  uebayasi 	${COMM} -13 "${SETS_DLIST}" "${SETS_MLIST}" > "${SETS_METALOG_EXTRA}"
    159      1.36  uebayasi }
    160      1.36  uebayasi 
    161      1.42  uebayasi generate_dlist_missing()
    162      1.41  uebayasi {
    163      1.42  uebayasi 	${COMM} -23 "${SETS_FLIST}" "${SETS_DLIST}" > "${SETS_DESTDIR_MISSING}"
    164      1.41  uebayasi }
    165      1.41  uebayasi 
    166      1.42  uebayasi generate_dlist_extra()
    167      1.41  uebayasi {
    168      1.42  uebayasi 	${COMM} -13 "${SETS_FLIST}" "${SETS_DLIST}" > "${SETS_DESTDIR_EXTRA}"
    169      1.41  uebayasi }
    170      1.41  uebayasi 
    171      1.39  uebayasi exist_case_insensitive()
    172      1.39  uebayasi {
    173      1.39  uebayasi 	while read f; do
    174      1.39  uebayasi 		[ -f "${DESTDIR}/${f}" ] || \
    175      1.39  uebayasi 		[ -d "${DESTDIR}/${f}" ] || \
    176      1.39  uebayasi 		[ -L "${DESTDIR}/${f}" ] || \
    177      1.39  uebayasi 		echo "$f"
    178      1.39  uebayasi 	done
    179      1.39  uebayasi }
    180      1.39  uebayasi 
    181      1.30       apb #
    182      1.30       apb # compare DESTDIR with METALOG, and report on differences.
    183      1.30       apb #
    184      1.37  uebayasi compare_metalog()
    185      1.37  uebayasi {
    186      1.33       dbj     # Handle case insensitive filesystems
    187      1.42  uebayasi     mv -f "${SETS_METALOG_EXTRA}" "${SETS_METALOG_EXTRA}.all"
    188      1.42  uebayasi     exist_case_insensitive < "${SETS_METALOG_EXTRA}.all" > "${SETS_METALOG_EXTRA}"
    189      1.42  uebayasi     rm -f "${SETS_METALOG_EXTRA}.all"
    190      1.33       dbj 
    191      1.37  uebayasi     check_metalog_extra
    192      1.37  uebayasi     check_metalog_missing
    193      1.37  uebayasi }
    194      1.37  uebayasi 
    195      1.37  uebayasi check_metalog_extra()
    196      1.37  uebayasi {
    197      1.42  uebayasi     if [ -s "${SETS_METALOG_EXTRA}" ]; then
    198      1.42  uebayasi 	count="$(${AWK} 'END {print NR}' "${SETS_METALOG_EXTRA}")"
    199      1.30       apb 	echo ""
    200      1.30       apb 	echo "=======  ${count} extra files in METALOG  ========="
    201      1.30       apb 	echo "Files in METALOG but missing from DESTDIR."
    202      1.30       apb 	echo "File was deleted after installation ?"
    203      1.30       apb 	echo "------------------------------------------"
    204      1.42  uebayasi 	cat "${SETS_METALOG_EXTRA}"
    205      1.30       apb 	echo "=========  end of ${count} extra files  ==========="
    206      1.30       apb 	echo ""
    207      1.30       apb 	es=1 # this is fatal even if ${allowextra} is true
    208      1.30       apb     fi
    209      1.37  uebayasi }
    210      1.30       apb 
    211      1.37  uebayasi check_metalog_missing()
    212      1.37  uebayasi {
    213      1.42  uebayasi     if [ -s "${SETS_METALOG_MISSING}" ]; then
    214      1.42  uebayasi 	count="$(${AWK} 'END {print NR}' "${SETS_METALOG_MISSING}")"
    215      1.30       apb 	echo ""
    216      1.30       apb 	echo "======  ${count} missing files in METALOG  ========"
    217      1.30       apb 	echo "Files in DESTDIR but missing from METALOG."
    218      1.30       apb 	echo "File installed but not registered in METALOG ?"
    219      1.30       apb 	echo "------------------------------------------"
    220      1.42  uebayasi 	cat "${SETS_METALOG_MISSING}"
    221      1.30       apb 	echo "========  end of ${count} missing files  =========="
    222      1.30       apb 	echo ""
    223      1.30       apb 	es=1 # this is fatal even if ${allowmissing} is true
    224      1.30       apb     fi
    225      1.37  uebayasi }
    226      1.37  uebayasi 
    227      1.30       apb #
    228      1.30       apb # compare flist with DESTDIR, and report on differences.
    229      1.30       apb #
    230      1.37  uebayasi compare_destdir()
    231      1.37  uebayasi {
    232      1.33       dbj # Handle case insensitive filesystems
    233      1.42  uebayasi mv -f "${SETS_DESTDIR_MISSING}" "${SETS_DESTDIR_MISSING}.all"
    234      1.42  uebayasi exist_case_insensitive < "${SETS_DESTDIR_MISSING}.all" > "${SETS_DESTDIR_MISSING}"
    235      1.42  uebayasi rm -f "${SETS_DESTDIR_MISSING}.all"
    236      1.33       dbj 
    237      1.37  uebayasi check_destdir_extra
    238      1.37  uebayasi check_destdir_missing
    239      1.37  uebayasi }
    240      1.37  uebayasi 
    241      1.37  uebayasi check_destdir_extra()
    242      1.37  uebayasi {
    243      1.42  uebayasi if [ -s "${SETS_DESTDIR_EXTRA}" ]; then
    244      1.42  uebayasi 	count="$(${AWK} 'END {print NR}' "${SETS_DESTDIR_EXTRA}")"
    245      1.20     lukem 	echo ""
    246      1.30       apb 	echo "=======  ${count} extra files in DESTDIR  ========="
    247      1.20     lukem 	echo "Files in DESTDIR but missing from flist."
    248      1.20     lukem 	echo "File is obsolete or flist is out of date ?"
    249      1.22     lukem 	if ${allowextra}; then
    250      1.30       apb 		echo "This is non-fatal, due to '-e' option."
    251      1.22     lukem 	else
    252      1.22     lukem 		es=1
    253      1.22     lukem 	fi
    254      1.20     lukem 	echo "------------------------------------------"
    255      1.42  uebayasi 	cat "${SETS_DESTDIR_EXTRA}"
    256      1.25     lukem 	echo "=========  end of ${count} extra files  ==========="
    257      1.20     lukem 	echo ""
    258      1.20     lukem fi
    259      1.37  uebayasi }
    260      1.20     lukem 
    261      1.37  uebayasi check_destdir_missing()
    262      1.37  uebayasi {
    263      1.42  uebayasi if [ -s "${SETS_DESTDIR_MISSING}" ]; then
    264      1.42  uebayasi 	count="$(${AWK} 'END {print NR}' "${SETS_DESTDIR_MISSING}")"
    265      1.20     lukem 	echo ""
    266      1.30       apb 	echo "======  ${count} missing files in DESTDIR  ========"
    267      1.20     lukem 	echo "Files in flist but missing from DESTDIR."
    268      1.20     lukem 	echo "File wasn't installed ?"
    269      1.22     lukem 	if ${allowmissing}; then
    270      1.30       apb 		echo "This is non-fatal, due to '-m' option."
    271      1.22     lukem 	else
    272      1.22     lukem 		es=1
    273      1.22     lukem 	fi
    274      1.20     lukem 	echo "------------------------------------------"
    275      1.42  uebayasi 	cat "${SETS_DESTDIR_MISSING}"
    276      1.25     lukem 	echo "========  end of ${count} missing files  =========="
    277      1.20     lukem 	echo ""
    278      1.15     lukem fi
    279      1.37  uebayasi }
    280      1.37  uebayasi 
    281      1.42  uebayasi generate_dlist
    282      1.38  uebayasi generate_flist
    283      1.38  uebayasi generate_mlist
    284      1.38  uebayasi 
    285      1.42  uebayasi generate_mlist_missing
    286      1.42  uebayasi generate_mlist_extra
    287      1.42  uebayasi 
    288      1.42  uebayasi generate_dlist_missing
    289      1.42  uebayasi generate_dlist_extra
    290      1.42  uebayasi 
    291      1.39  uebayasi if false && [ -n "${metalog}" ]; then
    292      1.41  uebayasi 	# XXX: Temporarily disabled due to problems with obsolete files in metalog
    293      1.39  uebayasi 	compare_metalog
    294      1.41  uebayasi else
    295      1.41  uebayasi 	compare_destdir
    296      1.39  uebayasi fi
    297      1.20     lukem 
    298      1.29       apb exit 0		# cleanup will exit with ${es}
    299