Skip to content

Instantly share code, notes, and snippets.

@frafra
Last active March 30, 2022 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frafra/f19d2dd2e1389e2a6da4a304bfec656a to your computer and use it in GitHub Desktop.
Save frafra/f19d2dd2e1389e2a6da4a304bfec656a to your computer and use it in GitHub Desktop.
#!/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