#!/bin/sh
set -eu
export LC_ALL=C.UTF-8
trap "rm -rf /tmp/debian-chroot" EXIT INT TERM
{{ CMD }} --mode=root --variant=apt \
	--essential-hook=./hooks/merged-usr/essential00.sh \
	--setup-hook=./hooks/merged-usr/setup00.sh \
	--customize-hook='[ -L "$1"/bin -a -L "$1"/sbin -a -L "$1"/lib ]' \
	{{ DIST }} /tmp/debian-chroot {{ MIRROR }}
tar -C /tmp/debian-chroot --one-file-system -c . | tar -t | sort > tar2.txt
{
	sed -e 's/^\.\/bin\//.\/usr\/bin\//;s/^\.\/lib\//.\/usr\/lib\//;s/^\.\/sbin\//.\/usr\/sbin\//;' tar1.txt | {
		case {{ HOSTARCH }} in
		amd64) sed -e 's/^\.\/lib32\//.\/usr\/lib32\//;s/^\.\/lib64\//.\/usr\/lib64\//;s/^\.\/libx32\//.\/usr\/libx32\//;';;
		ppc64el) sed -e 's/^\.\/lib64\//.\/usr\/lib64\//;';;
		*) cat;;
		esac
	};
	echo ./bin;
	echo ./lib;
	echo ./sbin;
	case {{ HOSTARCH }} in
	amd64)
		echo ./lib32;
		echo ./lib64;
		echo ./libx32;
		echo ./usr/lib32/;
		echo ./usr/libx32/;
		;;
	i386)
		echo ./lib64;
		echo ./libx32;
		echo ./usr/lib64/;
		echo ./usr/libx32/;
		;;
	ppc64el)
		echo ./lib64;
		;;
	s390x)
		echo ./lib32;
		echo ./usr/lib32/;
		;;
	esac
	echo ./usr/share/doc/usr-is-merged/
	echo ./usr/share/doc/usr-is-merged/changelog.gz
	echo ./usr/share/doc/usr-is-merged/copyright
	echo ./var/lib/dpkg/info/usr-is-merged.list
	echo ./var/lib/dpkg/info/usr-is-merged.md5sums
	echo ./var/lib/dpkg/info/usr-is-merged.preinst
} | sort -u | diff -u - tar2.txt