From 8b587505c3bc684874d450844f0b5508b574fa20 Mon Sep 17 00:00:00 2001 From: RandomNinjaAtk Date: Sat, 19 Nov 2022 17:34:55 -0500 Subject: [PATCH] Update 34-enable-hw.bash --- root/etc/cont-init.d/34-enable-hw.bash | 49 +++++++++++++++----------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/root/etc/cont-init.d/34-enable-hw.bash b/root/etc/cont-init.d/34-enable-hw.bash index 2a76e77..c07fe60 100644 --- a/root/etc/cont-init.d/34-enable-hw.bash +++ b/root/etc/cont-init.d/34-enable-hw.bash @@ -1,26 +1,35 @@ #!/usr/bin/with-contenv bash -## hardware support ## -FILES=$(find /dev/dri -type c -print 2>/dev/null) +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 - 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 + VIDEO_GID=$(stat -c '%g' "${i}") + VIDEO_UID=$(stat -c '%u' "${i}") + # check if user matches device + if id -u abc | grep -qw "${VIDEO_UID}"; then + echo "**** permissions for ${i} are good ****" + else + # check if group matches and that device has group rw + if id -G abc | grep -qw "${VIDEO_GID}" && [ $(stat -c '%A' "${i}" | cut -b 5,6) = "rw" ]; then + echo "**** permissions for ${i} are good ****" + # check if device needs to be added to video group + elif ! id -G abc | grep -qw "${VIDEO_GID}"; then + # check if video group needs to be created + VIDEO_NAME=$(getent group "${VIDEO_GID}" | awk -F: '{print $1}') + if [ -z "${VIDEO_NAME}" ]; then + VIDEO_NAME="video$(head /dev/urandom | tr -dc 'a-z0-9' | head -c4)" + groupadd "${VIDEO_NAME}" + groupmod -g "${VIDEO_GID}" "${VIDEO_NAME}" + echo "**** creating video group ${VIDEO_NAME} with id ${VIDEO_GID} ****" + fi + echo "**** adding ${i} to video group ${VIDEO_NAME} with id ${VIDEO_GID} ****" + usermod -a -G "${VIDEO_NAME}" abc + fi + # check if device has group rw + if [ $(stat -c '%A' "${i}" | cut -b 5,6) != "rw" ]; then + echo -e "**** The device ${i} does not have group read/write permissions, attempting to fix inside the container. ****" + chmod g+rw "${i}" + fi fi - fi done -if [ -n "${FILES}" ] && [ ! -f "/groupadd" ]; then - usermod -a -G root abc -fi -exit 0