etc/services - sync with NetBSD-8
[minix.git] / distrib / sets / checkflist
blobfb320f0e79afa594d4cbaa237fe1cc08ecf3c6df
1 #! /bin/sh --
3 # $NetBSD: checkflist,v 1.44 2013/06/10 05:03:20 mrg Exp $
5 # Verify output of makeflist against contents of ${DESTDIR} and ${metalog}.
7 if [ -z "${DESTDIR}" ]; then
8 echo "DESTDIR must be set"
9 exit 1
12 prog="${0##*/}"
13 rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
14 . "${rundir}/sets.subr"
17 # * ${SETS_DLIST}: files present in DESTDIR.
18 # * ${SETS_FLIST}: files mentioned in flist;
19 # * ${SETS_MLIST}: files mentioned in metalog;
21 SETS_DLIST="${DESTDIR}/SETS.dlist"
22 SETS_FLIST="${DESTDIR}/SETS.flist"
23 SETS_MLIST="${DESTDIR}/SETS.mlist"
26 # * ${SETS_METALOG_EXTRA}: Files in METALOG but missing from DESTDIR."
27 # * ${SETS_METALOG_MISSING}: Files in DESTDIR but missing from METALOG."
28 # * ${SETS_DESTDIR_EXTRA}: Files in DESTDIR but missing from setlist."
29 # * ${SETS_DESTDIR_MISSING}: Files in setlist but missing from DESTDIR."
31 SETS_METALOG_EXTRA="${DESTDIR}/SETS.metalog.extra"
32 SETS_METALOG_MISSING="${DESTDIR}/SETS.metalog.missing"
33 SETS_DESTDIR_EXTRA="${DESTDIR}/SETS.destdir.extra"
34 SETS_DESTDIR_MISSING="${DESTDIR}/SETS.destdir.missing"
36 es=0
37 cleanup()
39 if [ ${es} -gt 255 ]; then
40 es=255
42 exit ${es}
44 trap cleanup 0 2 3 13 # EXIT INT QUIT PIPE
46 origin=.
47 xargs=""
48 dargs=""
49 metalog=
50 allowextra=false
51 allowmissing=false
53 # handle args
54 while getopts xybL:M:em ch; do
55 case ${ch} in
57 xargs="-x"
58 origin="./etc/X11 ./etc/fonts ./usr/X11R6 ./usr/X11R7"
61 xargs="-y"
62 origin="./etc/ext ./usr/ext"
64 # backward compat
66 xargs="-b"
69 xargs="-L ${OPTARG}"
72 metalog="${OPTARG}"
75 allowextra=true
78 allowmissing=true
81 cat 1>&2 <<USAGE
82 Usage: ${prog} [-x|-y|-b|-L lists] [-M metalog] [-e] [-m]
83 -x check only x11 lists
84 -y check only extsrc lists
85 -b check netbsd + x11 lists
86 -L base,x,ext check specified lists
87 -M metalog metalog file
88 -e extra files are not considered an error
89 -m missing files are not considered an error
90 USAGE
91 exit 1
93 esac
94 done
95 shift $((${OPTIND} - 1))
98 # Exceptions to flist checking (all begin with "./"):
100 # * ignore var/db/syspkg and its contents
101 # * ignore METALOG and METALOG.*
102 # * ignore etc/mtree/set.*
103 # * MINIX3 only: ignore ASR service binaries
105 ignore_exceptions()
107 IGNORE_REGEXP_SYSPKG="^\./var/db/syspkg(\$|/)"
108 IGNORE_REGEXP_METALOG="^\./METALOG(\..*)?\$"
109 IGNORE_REGEXP_SETS="^\./SETS\..*\$"
110 IGNORE_REGEXP_MTREE="^\./etc/mtree/set\.[a-z]*\$"
111 IGNORE_REGEXP_SERVICE_ASR="^\./usr/service/asr/"
113 ${EGREP} -v \
114 -e "${IGNORE_REGEXP_SYSPKG}" \
115 -e "${IGNORE_REGEXP_METALOG}" \
116 -e "${IGNORE_REGEXP_SETS}" \
117 -e "${IGNORE_REGEXP_MTREE}" \
118 -e "${IGNORE_REGEXP_SERVICE_ASR}"
122 # Here would be a good place to add custom exceptions to flist checking.
126 # Make three lists:
128 # All three lists are filtered against ${IGNORE_REGEXP}.
131 generate_dlist()
133 ( cd "${DESTDIR}" && ${FIND} ${origin} \
134 \( -type d -o -type f -o -type l \) -print ) \
135 | ${SORT} -u | ignore_exceptions >"${SETS_DLIST}"
138 generate_flist()
140 ${HOST_SH} "${rundir}/makeflist" ${xargs} ${dargs} \
141 | ${SORT} -u | ignore_exceptions >"${SETS_FLIST}"
144 generate_mlist()
146 if [ -n "${metalog}" ]; then
147 ${AWK} '{print $1}' <"${metalog}" \
148 | ${SORT} -u | ignore_exceptions >"${SETS_MLIST}"
149 else
150 SETS_MLIST=/dev/null
154 generate_mlist_missing()
156 ${COMM} -23 "${SETS_DLIST}" "${SETS_MLIST}" > "${SETS_METALOG_MISSING}"
159 generate_mlist_extra()
161 ${COMM} -13 "${SETS_DLIST}" "${SETS_MLIST}" > "${SETS_METALOG_EXTRA}"
164 generate_dlist_missing()
166 ${COMM} -23 "${SETS_FLIST}" "${SETS_DLIST}" > "${SETS_DESTDIR_MISSING}"
169 generate_dlist_extra()
171 ${COMM} -13 "${SETS_FLIST}" "${SETS_DLIST}" > "${SETS_DESTDIR_EXTRA}"
174 exist_case_insensitive()
176 while read f; do
177 [ -f "${DESTDIR}/${f}" ] || \
178 [ -d "${DESTDIR}/${f}" ] || \
179 [ -L "${DESTDIR}/${f}" ] || \
180 echo "$f"
181 done
185 # compare DESTDIR with METALOG, and report on differences.
187 compare_metalog()
189 # Handle case insensitive filesystems
190 mv -f "${SETS_METALOG_EXTRA}" "${SETS_METALOG_EXTRA}.all"
191 exist_case_insensitive < "${SETS_METALOG_EXTRA}.all" > "${SETS_METALOG_EXTRA}"
192 rm -f "${SETS_METALOG_EXTRA}.all"
194 check_metalog_extra
195 check_metalog_missing
198 check_metalog_extra()
200 if [ -s "${SETS_METALOG_EXTRA}" ]; then
201 count="$(${AWK} 'END {print NR}' "${SETS_METALOG_EXTRA}")"
202 echo ""
203 echo "======= ${count} extra files in METALOG ========="
204 echo "Files in METALOG but missing from DESTDIR."
205 echo "File was deleted after installation ?"
206 echo "------------------------------------------"
207 cat "${SETS_METALOG_EXTRA}"
208 echo "========= end of ${count} extra files ==========="
209 echo ""
210 es=1 # this is fatal even if ${allowextra} is true
214 check_metalog_missing()
216 if [ -s "${SETS_METALOG_MISSING}" ]; then
217 count="$(${AWK} 'END {print NR}' "${SETS_METALOG_MISSING}")"
218 echo ""
219 echo "====== ${count} missing files in METALOG ========"
220 echo "Files in DESTDIR but missing from METALOG."
221 echo "File installed but not registered in METALOG ?"
222 echo "------------------------------------------"
223 cat "${SETS_METALOG_MISSING}"
224 echo "======== end of ${count} missing files =========="
225 echo ""
226 es=1 # this is fatal even if ${allowmissing} is true
231 # compare flist with DESTDIR, and report on differences.
233 compare_destdir()
235 # Handle case insensitive filesystems
236 mv -f "${SETS_DESTDIR_MISSING}" "${SETS_DESTDIR_MISSING}.all"
237 exist_case_insensitive < "${SETS_DESTDIR_MISSING}.all" > "${SETS_DESTDIR_MISSING}"
238 rm -f "${SETS_DESTDIR_MISSING}.all"
240 check_destdir_extra
241 check_destdir_missing
244 check_destdir_extra()
246 if [ -s "${SETS_DESTDIR_EXTRA}" ]; then
247 count="$(${AWK} 'END {print NR}' "${SETS_DESTDIR_EXTRA}")"
248 echo ""
249 echo "======= ${count} extra files in DESTDIR ========="
250 echo "Files in DESTDIR but missing from flist."
251 echo "File is obsolete or flist is out of date ?"
252 if ${allowextra}; then
253 echo "This is non-fatal, due to '-e' option."
254 else
255 es=1
257 echo "------------------------------------------"
258 cat "${SETS_DESTDIR_EXTRA}"
259 echo "========= end of ${count} extra files ==========="
260 echo ""
264 check_destdir_missing()
266 if [ -s "${SETS_DESTDIR_MISSING}" ]; then
267 count="$(${AWK} 'END {print NR}' "${SETS_DESTDIR_MISSING}")"
268 echo ""
269 echo "====== ${count} missing files in DESTDIR ========"
270 echo "Files in flist but missing from DESTDIR."
271 echo "File wasn't installed ?"
272 if ${allowmissing}; then
273 echo "This is non-fatal, due to '-m' option."
274 else
275 es=1
277 echo "------------------------------------------"
278 cat "${SETS_DESTDIR_MISSING}"
279 echo "======== end of ${count} missing files =========="
280 echo ""
284 generate_dlist
285 generate_flist
286 generate_mlist
288 generate_mlist_missing
289 generate_mlist_extra
291 generate_dlist_missing
292 generate_dlist_extra
294 if false && [ -n "${metalog}" ]; then
295 # XXX: Temporarily disabled due to problems with obsolete files in metalog
296 compare_metalog
297 else
298 compare_destdir
301 exit 0 # cleanup will exit with ${es}