summaryrefslogtreecommitdiff
path: root/distrib/sets/checkflist
blob: 41fb471b20c5e233c516035636ffd2ae99dc29a1 (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
#! /bin/sh --
#
#	$NetBSD: checkflist,v 1.25 2004/01/08 01:31:57 lukem Exp $
#
# Verify output of makeflist against contents of $DESTDIR.

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

prog=${0##*/}

: ${HOST_SH=sh}
: ${MKTEMP=mktemp}
SDIR=$(${MKTEMP} -d /tmp/${prog}.XXXXXX)

es=0
cleanup()
{
	/bin/rm -rf $SDIR
	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 xbM:em ch; do
	case ${ch} in
	x)
		xargs="-x"
		origin="./etc/X11 ./etc/fonts ./usr/X11R6"
		;;
	b)
		xargs="-b"
		;;
	M)
		metalog=${OPTARG}
		;;
	e)
		allowextra=true
		;;
	m)
		allowmissing=true
		;;
	*)
		cat 1>&2 <<USAGE
Usage: ${prog} [-x|-b] [-M metalog] [-e] [-m]
	-x		check only x11 lists
	-b		check netbsd + x11 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))

if [ -n "$metalog" ]; then
	case "$metalog" in
	${DESTDIR}/*)
		# Metalog would be noticed, so make sure it gets
		# ignored.
		metalog="./${metalog#${DESTDIR}/}"
		;;
	*)
		metalog=""
	esac
fi


${HOST_SH} ./makeflist $xargs $dargs > $SDIR/flist

(
	cd $DESTDIR
	find $origin \( -type d -o -type f -o -type l \) -print
) | (
	while read line; do
		case "$line" in
		$metalog)
			;;
		*)
			echo $line
			;;
		esac
	done
) | sort > $SDIR/files

comm -23 $SDIR/flist $SDIR/files > $SDIR/missing
comm -13 $SDIR/flist $SDIR/files > $SDIR/extra

if [ -s $SDIR/extra ]; then
	count=$(awk 'END {print NR}' $SDIR/extra)
	echo ""
	echo "============  ${count} extra files  ==============="
	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."
	else
		es=1
	fi
	echo "------------------------------------------"
	cat $SDIR/extra
	echo "=========  end of ${count} extra files  ==========="
	echo ""
fi

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

exit 0		# cleanup will exit with $es