summaryrefslogtreecommitdiff
path: root/distrib/sets/checkflist
blob: fb320f0e79afa594d4cbaa237fe1cc08ecf3c6df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#! /bin/sh --
#
#	$NetBSD: checkflist,v 1.44 2013/06/10 05:03:20 mrg Exp $
#
# Verify output of makeflist against contents of ${DESTDIR} and ${metalog}.

if [ -z "${DESTDIR}" ]; then
	echo "DESTDIR must be set"
	exit 1
fi

prog="${0##*/}"
rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
. "${rundir}/sets.subr"

#
# * ${SETS_DLIST}: files present in DESTDIR.
# * ${SETS_FLIST}: files mentioned in flist;
# * ${SETS_MLIST}: files mentioned in metalog;
#
SETS_DLIST="${DESTDIR}/SETS.dlist"
SETS_FLIST="${DESTDIR}/SETS.flist"
SETS_MLIST="${DESTDIR}/SETS.mlist"

#
# * ${SETS_METALOG_EXTRA}: Files in METALOG but missing from DESTDIR."
# * ${SETS_METALOG_MISSING}: Files in DESTDIR but missing from METALOG."
# * ${SETS_DESTDIR_EXTRA}: Files in DESTDIR but missing from setlist."
# * ${SETS_DESTDIR_MISSING}: Files in setlist but missing from DESTDIR."
#
SETS_METALOG_EXTRA="${DESTDIR}/SETS.metalog.extra"
SETS_METALOG_MISSING="${DESTDIR}/SETS.metalog.missing"
SETS_DESTDIR_EXTRA="${DESTDIR}/SETS.destdir.extra"
SETS_DESTDIR_MISSING="${DESTDIR}/SETS.destdir.missing"

es=0
cleanup()
{
	if [ ${es} -gt 255 ]; then
		es=255
	fi
	exit ${es}
}
trap cleanup 0 2 3 13		# EXIT INT QUIT PIPE

origin=.
xargs=""
dargs=""
metalog=
allowextra=false
allowmissing=false

# handle args
while getopts xybL:M:em ch; do
	case ${ch} in
	x)
		xargs="-x"
		origin="./etc/X11 ./etc/fonts ./usr/X11R6 ./usr/X11R7"
		;;
	y)
		xargs="-y"
		origin="./etc/ext ./usr/ext"
		;;
	# backward compat
	b)
		xargs="-b"
		;;
	L)
		xargs="-L ${OPTARG}"
		;;
	M)
		metalog="${OPTARG}"
		;;
	e)
		allowextra=true
		;;
	m)
		allowmissing=true
		;;
	*)
		cat 1>&2 <<USAGE
Usage: ${prog} [-x|-y|-b|-L lists] [-M metalog] [-e] [-m]
	-x		check only x11 lists
	-y		check only extsrc lists
	-b		check netbsd + x11 lists
	-L base,x,ext	check specified lists
	-M metalog	metalog file
	-e		extra files are not considered an error
	-m		missing files are not considered an error
USAGE
		exit 1
		;;
	esac
done
shift $((${OPTIND} - 1))

#
# Exceptions to flist checking (all begin with "./"):
#
# * ignore var/db/syspkg and its contents
# * ignore METALOG and METALOG.*
# * ignore etc/mtree/set.*
# * MINIX3 only: ignore ASR service binaries
#
ignore_exceptions()
{
IGNORE_REGEXP_SYSPKG="^\./var/db/syspkg(\$|/)"
IGNORE_REGEXP_METALOG="^\./METALOG(\..*)?\$"
IGNORE_REGEXP_SETS="^\./SETS\..*\$"
IGNORE_REGEXP_MTREE="^\./etc/mtree/set\.[a-z]*\$"
IGNORE_REGEXP_SERVICE_ASR="^\./usr/service/asr/"

	${EGREP} -v \
		-e "${IGNORE_REGEXP_SYSPKG}" \
		-e "${IGNORE_REGEXP_METALOG}" \
		-e "${IGNORE_REGEXP_SETS}" \
		-e "${IGNORE_REGEXP_MTREE}" \
		-e "${IGNORE_REGEXP_SERVICE_ASR}"
}

#
# Here would be a good place to add custom exceptions to flist checking.
#

#
# Make three lists:
#
# All three lists are filtered against ${IGNORE_REGEXP}.
#

generate_dlist()
{
( cd "${DESTDIR}" && ${FIND} ${origin} \
	\( -type d -o -type f -o -type l \) -print ) \
	| ${SORT} -u | ignore_exceptions >"${SETS_DLIST}"
}

generate_flist()
{
${HOST_SH} "${rundir}/makeflist" ${xargs} ${dargs} \
	| ${SORT} -u | ignore_exceptions >"${SETS_FLIST}"
}

generate_mlist()
{
if [ -n "${metalog}" ]; then
	${AWK} '{print $1}' <"${metalog}" \
	| ${SORT} -u | ignore_exceptions >"${SETS_MLIST}"
else
	SETS_MLIST=/dev/null
fi
}

