1 #! /bin/sh -- 2 # 3 # $NetBSD: checkflist,v 1.31 2006/01/06 18:07:56 apb 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 xbM:em ch; do 38 case ${ch} in 39 x) 40 xargs="-x" 41 origin="./etc/X11 ./etc/fonts ./usr/X11R6" 42 ;; 43 b) 44 xargs="-b" 45 ;; 46 M) 47 metalog="${OPTARG}" 48 ;; 49 e) 50 allowextra=true 51 ;; 52 m) 53 allowmissing=true 54 ;; 55 *) 56 cat 1>&2 <<USAGE 57 Usage: ${prog} [-x|-b] [-M metalog] [-e] [-m] 58 -x check only x11 lists 59 -b check netbsd + x11 lists 60 -M metalog metalog file 61 -e extra files are not considered an error 62 -m missing files are not considered an error 63 USAGE 64 exit 1 65 ;; 66 esac 67 done 68 shift $((${OPTIND} - 1)) 69 70 # 71 # Exceptions to flist checking (all begin with "./"): 72 # 73 # * ignore var/db/syspkg and its contents 74 # * ignore ${metalog} 75 # * ignore METALOG 76 # * ignore etc/mtree/set.* 77 # 78 IGNORE_REGEXP="^\./var/db/syspkg(\$|/)" 79 if [ -n "${metalog}" ]; then 80 ml="${metalog#${DESTDIR}/}" 81 ml2="METALOG" 82 IGNORE_REGEXP="${IGNORE_REGEXP}|^\./${ml}\$|^\./${ml2}\$" 83 IGNORE_REGEXP="${IGNORE_REGEXP}|^\./etc/mtree/set\.[a-z]*\$" 84 fi 85 86 # 87 # Here would be a good place to add custom exceptions to flist checking. 88 # 89 90 # 91 # Make three lists: 92 # * ${SDIR}/files: files present in DESTDIR. 93 # * ${SDIR}/flist: files mentioned in flist; 94 # * ${SDIR}/mlist: files mentioned in metalog; 95 # 96 ( cd "${DESTDIR}" && ${FIND} ${origin} \ 97 \( -type d -o -type f -o -type l \) -print ) \ 98 | ${SORT} -u | ${EGREP} -v -e "${IGNORE_REGEXP}" >"${SDIR}/files" 99 ${HOST_SH} "${rundir}/makeflist" ${xargs} ${dargs} \ 100 | ${SORT} -u | ${EGREP} -v -e "${IGNORE_REGEXP}" >"${SDIR}/flist" 101 if [ -n "${metalog}" ]; then 102 ${AWK} '{print $1}' <"${metalog}" \ 103 | ${SORT} -u | ${EGREP} -v -e "${IGNORE_REGEXP}" >"${SDIR}/mlist" 104 fi 105 106 # 107 # compare DESTDIR with METALOG, and report on differences. 108 # 109 # XXX: Temporarily disabled due to problems with obsolete files in metalog 110 # 111 if false && [ -n "${metalog}" ]; then 112 ${COMM} -23 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/missing" 113 ${COMM} -13 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/extra" 114 115 if [ -s "${SDIR}/extra" ]; then 116 count="$(${AWK} 'END {print NR}' "${SDIR}/extra")" 117 echo "" 118 echo "======= ${count} extra files in METALOG =========" 119 echo "Files in METALOG but missing from DESTDIR." 120 echo "File was deleted after installation ?" 121 echo "------------------------------------------" 122 cat "${SDIR}/extra" 123 echo "========= end of ${count} extra files ===========" 124 echo "" 125 es=1 # this is fatal even if ${allowextra} is true 126 fi 127 128 if [ -s "${SDIR}/missing" ]; then 129 count="$(${AWK} 'END {print NR}' "${SDIR}/missing")" 130 echo "" 131 echo "====== ${count} missing files in METALOG ========" 132 echo "Files in DESTDIR but missing from METALOG." 133 echo "File installed but not registered in METALOG ?" 134 echo "------------------------------------------" 135 cat "${SDIR}/missing" 136 echo "======== end of ${count} missing files ==========" 137 echo "" 138 es=1 # this is fatal even if ${allowmissing} is true 139 fi 140 fi 141 142 # 143 # compare flist with DESTDIR, and report on differences. 144 # 145 ${COMM} -23 "${SDIR}/flist" "${SDIR}/files" > "${SDIR}/missing" 146 ${COMM} -13 "${SDIR}/flist" "${SDIR}/files" > "${SDIR}/extra" 147 148 if [ -s "${SDIR}/extra" ]; then 149 count="$(${AWK} 'END {print NR}' "${SDIR}/extra")" 150 echo "" 151 echo "======= ${count} extra files in DESTDIR =========" 152 echo "Files in DESTDIR but missing from flist." 153 echo "File is obsolete or flist is out of date ?" 154 if ${allowextra}; then 155 echo "This is non-fatal, due to '-e' option." 156 else 157 es=1 158 fi 159 echo "------------------------------------------" 160 cat "${SDIR}/extra" 161 echo "========= end of ${count} extra files ===========" 162 echo "" 163 fi 164 165 if [ -s "${SDIR}/missing" ]; then 166 count="$(${AWK} 'END {print NR}' "${SDIR}/missing")" 167 echo "" 168 echo "====== ${count} missing files in DESTDIR ========" 169 echo "Files in flist but missing from DESTDIR." 170 echo "File wasn't installed ?" 171 if ${allowmissing}; then 172 echo "This is non-fatal, due to '-m' option." 173 else 174 es=1 175 fi 176 echo "------------------------------------------" 177 cat "${SDIR}/missing" 178 echo "======== end of ${count} missing files ==========" 179 echo "" 180 fi 181 182 exit 0 # cleanup will exit with ${es} 183