mirror of
https://github.com/jessfraz/dockerfiles.git
synced 2024-11-27 04:16:45 +01:00
48 lines
1.2 KiB
Bash
48 lines
1.2 KiB
Bash
#!/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" -o -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
|
|
|
|
docker run $DASHT -i -u $(whoami) -w "$HOME" \
|
|
$(env | cut -d= -f1 | awk '{print "-e", $1}') \
|
|
$DEVICES $VOLUMES \
|
|
-v /etc/passwd:/etc/passwd:ro \
|
|
-v /etc/group:/etc/group:ro \
|
|
-v /etc/localtime:/etc/localtime:ro \
|
|
-v /home:/home \
|
|
"$@"
|
|
}
|