#!/bin/sh
# Hack to see whether a package is missing anything, based on its
# file list from dpkg -L. (Can't use the *.list files because they
# don't take into account diversions; this script does.)

PACKAGE=$1

IFS="
"

for f in $(dpkg -L $PACKAGE); do
	case "$f" in
		"package diverts others to"*) ;;
		"diverted by"*)
			divertfile=$(echo "$f" | cut -d' ' -f5-)
			if [ -n "$missing" ] && [ "$missing" = "$divertfile" ]; then
				:
			else
				echo "missing: $divertfile"
			fi
			divertfile=""
			missing=""
		;;
		*)
			if [ ! -e "$f" ]; then
				if [ -z "$missing" ]; then
					missing="$f"
				else
					# flush missing, because there's no diverted statement to
					# expect later
					echo "missing: $missing"
					missing=""
				fi
			else
				if [ -n "$missing" ]; then
					echo "missing: $missing"
					missing=""
				fi
			fi
		;;
	esac
done

if [ -n "$missing" ]; then
	echo "missing: $missing"
fi
