Only chown if datastore is not writable by PUID:PGID

pull/722/head
jeanluc 2024-11-09 11:01:55 +01:00
rodzic a1285f2238
commit 89c9ead2a0
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 3EB52D4C754CD898
1 zmienionych plików z 13 dodań i 2 usunięć

15
docker-entrypoint.sh 100644 → 100755
Wyświetl plik

@ -19,8 +19,19 @@ if [ "$(id -u)" = '0' -a -z "${KEEP_PRIVILEGES:-}" ]; then
groupmod -o -g "$PGID" changedetection
usermod -o -u "$PUID" changedetection
# Look for files in datadir not owned by the correct user and chown them
find "$DATASTORE_PATH" \! -user changedetection -exec chown changedetection '{}' +
# Check if the supplied uid/gid grants write permissions on the datastore
# root directory. Only if it does not, chown it recursively.
# In my testing, `test -w "$DATASTORE_PATH"` did not work reliably.
tempfile="$DATASTORE_PATH/.check-writable"
gosu changedetection:changedetection bash -c ">> '$tempfile'" &&
rm -f "$tempfile" ||
chown -R changedetection:changedetection "$DATASTORE_PATH" ||
(
echo "Failed to change permissions on $DATASTORE_PATH. Ensure it is writable by $PUID:$PGID" >&2
exit 1
)
# Ensure the home directory's permissions are adjusted as well.
chown -R changedetection:changedetection ~changedetection
# Restart this script as an unprivileged user