#!/bin/sh

set -e

files_exist_twice() {
	cat <<EOF
ERROR! Some files exist twice, both in $1 and $1-desktop:
$2

This needs to be fixed, otherwise kali-defaults and kali-defaults-desktop
can't be installed together.
EOF
}

for d in etc usr; do
	find $d -type f,l | sort > $d.list
	find $d-desktop -type f,l | sed 's/-desktop//' | sort > $d-desktop.list
	dup=$(comm -12 $d.list $d-desktop.list)
	rm -f $d.list $d-desktop.list
	if [ "$dup" ]; then
		files_exist_twice "$d" "$dup" >&2
		exit 1
	fi
done
