#!/bin/sh
set -eu

IMAGE="${1:-registry.fedoraproject.org/fedora:latest}"

podman run --interactive --rm --privileged -v "$(pwd):/src" -w /src "$IMAGE" <<EOF
set -eux

# overlayfs does not support fanotify
mount -t tmpfs tmpfs /tmp

if type apt >/dev/null 2>&1; then
    apt-get update
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends gcc libc-dev make python3 btrfs-progs
else
    dnf install -y gcc glibc-devel make python3 util-linux btrfs-progs
fi

make

python3 -m unittest -v || {
    if [ -n "${DEBUG:-}" ]; then
        echo "Tests failed; run this to debug: podman exec -itl bash"
        sleep infinity
    fi
    exit 1
}
EOF
