Improve permission fixing for render & dvb devices

This commit is contained in:
aptalca
2019-10-02 12:49:38 -04:00
committed by Ryan Kuba
parent f5de72e0bf
commit 10471d1275
3 changed files with 23 additions and 20 deletions

View File

@@ -1,25 +1,26 @@
#!/usr/bin/with-contenv bash
# Check for the existence of the Intel video device
if [ -e /dev/dri ]; then
VIDEO_GID=$(stat -c '%g' /dev/dri/* | grep -v '^0$' | head -n 1)
else
exit 0
fi
FILES=$(find /dev/dri /dev/dvb -type c -print 2>/dev/null)
# Check if this GID matches the current abc user
ABCGID=$(getent group abc | awk -F: '{print $3}')
if [ "${ABCGID}" == "${VIDEO_GID}" ]; then
exit 0
fi
for i in $FILES
do
VIDEO_GID=$(stat -c '%g' "$i")
if id -G abc | grep -qw "$VIDEO_GID"; then
touch /groupadd
else
if [ ! "${VIDEO_GID}" == '0' ]; then
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"
fi
usermod -a -G "$VIDEO_NAME" abc
touch /groupadd
fi
fi
done
# Check if the GID is taken and swap to 65533
CURRENT=$(getent group ${VIDEO_GID} | awk -F: '{print $1}')
if [ -z "${CURRENT}" ] || [ "${CURRENT}" == 'video' ]; then
groupmod -g ${VIDEO_GID} video
usermod -a -G video abc
else
groupmod -g 65533 ${CURRENT}
groupmod -g ${VIDEO_GID} video
usermod -a -G video abc
if [ -n "${FILES}" ] && [ ! -f "/groupadd" ]; then
usermod -a -G root abc
fi