#!/bin/bash
set -e

# These tests can run in/outside of a container.  However,
# not all storage drivers are supported in a container
# environment.  Detect this and setup storage when
# running in a container.
if ((SKOPEO_CONTAINER_TESTS)) && [[ -r /etc/containers/storage.conf ]]; then
    sed -i \
        -e 's/^driver\s*=.*/driver = "vfs"/' \
        -e 's/^mountopt/#mountopt/' \
        /etc/containers/storage.conf
elif ((SKOPEO_CONTAINER_TESTS)); then
    cat >> /etc/containers/storage.conf << EOF
[storage]
driver = "vfs"
EOF
fi

# Build skopeo, install into /usr/bin
make PREFIX=/usr install

# Run tests
SKOPEO_BINARY=/usr/bin/skopeo bats --tap systemtest
