1 #! /bin/sh -- 2 # 3 # $NetBSD: checkflist,v 1.30 2006/01/04 15:08:42 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 if [ -n "${metalog}" ]; then 110 ${COMM} -23 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/missing" 111 ${COMM} -13 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/extra" 112 113 if [ -s "${SDIR}/extra" ]; then 114 count="$(${AWK} 'END {print NR}' "${SDIR}/extra")" 115 echo "" 116 echo "======= ${count} extra files in METALOG =========" 117 echo "Files in METALOG but missing from DESTDIR." 118 echo "File was deleted after installation ?" 119 echo "------------------------------------------" 120 cat "${SDIR}/extra" 121 echo "========= end of ${count} extra files ===========" 122 echo "" 123 es=1 # this is fatal even if ${allowextra} is true 124 fi 125 126 if [ -s "${SDIR}/missing" ]; then 127 count="$(${AWK} 'END {print NR}' "${SDIR}/missing")" 128 echo "" 129 echo "====== ${count} missing files in METALOG ========" 130 echo "Files in DESTDIR but missing from METALOG." 131 echo "File installed but not registered in METALOG ?" 132 echo "------------------------------------------" 133 cat "${SDIR}/missing" 134 echo "======== end of ${count} missing files ==========" 135 echo "" 136 es=1 # this is fatal even if ${allowmissing} is true 137 fi 138 fi 139 140 # 141 # compare flist with DESTDIR, and report on differences. 142 # 143 ${COMM} -23 "${SDIR}/flist" "${SDIR}/files" > "${SDIR}/missing" 144 ${COMM} -13 "${SDIR}/flist" "${SDIR}/files" > "${SDIR}/extra" 145 146 if [ -s "${SDIR}/extra" ]; then 147 count="$(${AWK} 'END {print NR}' "${SDIR}/extra")" 148 echo "" 149 echo "======= ${count} extra files in DESTDIR =========" 150 echo "Files in DESTDIR but missing from flist." 151 echo "File is obsolete or flist is out of date ?" 152 if ${allowextra}; then 153 echo "This is non-fatal, due to '-e' option." 154 else 155 es=1 156 fi 157 echo "------------------------------------------" 158 cat "${SDIR}/extra" 159 echo "========= end of ${count} extra files ===========" 160 echo "" 161 fi 162 163 if [ -s "${SDIR}/missing" ]; then 164 count="$(${AWK} 'END {print NR}' "${SDIR}/missing")" 165 echo "" 166 echo "====== ${count} missing files in DESTDIR ========" 167 echo "Files in flist but missing from DESTDIR." 168 echo "File wasn't installed ?" 169 if ${allowmissing}; then 170 echo "This is non-fatal, due to '-m' option." 171 else 172 es=1 173 fi 174 echo "------------------------------------------" 175 cat "${SDIR}/missing" 176 echo "======== end of ${count} missing files ==========" 177 echo "" 178 fi 179 180 exit 0 # cleanup will exit with ${es} 181