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