Last active
March 30, 2022 08:16
-
-
Save frafra/f19d2dd2e1389e2a6da4a304bfec656a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Build a container with the required command and run it | |
set -euo pipefail | |
docker_like() { | |
if command -v podman &> /dev/null | |
then | |
podman "$@" | |
elif command -v rootlesskit &> /dev/null | |
then | |
rootlesskit docker "$@" | |
elif command -v docker &> /dev/null | |
then | |
docker "$@" | |
else | |
echo "Cannot run $@" | |
fi | |
} | |
run_in_container() { | |
exe=$1 | |
docker_like build --tag $exe --build-arg exe=$exe - <<- 'EOF' | |
FROM fedora:36 | |
ARG exe | |
RUN dnf install -y $(dnf provides -q {/usr/bin,/usr/sbin}/$exe | awk '{ if (NR%5==1) pkg=$1 } END { print pkg }') | |
EOF | |
docker_like run --rm -it \ | |
-e DISPLAY \ | |
-v $XAUTHORITY:/root/.Xauthority -v /tmp/.X11-unix:/tmp/.X11-unix \ | |
-v $HOME:/root --workdir /root $exe "$@" | |
} | |
run_in_container "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment