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