mirror of
https://gh.con.sh/https://github.com/plexinc/pms-docker
synced 2024-09-20 06:45:31 +00:00
36 lines
936 B
Bash
Executable File
36 lines
936 B
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
IFS=$'\n\t'
|
|
|
|
DEBUG=${DEBUG:-}
|
|
|
|
# Check to make sure the devices exists. If not, exit as there is nothing for us to do
|
|
if [ ! -e /dev/dri ] && [ ! -e /dev/dvb ]; then
|
|
exit 0
|
|
fi
|
|
|
|
FILES=$(find /dev/dri /dev/dvb -type c -print 2>/dev/null)
|
|
GROUP_COUNT=1
|
|
|
|
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 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
|
|
|
|
# If plex user isn't part of this group, add them
|
|
if ! getent group "${CURRENT_GROUP}" | grep -q plex; then
|
|
usermod -a -G "${CURRENT_GROUP}" plex
|
|
fi
|
|
|
|
GROUP_COUNT=$((GROUP_COUNT + 1))
|
|
done
|
|
|