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