From baa34948d86fc9ca99b06af42a3035aaacef60ad Mon Sep 17 00:00:00 2001 From: aptalca Date: Wed, 18 Sep 2019 11:32:00 -0400 Subject: [PATCH] improve logic for root owned devices --- root/etc/cont-init.d/50-gid-video | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/root/etc/cont-init.d/50-gid-video b/root/etc/cont-init.d/50-gid-video index 96736a1..74e8050 100755 --- a/root/etc/cont-init.d/50-gid-video +++ b/root/etc/cont-init.d/50-gid-video @@ -15,10 +15,10 @@ fi for i in $FILES do VIDEO_GID=$(stat -c '%g' "$i") - if ! id -G abc | grep -qw "$VIDEO_GID"; then - if [ "${VIDEO_GID}" == '0' ]; then - usermod -a -G root abc - else + 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 0-9 | head -c4)" @@ -26,6 +26,11 @@ do groupmod -g "$VIDEO_GID" "$VIDEO_NAME" fi usermod -a -G "$VIDEO_NAME" abc + touch /groupadd fi fi -done \ No newline at end of file +done + +if [ ! -z "${FILES}" ] && [ ! -f "/groupadd" ]; then + usermod -a -G root abc +fi \ No newline at end of file