1 1.3 mikel #! /bin/sh -- 2 1.3 mikel # 3 1.35 uebayasi # $NetBSD: checkflist,v 1.40 2009/12/10 16:40:21 uebayasi 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.29 apb SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")" 17 1.20 lukem 18 1.20 lukem es=0 19 1.20 lukem cleanup() 20 1.20 lukem { 21 1.29 apb /bin/rm -rf "${SDIR}" 22 1.32 apb if [ ${es} -gt 255 ]; then 23 1.20 lukem es=255 24 1.20 lukem fi 25 1.29 apb exit ${es} 26 1.20 lukem } 27 1.20 lukem trap cleanup 0 2 3 13 # EXIT INT QUIT PIPE 28 1.20 lukem 29 1.9 ross origin=. 30 1.10 perry xargs="" 31 1.10 perry dargs="" 32 1.15 lukem metalog= 33 1.22 lukem allowextra=false 34 1.22 lukem allowmissing=false 35 1.10 perry 36 1.10 perry # handle args 37 1.35 uebayasi while getopts xybL:M:em ch; do 38 1.24 lukem case ${ch} in 39 1.24 lukem x) 40 1.10 perry xargs="-x" 41 1.18 tron origin="./etc/X11 ./etc/fonts ./usr/X11R6" 42 1.10 perry ;; 43 1.35 uebayasi y) 44 1.35 uebayasi xargs="-y" 45 1.35 uebayasi origin="./etc/ext ./usr/ext" 46 1.35 uebayasi ;; 47 1.35 uebayasi # backward compat 48 1.24 lukem b) 49 1.10 perry xargs="-b" 50 1.10 perry ;; 51 1.35 uebayasi L) 52 1.35 uebayasi xargs="-L ${OPTARG}" 53 1.35 uebayasi ;; 54 1.24 lukem M) 55 1.29 apb metalog="${OPTARG}" 56 1.15 lukem ;; 57 1.24 lukem e) 58 1.22 lukem allowextra=true 59 1.22 lukem ;; 60 1.24 lukem m) 61 1.22 lukem allowmissing=true 62 1.22 lukem ;; 63 1.24 lukem *) 64 1.10 perry cat 1>&2 <<USAGE 65 1.35 uebayasi Usage: ${prog} [-x|-y|-b|-L lists] [-M metalog] [-e] [-m] 66 1.24 lukem -x check only x11 lists 67 1.35 uebayasi -y check only extsrc lists 68 1.24 lukem -b check netbsd + x11 lists 69 1.35 uebayasi -L base,x,ext check specified lists 70 1.15 lukem -M metalog metalog file 71 1.22 lukem -e extra files are not considered an error 72 1.22 lukem -m missing files are not considered an error 73 1.10 perry USAGE 74 1.10 perry exit 1 75 1.10 perry ;; 76 1.10 perry esac 77 1.10 perry done 78 1.24 lukem shift $((${OPTIND} - 1)) 79 1.10 perry 80 1.30 apb # 81 1.30 apb # Exceptions to flist checking (all begin with "./"): 82 1.30 apb # 83 1.30 apb # * ignore var/db/syspkg and its contents 84 1.34 apb # * ignore METALOG and METALOG.* 85 1.30 apb # * ignore etc/mtree/set.* 86 1.30 apb # 87 1.36 uebayasi ignore_exceptions() 88 1.36 uebayasi { 89 1.40 uebayasi IGNORE_REGEXP_SYSPKG="^\./var/db/syspkg(\$|/)" 90 1.40 uebayasi IGNORE_REGEXP_METALOG="^\./METALOG(\..*)?\$" 91 1.40 uebayasi IGNORE_REGEXP_MTREE="^\./etc/mtree/set\.[a-z]*\$" 92 1.40 uebayasi 93 1.40 uebayasi ${EGREP} -v \ 94 1.40 uebayasi -e "${IGNORE_REGEXP_SYSPKG}" \ 95 1.40 uebayasi -e "${IGNORE_REGEXP_METALOG}" \ 96 1.40 uebayasi -e "${IGNORE_REGEXP_MTREE}" 97 1.36 uebayasi } 98 1.15 lukem 99 1.30 apb # 100 1.30 apb # Here would be a good place to add custom exceptions to flist checking. 101 1.30 apb # 102 1.15 lukem 103 1.30 apb # 104 1.30 apb # Make three lists: 105 1.30 apb # * ${SDIR}/files: files present in DESTDIR. 106 1.30 apb # * ${SDIR}/flist: files mentioned in flist; 107 1.30 apb # * ${SDIR}/mlist: files mentioned in metalog; 108 1.30 apb # 109 1.34 apb # All three lists are filtered against ${IGNORE_REGEXP}. 110 1.34 apb # 111 1.36 uebayasi 112 1.36 uebayasi generate_files() 113 1.36 uebayasi { 114 1.30 apb ( cd "${DESTDIR}" && ${FIND} ${origin} \ 115 1.30 apb \( -type d -o -type f -o -type l \) -print ) \ 116 1.36 uebayasi | ${SORT} -u | ignore_exceptions >"${SDIR}/files" 117 1.36 uebayasi } 118 1.36 uebayasi 119 1.36 uebayasi generate_flist() 120 1.36 uebayasi { 121 1.30 apb ${HOST_SH} "${rundir}/makeflist" ${xargs} ${dargs} \ 122 1.36 uebayasi | ${SORT} -u | ignore_exceptions >"${SDIR}/flist" 123 1.36 uebayasi } 124 1.36 uebayasi 125 1.36 uebayasi generate_mlist() 126 1.36 uebayasi { 127 1.30 apb if [ -n "${metalog}" ]; then 128 1.30 apb ${AWK} '{print $1}' <"${metalog}" \ 129 1.36 uebayasi | ${SORT} -u | ignore_exceptions >"${SDIR}/mlist" 130 1.30 apb fi 131 1.36 uebayasi } 132 1.36 uebayasi 133 1.36 uebayasi generate_missing() 134 1.36 uebayasi { 135 1.36 uebayasi ${COMM} -23 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/missing" 136 1.36 uebayasi } 137 1.36 uebayasi 138 1.36 uebayasi generate_extra() 139 1.36 uebayasi { 140 1.36 uebayasi ${COMM} -13 "${SDIR}/files" "${SDIR}/mlist" > "${SDIR}/extra" 141 1.36 uebayasi } 142 1.36 uebayasi 143 1.39 uebayasi exist_case_insensitive() 144 1.39 uebayasi { 145 1.39 uebayasi while read f; do 146 1.39 uebayasi [ -f "${DESTDIR}/${f}" ] || \ 147 1.39 uebayasi [ -d "${DESTDIR}/${f}" ] || \ 148 1.39 uebayasi [ -L "${DESTDIR}/${f}" ] || \ 149 1.39 uebayasi echo "$f" 150 1.39 uebayasi done 151 1.39 uebayasi } 152 1.39 uebayasi 153 1.30 apb # 154 1.30 apb # compare DESTDIR with METALOG, and report on differences. 155 1.30 apb # 156 1.37 uebayasi compare_metalog() 157 1.37 uebayasi { 158 1.33 dbj # Handle case insensitive filesystems 159 1.33 dbj mv -f "${SDIR}/extra" "${SDIR}/extra.all" 160 1.39 uebayasi exist_case_insensitive < "${SDIR}/extra.all" > "${SDIR}/extra" 161 1.33 dbj 162 1.37 uebayasi check_metalog_extra 163 1.37 uebayasi check_metalog_missing 164 1.37 uebayasi } 165 1.37 uebayasi 166 1.37 uebayasi check_metalog_extra() 167 1.37 uebayasi { 168 1.30 apb if [ -s "${SDIR}/extra" ]; then 169 1.30 apb count="$(${AWK} 'END {print NR}' "${SDIR}/extra")" 170 1.30 apb echo "" 171 1.30 apb echo "======= ${count} extra files in METALOG =========" 172 1.30 apb echo "Files in METALOG but missing from DESTDIR." 173 1.30 apb echo "File was deleted after installation ?" 174 1.30 apb echo "------------------------------------------" 175 1.30 apb cat "${SDIR}/extra" 176 1.30 apb echo "========= end of ${count} extra files ===========" 177 1.30 apb echo "" 178 1.30 apb es=1 # this is fatal even if ${allowextra} is true 179 1.30 apb fi 180 1.37 uebayasi } 181 1.30 apb 182 1.37 uebayasi check_metalog_missing() 183 1.37 uebayasi { 184 1.30 apb if [ -s "${SDIR}/missing" ]; then 185 1.30 apb count="$(${AWK} 'END {print NR}' "${SDIR}/missing")" 186 1.30 apb echo "" 187 1.30 apb echo "====== ${count} missing files in METALOG ========" 188 1.30 apb echo "Files in DESTDIR but missing from METALOG." 189 1.30 apb echo "File installed but not registered in METALOG ?" 190 1.30 apb echo "------------------------------------------" 191 1.30 apb cat "${SDIR}/missing" 192 1.30 apb echo "======== end of ${count} missing files ==========" 193 1.30 apb echo "" 194 1.30 apb es=1 # this is fatal even if ${allowmissing} is true 195 1.30 apb fi 196 1.37 uebayasi } 197 1.37 uebayasi 198 1.30 apb # 199 1.30 apb # compare flist with DESTDIR, and report on differences. 200 1.30 apb # 201 1.37 uebayasi compare_destdir() 202 1.37 uebayasi { 203 1.33 dbj # Handle case insensitive filesystems 204 1.33 dbj mv -f "${SDIR}/missing" "${SDIR}/missing.all" 205 1.39 uebayasi exist_case_insensitive < "${SDIR}/missing.all" > "${SDIR}/missing" 206 1.33 dbj 207 1.37 uebayasi check_destdir_extra 208 1.37 uebayasi check_destdir_missing 209 1.37 uebayasi } 210 1.37 uebayasi 211 1.37 uebayasi check_destdir_extra() 212 1.37 uebayasi { 213 1.29 apb if [ -s "${SDIR}/extra" ]; then 214 1.29 apb count="$(${AWK} 'END {print NR}' "${SDIR}/extra")" 215 1.20 lukem echo "" 216 1.30 apb echo "======= ${count} extra files in DESTDIR =========" 217 1.20 lukem echo "Files in DESTDIR but missing from flist." 218 1.20 lukem echo "File is obsolete or flist is out of date ?" 219 1.22 lukem if ${allowextra}; then 220 1.30 apb echo "This is non-fatal, due to '-e' option." 221 1.22 lukem else 222 1.22 lukem es=1 223 1.22 lukem fi 224 1.20 lukem echo "------------------------------------------" 225 1.29 apb cat "${SDIR}/extra" 226 1.25 lukem echo "========= end of ${count} extra files ===========" 227 1.20 lukem echo "" 228 1.20 lukem fi 229 1.37 uebayasi } 230 1.20 lukem 231 1.37 uebayasi check_destdir_missing() 232 1.37 uebayasi { 233 1.29 apb if [ -s "${SDIR}/missing" ]; then 234 1.29 apb count="$(${AWK} 'END {print NR}' "${SDIR}/missing")" 235 1.20 lukem echo "" 236 1.30 apb echo "====== ${count} missing files in DESTDIR ========" 237 1.20 lukem echo "Files in flist but missing from DESTDIR." 238 1.20 lukem echo "File wasn't installed ?" 239 1.22 lukem if ${allowmissing}; then 240 1.30 apb echo "This is non-fatal, due to '-m' option." 241 1.22 lukem else 242 1.22 lukem es=1 243 1.22 lukem fi 244 1.20 lukem echo "------------------------------------------" 245 1.29 apb cat "${SDIR}/missing" 246 1.25 lukem echo "======== end of ${count} missing files ==========" 247 1.20 lukem echo "" 248 1.15 lukem fi 249 1.37 uebayasi } 250 1.37 uebayasi 251 1.38 uebayasi generate_files 252 1.38 uebayasi generate_flist 253 1.38 uebayasi generate_mlist 254 1.38 uebayasi generate_missing 255 1.38 uebayasi generate_extra 256 1.38 uebayasi 257 1.39 uebayasi # XXX: Temporarily disabled due to problems with obsolete files in metalog 258 1.39 uebayasi if false && [ -n "${metalog}" ]; then 259 1.39 uebayasi compare_metalog 260 1.39 uebayasi fi 261 1.37 uebayasi compare_destdir 262 1.20 lukem 263 1.29 apb exit 0 # cleanup will exit with ${es} 264