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