blob: 0147c272c73c618bd8fefe8c68d253bb5355b2e7 [file] [log] [blame]
#!/bin/bash
command_not_found_handle () {
# Check if there is a container image with that name
if ! docker inspect --format '{{ .Author }}' "$1" >&/dev/null; then
echo "$0: $1: command not found"
return
fi
# Check that it's really the name of the image, not a prefix
if docker inspect --format '{{ .Id }}' "$1" | grep -q "^$1" ;then
echo "$0: $1: command not found"
return
fi
# Add a bunch of (optional) devices
# (Don't add them unconditionally: if they don't exist, it
# would prevent the container from starting)
DEVICES=
for DEV in /dev/kvm /dev/ttyUSB* /dev/dri/* /dev/snd/*; do
if [ -b "$DEV" ] || [ -c "$DEV" ]; then
DEVICES="$DEVICES --device $DEV:$DEV"
fi
done
# And a few (optional) files
# (Here again, they don't always exist everywhere)
VOLUMES=
for VOL in /tmp/.X11-unix /run/user; do
if [ -e "$VOL" ]; then
VOLUMES="$VOLUMES --volume $VOL:$VOL"
fi
done
# Check if we are on a tty to decide whether to allocate one
DASHT=
tty -s && DASHT=-t
# shellcheck disable=SC2086
# shellcheck disable=SC2046
docker run $DASHT -i -u $(whoami) -w "$HOME" \
$(env | cut -d= -f1 | awk '{print "-e", $1}') \
$DOCKERFILES_RUN_FLAGS \
$DEVICES \
$VOLUMES \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
-v /etc/localtime:/etc/localtime:ro \
-v /home:/home \
"$@"
}