mirror of
https://gh.con.sh/https://github.com/plexinc/pms-docker
synced 2024-09-20 06:45:31 +00:00
Update to cater for multiple video device groups.
This commit is contained in:
parent
bf9f07626f
commit
0ce632c43f
|
@ -5,28 +5,27 @@ if [ ! -e /dev/dri ] && [ ! -e /dev/dvb ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
# Get the group ID for the dri or dvb devices.
|
||||
if [ -e /dev/dri ]; then
|
||||
DEVICE_GID=$(stat -c '%g' /dev/dri/* | grep -v '^0$' | head -n 1)
|
||||
else
|
||||
DEVICE_GID=$(stat -c '%g' /dev/dvb/adapter*/* | grep -v '^0$' | head -n 1)
|
||||
fi
|
||||
FILES=$(find /dev/dri /dev/dvb -type c -print 2>/dev/null)
|
||||
GROUP_COUNT=1
|
||||
|
||||
# Get the group ID for the video group
|
||||
VIDEO_GID=$(getent group video | awk -F: '{print $3}')
|
||||
for i in $FILES
|
||||
do
|
||||
# Get the group ID for the dri or dvb device.
|
||||
DEVICE_GID=$(stat -c '%g' "$i")
|
||||
# Get the group name (if it exists)
|
||||
CURRENT_GROUP=$(getent group "${DEVICE_GID}" | awk -F: '{print $1}')
|
||||
|
||||
# If the video group's ID matches the group ID of the device, exit as permissions are already setup.
|
||||
if [ "${DEVICE_GID}" == "${VIDEO_GID}" ]; then
|
||||
exit 0
|
||||
fi
|
||||
# If it doesn't exist, create a new group name and assign it to the device GID
|
||||
if [ -z "${CURRENT_GROUP}" ]; then
|
||||
CURRENT_GROUP=video${GROUP_COUNT}
|
||||
groupadd -g "${DEVICE_GID}" "${CURRENT_GROUP}"
|
||||
fi
|
||||
|
||||
# Get the current group name for the device's group ID
|
||||
CURRENT_GROUP=$(getent group ${DEVICE_GID} | awk -F: '{print $1}')
|
||||
# If plex user isn't part of this group, add them
|
||||
if [ ! $(getent group "${CURRENT_GROUP}" | grep &>/dev/null plex) ]; then
|
||||
usermod -a -G "${CURRENT_GROUP}" plex
|
||||
fi
|
||||
|
||||
GROUP_COUNT=$(($GROUP_COUNT + 1))
|
||||
done
|
||||
|
||||
if [ -z "${CURRENT_GROUP}" ]; then
|
||||
# If there is no group name for the device's group ID, change the video group to that ID.
|
||||
groupmod -g ${DEVICE_GID} video
|
||||
else
|
||||
# There is a group name, so add it to the plex user's list of groups
|
||||
usermod -a -G ${CURRENT_GROUP} plex
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue
Block a user