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