#!/bin/sh

set -eu

here="$(dirname "$0")"
here="$(readlink -f "$here")"

cd "${AUTOPKGTEST_TMP:-"${ADTTMP}"}"

mkdir webroot
"$here/test-webserver.sh" webroot

truncate -s10M webroot/filesystem.img
/sbin/mkfs.vfat webroot/filesystem.img
bmaptool create webroot/filesystem.img > webroot/filesystem.img.bmap
cat webroot/filesystem.img.bmap

bmaptool copy webroot/filesystem.img filesystem.out
diff -s webroot/filesystem.img filesystem.out

gzip -9n webroot/filesystem.img
bmaptool copy "$(cat httpd-address)/filesystem.img.gz" filesystem.out2
diff -s filesystem.out filesystem.out2

kill "$(cat httpd-pid)"
