1 #! /bin/sh -- 2 # 3 # $NetBSD: checkflist,v 1.36 2009/12/10 16:01:06 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_exceptions() 88 { 89 IGNORE_REGEXP="^\./var/db/syspkg(\$|/)" 90 IGNORE_REGEXP="${IGNORE_REGEXP}|^\./METALOG(\..*)?\$" 91 IGNORE_REGEXP="${IGNORE_REGEXP}|^\./etc/mtree/set\.[a-z]*\$" 92 ${EGREP} -v -e "${IGNORE_REGEXP}" 93 } 94 95 # 96 # Here would be a good place to add custom exceptions to flist checking. 97 # 98 99 # 100 # Make three lists: 101 # * ${SDIR}/files: files present in DESTDIR. 102 # * ${SDIR}/flist: files mentioned in flist; 103 # * ${SDIR}/mlist: files mentioned in metalog; 104 # 105 # All three lists are filtered against ${IGNORE_REGEXP}. 106 # 107 108 generate_files() 109 { 110 ( cd "${DESTDIR}" && ${FIND} ${origin} \ 111 \( -type d -o -type f -o -type l \) -print ) \ 112 | ${SORT} -u | ignore_exceptions >"${SDIR}/files" 113 } 114 115 generate_flist() 116 { 117 ${HOST_SH} "${rundir}/makeflist" ${xargs} ${dargs} \ 118 | ${SORT} -u | ignore_exceptions >"${SDIR}/flist" 119 } 120 121 generate_mlist() 122 { 123 if [ -n "${metalog}" ]; then 124 ${AWK} '{print $1}' <"${metalog}" \ 125 | ${SORT} -u | ignore_exceptions >"${SDIR}/mlist" 126 fi 127 } 128 129 generate_missing() 130 { 131 ${COMM} -23 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/missing" 132 } 133 134 generate_extra() 135 { 136 ${COMM} -13 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/extra" 137 } 138 139 generate_files 140 generate_flist 141 generate_mlist 142 143 # 144 # compare DESTDIR with METALOG, and report on differences. 145 # 146 # XXX: Temporarily disabled due to problems with obsolete files in metalog 147 # 148 if false && [ -n "${metalog}" ]; then 149 generate_missing 150 generate_extra 151 152 # Handle case insensitive filesystems 153 mv -f "${SDIR}/extra" "${SDIR}/extra.all" 154 while read f; do 155 [ -f "${DESTDIR}/${f}" ] || \ 156 [ -d "${DESTDIR}/${f}" ] || \ 157 [ -L "${DESTDIR}/${f}" ] || echo "$f" 158 done < "${SDIR}/extra.all" > "${SDIR}/extra" 159 160 if [ -s "${SDIR}/extra" ]; then 161 count="$(${AWK} 'END {print NR}' "${SDIR}/extra")" 162 echo "" 163 echo "======= ${count} extra files in METALOG =========" 164 echo "Files in METALOG but missing from DESTDIR." 165 echo "File was deleted after installation ?" 166 echo "------------------------------------------" 167 cat "${SDIR}/extra" 168 echo "========= end of ${count} extra files ===========" 169 echo "" 170 es=1 # this is fatal even if ${allowextra} is true 171 fi 172 173 if [ -s "${SDIR}/missing" ]; then 174 count="$(${AWK} 'END {print NR}' "${SDIR}/missing")" 175 echo "" 176 echo "====== ${count} missing files in METALOG ========" 177 echo "Files in DESTDIR but missing from METALOG." 178 echo "File installed but not registered in METALOG ?" 179 echo "------------------------------------------" 180 cat "${SDIR}/missing" 181 echo "======== end of ${count} missing files ==========" 182 echo "" 183 es=1 # this is fatal even if ${allowmissing} is true 184 fi 185 fi 186 187 # 188 # compare flist with DESTDIR, and report on differences. 189 # 190 generate_missing 191 generate_extra 192 193 # Handle case insensitive filesystems 194 mv -f "${SDIR}/missing" "${SDIR}/missing.all" 195 while read f; do 196 [ -f "${DESTDIR}/${f}" ] || \ 197 [ -d "${DESTDIR}/${f}" ] || \ 198 [ -L "${DESTDIR}/${f}" ] || echo "$f" 199 done < "${SDIR}/missing.all" > "${SDIR}/missing" 200 201 if [ -s "${SDIR}/extra" ]; then 202 count="$(${AWK} 'END {print NR}' "${SDIR}/extra")" 203 echo "" 204 echo "======= ${count} extra files in DESTDIR =========" 205 echo "Files in DESTDIR but missing from flist." 206 echo "File is obsolete or flist is out of date ?" 207 if ${allowextra}; then 208 echo "This is non-fatal, due to '-e' option." 209 else 210 es=1 211 fi 212 echo "------------------------------------------" 213 cat "${SDIR}/extra" 214 echo "========= end of ${count} extra files ===========" 215 echo "" 216 fi 217 218 if [ -s "${SDIR}/missing" ]; then 219 count="$(${AWK} 'END {print NR}' "${SDIR}/missing")" 220 echo "" 221 echo "====== ${count} missing files in DESTDIR ========" 222 echo "Files in flist but missing from DESTDIR." 223 echo "File wasn't installed ?" 224 if ${allowmissing}; then 225 echo "This is non-fatal, due to '-m' option." 226 else 227 es=1 228 fi 229 echo "------------------------------------------" 230 cat "${SDIR}/missing" 231 echo "======== end of ${count} missing files ==========" 232 echo "" 233 fi 234 235 exit 0 # cleanup will exit with ${es} 236