Add more devices, but only if they really exist

This commit is contained in:
Jerome Petazzoni 2015-07-30 16:03:28 -07:00
parent ae2529386d
commit 43c57f4f78

22
bashrc
View File

@ -13,13 +13,31 @@ command_not_found_handle () {
return return
fi 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
docker run -ti -u $(whoami) -w "$HOME" \ docker run -ti -u $(whoami) -w "$HOME" \
$(env | cut -d= -f1 | awk '{print "-e", $1}') \ $(env | cut -d= -f1 | awk '{print "-e", $1}') \
-v /dev/snd:/dev/snd \ $DEVICES $VOLUMES \
-v /etc/passwd:/etc/passwd:ro \ -v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \ -v /etc/group:/etc/group:ro \
-v /etc/localtime:/etc/localtime:ro \ -v /etc/localtime:/etc/localtime:ro \
-v /home:/home \ -v /home:/home \
-v /tmp/.X11-unix:/tmp/.X11-unix \
"$@" "$@"
} }