dockerfiles/bashrc
Jess Frazelle f37b405511
update
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
2018-09-24 19:47:53 -04:00

52 lines
1.3 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" ] || [ -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 \
"$@"
}