|
3 | 3 |
|
4 | 4 | FILES=$(find /dev/dri /dev/dvb /dev/vchiq /dev/vc-mem /dev/video1? -type c -print 2>/dev/null)
|
5 | 5 |
|
6 |
| -for i in $FILES |
7 |
| -do |
8 |
| - VIDEO_GID=$(stat -c '%g' "$i") |
9 |
| - if ! id -G abc | grep -qw "$VIDEO_GID"; then |
10 |
| - VIDEO_NAME=$(getent group "${VIDEO_GID}" | awk -F: '{print $1}') |
11 |
| - if [[ -z "${VIDEO_NAME}" ]]; then |
12 |
| - VIDEO_NAME="video$(head /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c8)" |
13 |
| - groupadd "$VIDEO_NAME" |
14 |
| - groupmod -g "$VIDEO_GID" "$VIDEO_NAME" |
| 6 | +for i in ${FILES}; do |
| 7 | + VIDEO_GID=$(stat -c '%g' "${i}") |
| 8 | + VIDEO_UID=$(stat -c '%u' "${i}") |
| 9 | + # check if user matches device |
| 10 | + if id -u abc | grep -qw "${VIDEO_UID}"; then |
| 11 | + echo "**** permissions for ${i} are good ****" |
| 12 | + else |
| 13 | + # check if group matches and that device has group rw |
| 14 | + if id -G abc | grep -qw "${VIDEO_GID}" && [[ $(stat -c '%A' "${i}" | cut -b 5,6) == "rw" ]]; then |
| 15 | + echo "**** permissions for ${i} are good ****" |
| 16 | + # check if device needs to be added to video group |
| 17 | + elif ! id -G abc | grep -qw "${VIDEO_GID}"; then |
| 18 | + # check if video group needs to be created |
| 19 | + VIDEO_NAME=$(getent group "${VIDEO_GID}" | awk -F: '{print $1}') |
| 20 | + if [[ -z "${VIDEO_NAME}" ]]; then |
| 21 | + VIDEO_NAME="video$(head /dev/urandom | tr -dc 'a-z0-9' | head -c4)" |
| 22 | + groupadd "${VIDEO_NAME}" |
| 23 | + groupmod -g "${VIDEO_GID}" "${VIDEO_NAME}" |
| 24 | + echo "**** creating video group ${VIDEO_NAME} with id ${VIDEO_GID} ****" |
| 25 | + fi |
| 26 | + echo "**** adding ${i} to video group ${VIDEO_NAME} with id ${VIDEO_GID} ****" |
| 27 | + usermod -a -G "${VIDEO_NAME}" abc |
15 | 28 | fi
|
16 |
| - usermod -a -G "$VIDEO_NAME" abc |
17 |
| - if [ $(stat -c '%A' "${i}" | cut -b 5,6) != "rw" ]; then |
18 |
| - echo -e "**** The device ${i} does not have group read/write permissions, which might prevent hardware transcode from functioning correctly. To fix it, you can run the following on your docker host: ****\nsudo chmod g+rw ${i}\n" |
| 29 | + # check if device has group rw |
| 30 | + if [[ $(stat -c '%A' "${i}" | cut -b 5,6) != "rw" ]]; then |
| 31 | + echo -e "**** The device ${i} does not have group read/write permissions, attempting to fix inside the container. ****" |
| 32 | + chmod g+rw "${i}" |
19 | 33 | fi
|
20 | 34 | fi
|
21 | 35 | done
|
|
0 commit comments