Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/init-device-perms/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

if [[ -z ${LSIO_NON_ROOT_USER} ]] && [[ -n ${ATTACHED_DEVICES_PERMS} ]]; then
FILES=$(find ${ATTACHED_DEVICES_PERMS} -print 2>/dev/null)

for i in ${FILES}; do
FILE_GID=$(stat -c '%g' "${i}")
FILE_UID=$(stat -c '%u' "${i}")
# check if user matches device
if id -u abc | grep -qw "${FILE_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 "${FILE_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 group
elif ! id -G abc | grep -qw "${FILE_GID}"; then
# check if group needs to be created
GROUP_NAME=$(getent group "${FILE_GID}" | awk -F: '{print $1}')
if [[ -z "${GROUP_NAME}" ]]; then
GROUP_NAME="group$(head /dev/urandom | tr -dc 'a-z0-9' | head -c4)"
groupadd "${GROUP_NAME}"
groupmod -g "${FILE_GID}" "${GROUP_NAME}"
echo "**** creating group ${GROUP_NAME} with id ${FILE_GID} ****"
fi
echo "**** adding ${i} to group ${GROUP_NAME} with id ${FILE_GID} ****"
usermod -a -G "${GROUP_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
fi
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-device-perms/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-device-perms/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-device-perms/run
Empty file.
Empty file.