aboutsummaryrefslogtreecommitdiff
path: root/checkpkg
blob: b596e722e9b07a44bb717aa4de8af3f9386973ee (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
#!/bin/sh

# check one or more package lists from /var/log/packages to see if the
# files listed there actually exist on the filesystem.
# ROOT variable is respected, same as installpkg.
# .new config files are checked for without their .new ending.
# known issue: any file whose name has a colon in it, won't be checked.

# exit status of this script will be 0 for OK, non-zero if one or
# more file was missing.
exitstatus=0

# package filenames are ASCII, this will speed things up slightly.
LANG="C"
LC_ALL="C"
export LANG LC_ALL

check_pkg() {
	if [ ! -e "$1" ]; then
		echo "$0: $1 not found" 1>&2
		exitstatus=1
		return
	fi

	grep -v -e ":" -e "^install" "$1" | sed 's,\.new$,,' > "$tmpfile"

	( while read line; do
		[ -e "$ROOT"/"$line" ] || ( exitstatus=1 && echo "$1: missing $line" )
	done ) < "$tmpfile"
}

if [ -z "$*" -o "$1" = "--help" ]; then
	cat <<EOF
Usage: $0 [ package-list-file(s) ]
EOF
	exit 0
fi

for pkg in "$@"; do
	tmpfile="$( mktemp -t checkpkg.XXXXXX )"
	check_pkg "$pkg"
	rm -f "$tmpfile"
done
exit $exitstatus