From 875eccd1bba01ff29ed0f79879ed3ff54bfbb2bd Mon Sep 17 00:00:00 2001 From: Rasmus Date: Mon, 19 Aug 2019 14:11:04 +0200 Subject: [PATCH] Only set permissions when needed This will speed up boot by only run chown when needed. Solution taken from https://github.com/linuxserver/docker-tvheadend/blob/master/root/etc/cont-init.d/30-config#L22 --- root/etc/cont-init.d/30-config | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/root/etc/cont-init.d/30-config b/root/etc/cont-init.d/30-config index 39d0c3c..d51e496 100644 --- a/root/etc/cont-init.d/30-config +++ b/root/etc/cont-init.d/30-config @@ -1,6 +1,27 @@ #!/usr/bin/with-contenv bash -# permissions -chown -R abc:abc \ - /app \ - /config +# function to randomly sample 5 files for their owner and only chown if not abc +chowner () { +files=(${1}/*) +for i in {1..5}; do + user=$(stat -c '%U' $(printf "%s\n" "${files[RANDOM % ${#files[@]}]}")) + if [ "${user}" != "abc" ]; then + chown -R abc:abc ${1} + break + fi +done +} + +# permissions +echo "Setting permissions" +abc_dirs=( \ +/app \ +/config \ +) +for i in "${abc_dirs[@]}"; do + if [ "$(ls -A ${i})" ]; then + chowner ${i} + else + chown -R abc:abc ${i} + fi +done