#!/bin/bash -e

CRI=(podman)
CRI_OPT=()

if [ -z "$WAYLAND_DISPLAY" ]; then
    CRI_OPT+=(
        --network=host
        -e XAUTHORITY=/app/.Xauthority
        -v "$XAUTHORITY:/app/.Xauthority:ro"
    )
fi

"${CRI[@]}" run --rm -it --name epitest            \
    "${CRI_OPT[@]}"                                \
    --ipc=host                                     \
    --device /dev/dri/                             \
    -e DISPLAY                                     \
    -e XDG_RUNTIME_DIR                             \
    -e MAKEFLAGS                                   \
    -e CFLAGS=-g3                                  \
    -e CXXFLAGS=-g3                                \
    -v /tmp/.X11-unix/:/tmp/.X11-unix/             \
    -v "$XDG_RUNTIME_DIR:$XDG_RUNTIME_DIR"         \
    -v /usr/share/fonts/:/usr/share/fonts/:ro      \
    -v "$PWD:$PWD"                                 \
    -w "$PWD"                                      \
    docker.io/epitechcontent/epitest-docker:latest \
    "$@"
