-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #416 from linuxserver/nonroot
- Loading branch information
Showing
5 changed files
with
84 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,37 @@ | ||
#!/usr/bin/with-contenv bash | ||
# shellcheck shell=bash | ||
|
||
FILES=$(find /dev/dri /dev/dvb -type c -print 2>/dev/null) | ||
if [[ -z ${LSIO_NON_ROOT_USER} ]]; then | ||
FILES=$(find /dev/dri /dev/dvb -type c -print 2>/dev/null) | ||
|
||
for i in ${FILES}; do | ||
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 | ||
for i in ${FILES}; do | ||
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 ****" | ||
# 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} ****" | ||
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 | ||
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 | ||
done | ||
done | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters