#!/bin/sh
set -eu
export LC_ALL=C.UTF-8
if [ ! -e "tar1.txt" ]; then
  echo "E: tar1.txt doesn't exist -- run create-directory test first" >&2
  exit 1
fi
trap "rm -rf /tmp/debian-chroot" EXIT INT TERM
{{ CMD }} --mode=root --variant=apt --include=doc-debian --include=tzdata {{ DIST }} /tmp/debian-chroot {{ MIRROR }}
rm /tmp/debian-chroot/usr/share/doc-base/doc-debian.debian-*
rm -r /tmp/debian-chroot/usr/share/doc/debian
rm -r /tmp/debian-chroot/usr/share/doc/doc-debian
rm /tmp/debian-chroot/usr/share/lintian/overrides/tzdata
rm /tmp/debian-chroot/etc/localtime
# tzdata 2024b-5 does not create /etc/timezone anymore #822733
case {{ DIST }} in oldstable) rm /tmp/debian-chroot/etc/timezone ;; esac
rm -r /tmp/debian-chroot/usr/share/doc/tzdata
rm -r /tmp/debian-chroot/usr/share/zoneinfo
for p in doc-debian tzdata; do
  for f in list md5sums config postinst postrm templates preinst prerm; do
    [ -e "/tmp/debian-chroot/var/lib/dpkg/info/$p.$f" ] || continue
    rm "/tmp/debian-chroot/var/lib/dpkg/info/$p.$f"
  done
done
tar -C /tmp/debian-chroot --one-file-system -c . | {
  tar -t
  echo ./dev/console
  echo ./dev/fd
  echo ./dev/full
  echo ./dev/null
  echo ./dev/ptmx
  echo ./dev/pts/
  echo ./dev/random
  echo ./dev/shm/
  echo ./dev/stderr
  echo ./dev/stdin
  echo ./dev/stdout
  echo ./dev/tty
  echo ./dev/urandom
  echo ./dev/zero
} | sort -u | diff -u tar1.txt -
