Skip to content

Commit

Permalink
Improve permission fixing on render & dvb devices
Browse files Browse the repository at this point in the history
  • Loading branch information
aptalca authored and thelamer committed Oct 2, 2019
1 parent 9a7b46c commit 70b794c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64

## Versions

* **02.10.19:** - Improve permission fixing on render & dvb devices.
* **18.08.19:** - Add AMD drivers.
* **02.08.19:** - Attempt to automatically fix permissions on /dev/dri and /dev/dvb.
* **28.06.19:** - Rebasing to alpine 3.10.
Expand Down
1 change: 1 addition & 0 deletions readme-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ app_setup_block: |
# changelog
changelogs:
- { date: "02.10.19:", desc: "Improve permission fixing on render & dvb devices." }
- { date: "18.08.19:", desc: "Add AMD drivers." }
- { date: "02.08.19:", desc: "Attempt to automatically fix permissions on /dev/dri and /dev/dvb." }
- { date: "28.06.19:", desc: "Rebasing to alpine 3.10." }
Expand Down
48 changes: 20 additions & 28 deletions root/etc/cont-init.d/50-gid-video
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
#!/usr/bin/with-contenv bash

# check for the existence of a video and/or tuner device
if [ -e /dev/dri ] || [ -e /dev/dvb ]; then
if [ -e /dev/dri ]; then
VIDEO_GID=$(stat -c '%g' /dev/dri/* | grep -v '^0$' | head -n 1)
FILES=$(find /dev/dri /dev/dvb -type c -print 2>/dev/null)

for i in $FILES
do
VIDEO_GID=$(stat -c '%g' "$i")
if id -G abc | grep -qw "$VIDEO_GID"; then
touch /groupadd
else
VIDEO_GID=$(stat -c '%g' /dev/dvb/* | grep -v '^0$' | head -n 1)
fi
# just add abc to root if stuff in dri/dvb is root owned
if [ -z "${VIDEO_GID}" ]; then
usermod -a -G root abc
exit 0
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)"

This comment has been minimized.

Copy link
@bernhardberger

bernhardberger Oct 19, 2019

Contributor

I think this needs to be changed to:
VIDEO_NAME="video$(head /dev/urandom | tr -dc 'a-za-z0-9' | head -c8)"

I'm pretty sure that's the allowed pattern for group names: [_a-z][-0-9_a-z]

groupadd "$VIDEO_NAME"
groupmod -g "$VIDEO_GID" "$VIDEO_NAME"
fi
usermod -a -G "$VIDEO_NAME" abc
touch /groupadd
fi
fi
else
exit 0
fi

# 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
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

0 comments on commit 70b794c

Please sign in to comment.