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 7if [ -z "${DESTDIR}" ]; then 8 echo "DESTDIR must be set" 9 exit 1 10fi 11 12prog="${0##*/}" 13rundir="$(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# 21SETS_DLIST="${DESTDIR}/SETS.dlist" 22SETS_FLIST="${DESTDIR}/SETS.flist" 23SETS_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# 31SETS_METALOG_EXTRA="${DESTDIR}/SETS.metalog.extra" 32SETS_METALOG_MISSING="${DESTDIR}/SETS.metalog.missing" 33SETS_DESTDIR_EXTRA="${DESTDIR}/SETS.destdir.extra" 34SETS_DESTDIR_MISSING="${DESTDIR}/SETS.destdir.missing" 35 36es=0 37cleanup() 38{ 39 if [ ${es} -gt 255 ]; then 40 es=255 41 fi 42 exit ${es} 43} 44trap cleanup 0 2 3 13 # EXIT INT QUIT PIPE 45 46origin=. 47xargs="" 48dargs="" 49metalog= 50allowextra=false 51allowmissing=false 52 53# handle args 54while 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 82Usage: ${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 90USAGE 91 exit 1 92 ;; 93 esac 94done 95shift $((${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# 104ignore_exceptions() 105{ 106IGNORE_REGEXP_SYSPKG="^\./var/db/syspkg(\$|/)" 107IGNORE_REGEXP_METALOG="^\./METALOG(\..*)?\$" 108IGNORE_REGEXP_SETS="^\./SETS\..*\$" 109IGNORE_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 128generate_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 135generate_flist() 136{ 137${HOST_SH} "${rundir}/makeflist" ${xargs} ${dargs} \ 138 | ${SORT} -u | ignore_exceptions >"${SETS_FLIST}" 139} 140 141generate_mlist() 142{ 143if [ -n "${metalog}" ]; then 144 ${AWK} '{print $1}' <"${metalog}" \ 145 | ${SORT} -u | ignore_exceptions >"${SETS_MLIST}" 146fi 147} 148 149generate_mlist_missing() 150{ 151 ${COMM} -23 "${SETS_DLIST}" "${SETS_MLIST}" > "${SETS_METALOG_MISSING}" 152} 153 154generate_mlist_extra() 155{ 156 ${COMM} -13 "${SETS_DLIST}" "${SETS_MLIST}" > "${SETS_METALOG_EXTRA}" 157} 158 159generate_dlist_missing() 160{ 161 ${COMM} -23 "${SETS_FLIST}" "${SETS_DLIST}" > "${SETS_DESTDIR_MISSING}" 162} 163 164generate_dlist_extra() 165{ 166 ${COMM} -13 "${SETS_FLIST}" "${SETS_DLIST}" > "${SETS_DESTDIR_EXTRA}" 167} 168 169exist_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# 182compare_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 193check_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 209check_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# 228compare_destdir() 229{ 230# Handle case insensitive filesystems 231mv -f "${SETS_DESTDIR_MISSING}" "${SETS_DESTDIR_MISSING}.all" 232exist_case_insensitive < "${SETS_DESTDIR_MISSING}.all" > "${SETS_DESTDIR_MISSING}" 233rm -f "${SETS_DESTDIR_MISSING}.all" 234 235check_destdir_extra 236check_destdir_missing 237} 238 239check_destdir_extra() 240{ 241if [ -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 "" 256fi 257} 258 259check_destdir_missing() 260{ 261if [ -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 "" 276fi 277} 278 279generate_dlist 280generate_flist 281generate_mlist 282 283generate_mlist_missing 284generate_mlist_extra 285 286generate_dlist_missing 287generate_dlist_extra 288 289if false && [ -n "${metalog}" ]; then 290 # XXX: Temporarily disabled due to problems with obsolete files in metalog 291 compare_metalog 292else 293 compare_destdir 294fi 295 296exit 0 # cleanup will exit with ${es} 297