1#! /bin/sh -- 2# 3# $NetBSD: checkflist,v 1.45 2018/03/01 07:18:39 snj 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/X11R7" 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}" 146else 147 SETS_MLIST=/dev/null 148fi 149} 150 151generate_mlist_missing() 152{ 153 ${COMM} -23 "${SETS_DLIST}" "${SETS_MLIST}" > "${SETS_METALOG_MISSING}" 154} 155 156generate_mlist_extra() 157{ 158 ${COMM} -13 "${SETS_DLIST}" "${SETS_MLIST}" > "${SETS_METALOG_EXTRA}" 159} 160 161generate_dlist_missing() 162{ 163 ${COMM} -23 "${SETS_FLIST}" "${SETS_DLIST}" > "${SETS_DESTDIR_MISSING}" 164} 165 166generate_dlist_extra() 167{ 168 ${COMM} -13 "${SETS_FLIST}" "${SETS_DLIST}" > "${SETS_DESTDIR_EXTRA}" 169} 170 171exist_case_insensitive() 172{ 173 while read f; do 174 [ -f "${DESTDIR}/${f}" ] || \ 175 [ -d "${DESTDIR}/${f}" ] || \ 176 [ -L "${DESTDIR}/${f}" ] || \ 177 echo "$f" 178 done 179} 180 181# 182# compare DESTDIR with METALOG, and report on differences. 183# 184compare_metalog() 185{ 186 # Handle case insensitive filesystems 187 mv -f "${SETS_METALOG_EXTRA}" "${SETS_METALOG_EXTRA}.all" 188 exist_case_insensitive < "${SETS_METALOG_EXTRA}.all" > "${SETS_METALOG_EXTRA}" 189 rm -f "${SETS_METALOG_EXTRA}.all" 190 191 check_metalog_extra 192 check_metalog_missing 193} 194 195check_metalog_extra() 196{ 197 if [ -s "${SETS_METALOG_EXTRA}" ]; then 198 count="$(${AWK} 'END {print NR}' "${SETS_METALOG_EXTRA}")" 199 echo "" 200 echo "======= ${count} extra files in METALOG =========" 201 echo "Files in METALOG but missing from DESTDIR." 202 echo "File was deleted after installation ?" 203 echo "------------------------------------------" 204 cat "${SETS_METALOG_EXTRA}" 205 echo "========= end of ${count} extra files ===========" 206 echo "" 207 es=1 # this is fatal even if ${allowextra} is true 208 fi 209} 210 211check_metalog_missing() 212{ 213 if [ -s "${SETS_METALOG_MISSING}" ]; then 214 count="$(${AWK} 'END {print NR}' "${SETS_METALOG_MISSING}")" 215 echo "" 216 echo "====== ${count} missing files in METALOG ========" 217 echo "Files in DESTDIR but missing from METALOG." 218 echo "File installed but not registered in METALOG ?" 219 echo "------------------------------------------" 220 cat "${SETS_METALOG_MISSING}" 221 echo "======== end of ${count} missing files ==========" 222 echo "" 223 es=1 # this is fatal even if ${allowmissing} is true 224 fi 225} 226 227# 228# compare flist with DESTDIR, and report on differences. 229# 230compare_destdir() 231{ 232# Handle case insensitive filesystems 233mv -f "${SETS_DESTDIR_MISSING}" "${SETS_DESTDIR_MISSING}.all" 234exist_case_insensitive < "${SETS_DESTDIR_MISSING}.all" > "${SETS_DESTDIR_MISSING}" 235rm -f "${SETS_DESTDIR_MISSING}.all" 236 237check_destdir_extra 238check_destdir_missing 239} 240 241check_destdir_extra() 242{ 243if [ -s "${SETS_DESTDIR_EXTRA}" ]; then 244 count="$(${AWK} 'END {print NR}' "${SETS_DESTDIR_EXTRA}")" 245 echo "" 246 echo "======= ${count} extra files in DESTDIR =========" 247 echo "Files in DESTDIR but missing from flist." 248 echo "File is obsolete or flist is out of date ?" 249 if ${allowextra}; then 250 echo "This is non-fatal, due to '-e' option." 251 else 252 es=1 253 fi 254 echo "------------------------------------------" 255 cat "${SETS_DESTDIR_EXTRA}" 256 echo "========= end of ${count} extra files ===========" 257 echo "" 258fi 259} 260 261check_destdir_missing() 262{ 263if [ -s "${SETS_DESTDIR_MISSING}" ]; then 264 count="$(${AWK} 'END {print NR}' "${SETS_DESTDIR_MISSING}")" 265 echo "" 266 echo "====== ${count} missing files in DESTDIR ========" 267 echo "Files in flist but missing from DESTDIR." 268 echo "File wasn't installed ?" 269 if ${allowmissing}; then 270 echo "This is non-fatal, due to '-m' option." 271 else 272 es=1 273 fi 274 echo "------------------------------------------" 275 cat "${SETS_DESTDIR_MISSING}" 276 echo "======== end of ${count} missing files ==========" 277 echo "" 278fi 279} 280 281generate_dlist 282generate_flist 283generate_mlist 284 285generate_mlist_missing 286generate_mlist_extra 287 288generate_dlist_missing 289generate_dlist_extra 290 291if false && [ -n "${metalog}" ]; then 292 # XXX: Temporarily disabled due to problems with obsolete files in metalog 293 compare_metalog 294else 295 compare_destdir 296fi 297 298exit 0 # cleanup will exit with ${es} 299