generate_mlist_missing()
{
	${COMM} -23 "${SETS_DLIST}" "${SETS_MLIST}" > "${SETS_METALOG_MISSING}"
}

generate_mlist_extra()
{
	${COMM} -13 "${SETS_DLIST}" "${SETS_MLIST}" > "${SETS_METALOG_EXTRA}"
}

generate_dlist_missing()
{
	${COMM} -23 "${SETS_FLIST}" "${SETS_DLIST}" > "${SETS_DESTDIR_MISSING}"
}

generate_dlist_extra()
{
	${COMM} -13 "${SETS_FLIST}" "${SETS_DLIST}" > "${SETS_DESTDIR_EXTRA}"
}

exist_case_insensitive()
{
	while read f; do
		[ -f "${DESTDIR}/${f}" ] || \
		[ -d "${DESTDIR}/${f}" ] || \
		[ -L "${DESTDIR}/${f}" ] || \
		echo "$f"
	done
}

#
# compare DESTDIR with METALOG, and report on differences.
#
compare_metalog()
{
    # Handle case insensitive filesystems
    mv -f "${SETS_METALOG_EXTRA}" "${SETS_METALOG_EXTRA}.all"
    exist_case_insensitive < "${SETS_METALOG_EXTRA}.all" > "${SETS_METALOG_EXTRA}"
    rm -f "${SETS_METALOG_EXTRA}.all"

    check_metalog_extra
    check_metalog_missing
}

check_metalog_extra()
{
    if [ -s "${SETS_METALOG_EXTRA}" ]; then
	count="$(${AWK} 'END {print NR}' "${SETS_METALOG_EXTRA}")"
	echo ""
	echo "=======  ${count} extra files in METALOG  ========="
	echo "Files in METALOG but missing from DESTDIR."
	echo "File was deleted after installation ?"
	echo "------------------------------------------"
	cat "${SETS_METALOG_EXTRA}"
	echo "=========  end of ${count} extra files  ==========="
	echo ""
	es=1 # this is fatal even if ${allowextra} is true
    fi
}

check_metalog_missing()
{
    if [ -s "${SETS_METALOG_MISSING}" ]; then
	count="$(${AWK} 'END {print NR}' "${SETS_METALOG_MISSING}")"
	echo ""
	echo "======  ${count} missing files in METALOG  ========"
	echo "Files in DESTDIR but missing from METALOG."
	echo "File installed but not registered in METALOG ?"
	echo "------------------------------------------"
	cat "${SETS_METALOG_MISSING}"
	echo "========  end of ${count} missing files  =========="
	echo ""
	es=1 # this is fatal even if ${allowmissing} is true
    fi
}

#
# compare flist with DESTDIR, and report on differences.
#
compare_destdir()
{
# Handle case insensitive filesystems
mv -f "${SETS_DESTDIR_MISSING}" "${SETS_DESTDIR_MISSING}.all"
exist_case_insensitive < "${SETS_DESTDIR_MISSING}.all" > "${SETS_DESTDIR_MISSING}"
rm -f "${SETS_DESTDIR_MISSING}.all"

check_destdir_extra
check_destdir_missing
}

check_destdir_extra()
{
if [ -s "${SETS_DESTDIR_EXTRA}" ]; then
	count="$(${AWK} 'END {print NR}' "${SETS_DESTDIR_EXTRA}")"
	echo ""
	echo "=======  ${count} extra files in DESTDIR  ========="
	echo "Files in DESTDIR but missing from flist."
	echo "File is obsolete or flist is out of date ?"
	if ${allowextra}; then
		echo "This is non-fatal, due to '-e' option."
	else
		es=1
	fi
	echo "------------------------------------------"
	cat "${SETS_DESTDIR_EXTRA}"
	echo "=========  end of ${count} extra files  ==========="
	echo ""
fi
}

check_destdir_missing()
{
if [ -s "${SETS_DESTDIR_MISSING}" ]; then
	count="$(${AWK} 'END {print NR}' "${SETS_DESTDIR_MISSING}")"
	echo ""
	echo "======  ${count} missing files in DESTDIR  ========"
	echo "Files in flist but missing from DESTDIR."
	echo "File wasn't installed ?"
	if ${allowmissing}; then
		echo "This is non-fatal, due to '-m' option."
	else
		es=1
	fi
	echo "------------------------------------------"
	cat "${SETS_DESTDIR_MISSING}"
	echo "========  end of ${count} missing files  =========="
	echo ""
fi
}

generate_dlist
generate_flist
generate_mlist

generate_mlist_missing
generate_mlist_extra

generate_dlist_missing
generate_dlist_extra

if false && [ -n "${metalog}" ]; then
	# XXX: Temporarily disabled due to problems with obsolete files in metalog
	compare_metalog
else
	compare_destdir
fi

exit 0		# cleanup will exit with ${es}