2019-02-06 12:16:30 -08:00
#!/usr/bin/with-contenv bash
2019-09-18 17:27:28 -07:00
FILES=$(find /dev/dri /dev/dvb -type c -print 2>/dev/null)
2019-02-06 12:16:30 -08:00
2019-09-17 12:55:06 -04:00
for i in $FILES
do
2022-03-04 14:40:34 -05:00
VIDEO_GID=$(stat -c '%g' "${i}")
VIDEO_UID=$(stat -c '%u' "${i}")
# check if user matches device
if id -u abc | grep -qw "${VIDEO_UID}"; then
echo "**** permissions for ${i} are good ****"
else
# check if group matches and that device has group rw
if id -G abc | grep -qw "${VIDEO_GID}" && [ $(stat -c '%A' "${i}" | cut -b 5,6) = "rw" ]; then
echo "**** permissions for ${i} are good ****"
# check if device needs to be added to video group
elif ! id -G abc | grep -qw "${VIDEO_GID}"; then
# check if video group needs to be created
VIDEO_NAME=$(getent group "${VIDEO_GID}" | awk -F: '{print $1}')
if [ -z "${VIDEO_NAME}" ]; then
VIDEO_NAME="video$(head /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c8)"
groupadd "${VIDEO_NAME}"
groupmod -g "${VIDEO_GID}" "${VIDEO_NAME}"
echo "**** creating video group ${VIDEO_NAME} with id ${VIDEO_GID} ****"
fi
echo "**** adding ${i} to video group ${VIDEO_NAME} with id ${VIDEO_GID} ****"
usermod -a -G "${VIDEO_NAME}" abc
2021-12-25 14:24:10 -05:00
fi
2022-03-04 14:40:34 -05:00
# check if device has group rw
2021-12-25 14:24:10 -05:00
if [ $(stat -c '%A' "${i}" | cut -b 5,6) != "rw" ]; then
2022-03-04 14:40:34 -05:00
echo -e "**** The device ${i} does not have group read/write permissions, attempting to fix inside the container.If it doesn't work, you can run the following on your docker host: ****\nsudo chmod g+rw ${i}\n"
chmod g+rw "${i}"
2021-12-25 14:24:10 -05:00
fi
fi
2019-09-18 11:32:00 -04:00
done