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