From 5aca29c35e3ff12eab375dd41dc5d14c741cf438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Maldonado?= Date: Thu, 14 Nov 2024 18:07:11 +0100 Subject: [PATCH] fix: change owner after initialization Currently, the `docker-run.sh` script updates ownership for files in `/var/www/documents`, but more files get added to that directory after the ownership update, so the new files may have a bad owner. This commit moves the code handling the ownership update to a later point, when all files have been copied to /var/www/documents. --- docker-run.sh | 32 +++++++++++++++--------------- images/15.0.3-php7.4/docker-run.sh | 32 +++++++++++++++--------------- images/16.0.5-php8.1/docker-run.sh | 32 +++++++++++++++--------------- images/17.0.4-php8.1/docker-run.sh | 32 +++++++++++++++--------------- images/18.0.6-php8.1/docker-run.sh | 32 +++++++++++++++--------------- images/19.0.4-php8.2/docker-run.sh | 32 +++++++++++++++--------------- images/20.0.2-php8.2/docker-run.sh | 32 +++++++++++++++--------------- images/develop/docker-run.sh | 32 +++++++++++++++--------------- 8 files changed, 128 insertions(+), 128 deletions(-) diff --git a/docker-run.sh b/docker-run.sh index 5fc2048..10fa974 100755 --- a/docker-run.sh +++ b/docker-run.sh @@ -32,11 +32,6 @@ function get_env_value() { # Function to create directories, create conf.php file and set permissions on files function initDolibarr() { - local CURRENT_UID=$(id -u www-data) - local CURRENT_GID=$(id -g www-data) - usermod -u ${WWW_USER_ID} www-data - groupmod -g ${WWW_GROUP_ID} www-data - if [[ ! -d /var/www/documents ]]; then echo "[INIT] => create volume directory /var/www/documents ..." mkdir -p /var/www/documents @@ -109,16 +104,6 @@ EOF else chmod 400 /var/www/html/conf/conf.php fi - - if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then - # Refresh file ownership cause it has changed - echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." - chown -R www-data:www-data /var/www - else - # Reducing load on init : change ownership only for volumes declared in docker - echo "[INIT] => update ownership for files in /var/www/documents ..." - chown -R www-data:www-data /var/www/documents - fi } @@ -416,7 +401,22 @@ function run() # Run scripts before starting runScripts "before-starting.d" - + + local CURRENT_UID=$(id -u www-data) + local CURRENT_GID=$(id -g www-data) + usermod -u ${WWW_USER_ID} www-data + groupmod -g ${WWW_GROUP_ID} www-data + + if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then + # Refresh file ownership cause it has changed + echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." + chown -R www-data:www-data /var/www + else + # Reducing load on init : change ownership only for volumes declared in docker + echo "[INIT] => update ownership for files in /var/www/documents ..." + chown -R www-data:www-data /var/www/documents + fi + echo "*** You can connect to the docker Mariadb with:" echo "sudo docker exec -it nameofmariadbcontainer bash" echo "mysql -uroot -p'MYSQL_ROOT_PASSWORD' -h localhost" diff --git a/images/15.0.3-php7.4/docker-run.sh b/images/15.0.3-php7.4/docker-run.sh index 5fc2048..10fa974 100755 --- a/images/15.0.3-php7.4/docker-run.sh +++ b/images/15.0.3-php7.4/docker-run.sh @@ -32,11 +32,6 @@ function get_env_value() { # Function to create directories, create conf.php file and set permissions on files function initDolibarr() { - local CURRENT_UID=$(id -u www-data) - local CURRENT_GID=$(id -g www-data) - usermod -u ${WWW_USER_ID} www-data - groupmod -g ${WWW_GROUP_ID} www-data - if [[ ! -d /var/www/documents ]]; then echo "[INIT] => create volume directory /var/www/documents ..." mkdir -p /var/www/documents @@ -109,16 +104,6 @@ EOF else chmod 400 /var/www/html/conf/conf.php fi - - if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then - # Refresh file ownership cause it has changed - echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." - chown -R www-data:www-data /var/www - else - # Reducing load on init : change ownership only for volumes declared in docker - echo "[INIT] => update ownership for files in /var/www/documents ..." - chown -R www-data:www-data /var/www/documents - fi } @@ -416,7 +401,22 @@ function run() # Run scripts before starting runScripts "before-starting.d" - + + local CURRENT_UID=$(id -u www-data) + local CURRENT_GID=$(id -g www-data) + usermod -u ${WWW_USER_ID} www-data + groupmod -g ${WWW_GROUP_ID} www-data + + if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then + # Refresh file ownership cause it has changed + echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." + chown -R www-data:www-data /var/www + else + # Reducing load on init : change ownership only for volumes declared in docker + echo "[INIT] => update ownership for files in /var/www/documents ..." + chown -R www-data:www-data /var/www/documents + fi + echo "*** You can connect to the docker Mariadb with:" echo "sudo docker exec -it nameofmariadbcontainer bash" echo "mysql -uroot -p'MYSQL_ROOT_PASSWORD' -h localhost" diff --git a/images/16.0.5-php8.1/docker-run.sh b/images/16.0.5-php8.1/docker-run.sh index 5fc2048..10fa974 100755 --- a/images/16.0.5-php8.1/docker-run.sh +++ b/images/16.0.5-php8.1/docker-run.sh @@ -32,11 +32,6 @@ function get_env_value() { # Function to create directories, create conf.php file and set permissions on files function initDolibarr() { - local CURRENT_UID=$(id -u www-data) - local CURRENT_GID=$(id -g www-data) - usermod -u ${WWW_USER_ID} www-data - groupmod -g ${WWW_GROUP_ID} www-data - if [[ ! -d /var/www/documents ]]; then echo "[INIT] => create volume directory /var/www/documents ..." mkdir -p /var/www/documents @@ -109,16 +104,6 @@ EOF else chmod 400 /var/www/html/conf/conf.php fi - - if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then - # Refresh file ownership cause it has changed - echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." - chown -R www-data:www-data /var/www - else - # Reducing load on init : change ownership only for volumes declared in docker - echo "[INIT] => update ownership for files in /var/www/documents ..." - chown -R www-data:www-data /var/www/documents - fi } @@ -416,7 +401,22 @@ function run() # Run scripts before starting runScripts "before-starting.d" - + + local CURRENT_UID=$(id -u www-data) + local CURRENT_GID=$(id -g www-data) + usermod -u ${WWW_USER_ID} www-data + groupmod -g ${WWW_GROUP_ID} www-data + + if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then + # Refresh file ownership cause it has changed + echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." + chown -R www-data:www-data /var/www + else + # Reducing load on init : change ownership only for volumes declared in docker + echo "[INIT] => update ownership for files in /var/www/documents ..." + chown -R www-data:www-data /var/www/documents + fi + echo "*** You can connect to the docker Mariadb with:" echo "sudo docker exec -it nameofmariadbcontainer bash" echo "mysql -uroot -p'MYSQL_ROOT_PASSWORD' -h localhost" diff --git a/images/17.0.4-php8.1/docker-run.sh b/images/17.0.4-php8.1/docker-run.sh index 5fc2048..10fa974 100755 --- a/images/17.0.4-php8.1/docker-run.sh +++ b/images/17.0.4-php8.1/docker-run.sh @@ -32,11 +32,6 @@ function get_env_value() { # Function to create directories, create conf.php file and set permissions on files function initDolibarr() { - local CURRENT_UID=$(id -u www-data) - local CURRENT_GID=$(id -g www-data) - usermod -u ${WWW_USER_ID} www-data - groupmod -g ${WWW_GROUP_ID} www-data - if [[ ! -d /var/www/documents ]]; then echo "[INIT] => create volume directory /var/www/documents ..." mkdir -p /var/www/documents @@ -109,16 +104,6 @@ EOF else chmod 400 /var/www/html/conf/conf.php fi - - if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then - # Refresh file ownership cause it has changed - echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." - chown -R www-data:www-data /var/www - else - # Reducing load on init : change ownership only for volumes declared in docker - echo "[INIT] => update ownership for files in /var/www/documents ..." - chown -R www-data:www-data /var/www/documents - fi } @@ -416,7 +401,22 @@ function run() # Run scripts before starting runScripts "before-starting.d" - + + local CURRENT_UID=$(id -u www-data) + local CURRENT_GID=$(id -g www-data) + usermod -u ${WWW_USER_ID} www-data + groupmod -g ${WWW_GROUP_ID} www-data + + if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then + # Refresh file ownership cause it has changed + echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." + chown -R www-data:www-data /var/www + else + # Reducing load on init : change ownership only for volumes declared in docker + echo "[INIT] => update ownership for files in /var/www/documents ..." + chown -R www-data:www-data /var/www/documents + fi + echo "*** You can connect to the docker Mariadb with:" echo "sudo docker exec -it nameofmariadbcontainer bash" echo "mysql -uroot -p'MYSQL_ROOT_PASSWORD' -h localhost" diff --git a/images/18.0.6-php8.1/docker-run.sh b/images/18.0.6-php8.1/docker-run.sh index 5fc2048..10fa974 100755 --- a/images/18.0.6-php8.1/docker-run.sh +++ b/images/18.0.6-php8.1/docker-run.sh @@ -32,11 +32,6 @@ function get_env_value() { # Function to create directories, create conf.php file and set permissions on files function initDolibarr() { - local CURRENT_UID=$(id -u www-data) - local CURRENT_GID=$(id -g www-data) - usermod -u ${WWW_USER_ID} www-data - groupmod -g ${WWW_GROUP_ID} www-data - if [[ ! -d /var/www/documents ]]; then echo "[INIT] => create volume directory /var/www/documents ..." mkdir -p /var/www/documents @@ -109,16 +104,6 @@ EOF else chmod 400 /var/www/html/conf/conf.php fi - - if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then - # Refresh file ownership cause it has changed - echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." - chown -R www-data:www-data /var/www - else - # Reducing load on init : change ownership only for volumes declared in docker - echo "[INIT] => update ownership for files in /var/www/documents ..." - chown -R www-data:www-data /var/www/documents - fi } @@ -416,7 +401,22 @@ function run() # Run scripts before starting runScripts "before-starting.d" - + + local CURRENT_UID=$(id -u www-data) + local CURRENT_GID=$(id -g www-data) + usermod -u ${WWW_USER_ID} www-data + groupmod -g ${WWW_GROUP_ID} www-data + + if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then + # Refresh file ownership cause it has changed + echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." + chown -R www-data:www-data /var/www + else + # Reducing load on init : change ownership only for volumes declared in docker + echo "[INIT] => update ownership for files in /var/www/documents ..." + chown -R www-data:www-data /var/www/documents + fi + echo "*** You can connect to the docker Mariadb with:" echo "sudo docker exec -it nameofmariadbcontainer bash" echo "mysql -uroot -p'MYSQL_ROOT_PASSWORD' -h localhost" diff --git a/images/19.0.4-php8.2/docker-run.sh b/images/19.0.4-php8.2/docker-run.sh index 5fc2048..10fa974 100755 --- a/images/19.0.4-php8.2/docker-run.sh +++ b/images/19.0.4-php8.2/docker-run.sh @@ -32,11 +32,6 @@ function get_env_value() { # Function to create directories, create conf.php file and set permissions on files function initDolibarr() { - local CURRENT_UID=$(id -u www-data) - local CURRENT_GID=$(id -g www-data) - usermod -u ${WWW_USER_ID} www-data - groupmod -g ${WWW_GROUP_ID} www-data - if [[ ! -d /var/www/documents ]]; then echo "[INIT] => create volume directory /var/www/documents ..." mkdir -p /var/www/documents @@ -109,16 +104,6 @@ EOF else chmod 400 /var/www/html/conf/conf.php fi - - if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then - # Refresh file ownership cause it has changed - echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." - chown -R www-data:www-data /var/www - else - # Reducing load on init : change ownership only for volumes declared in docker - echo "[INIT] => update ownership for files in /var/www/documents ..." - chown -R www-data:www-data /var/www/documents - fi } @@ -416,7 +401,22 @@ function run() # Run scripts before starting runScripts "before-starting.d" - + + local CURRENT_UID=$(id -u www-data) + local CURRENT_GID=$(id -g www-data) + usermod -u ${WWW_USER_ID} www-data + groupmod -g ${WWW_GROUP_ID} www-data + + if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then + # Refresh file ownership cause it has changed + echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." + chown -R www-data:www-data /var/www + else + # Reducing load on init : change ownership only for volumes declared in docker + echo "[INIT] => update ownership for files in /var/www/documents ..." + chown -R www-data:www-data /var/www/documents + fi + echo "*** You can connect to the docker Mariadb with:" echo "sudo docker exec -it nameofmariadbcontainer bash" echo "mysql -uroot -p'MYSQL_ROOT_PASSWORD' -h localhost" diff --git a/images/20.0.2-php8.2/docker-run.sh b/images/20.0.2-php8.2/docker-run.sh index 5fc2048..10fa974 100755 --- a/images/20.0.2-php8.2/docker-run.sh +++ b/images/20.0.2-php8.2/docker-run.sh @@ -32,11 +32,6 @@ function get_env_value() { # Function to create directories, create conf.php file and set permissions on files function initDolibarr() { - local CURRENT_UID=$(id -u www-data) - local CURRENT_GID=$(id -g www-data) - usermod -u ${WWW_USER_ID} www-data - groupmod -g ${WWW_GROUP_ID} www-data - if [[ ! -d /var/www/documents ]]; then echo "[INIT] => create volume directory /var/www/documents ..." mkdir -p /var/www/documents @@ -109,16 +104,6 @@ EOF else chmod 400 /var/www/html/conf/conf.php fi - - if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then - # Refresh file ownership cause it has changed - echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." - chown -R www-data:www-data /var/www - else - # Reducing load on init : change ownership only for volumes declared in docker - echo "[INIT] => update ownership for files in /var/www/documents ..." - chown -R www-data:www-data /var/www/documents - fi } @@ -416,7 +401,22 @@ function run() # Run scripts before starting runScripts "before-starting.d" - + + local CURRENT_UID=$(id -u www-data) + local CURRENT_GID=$(id -g www-data) + usermod -u ${WWW_USER_ID} www-data + groupmod -g ${WWW_GROUP_ID} www-data + + if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then + # Refresh file ownership cause it has changed + echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." + chown -R www-data:www-data /var/www + else + # Reducing load on init : change ownership only for volumes declared in docker + echo "[INIT] => update ownership for files in /var/www/documents ..." + chown -R www-data:www-data /var/www/documents + fi + echo "*** You can connect to the docker Mariadb with:" echo "sudo docker exec -it nameofmariadbcontainer bash" echo "mysql -uroot -p'MYSQL_ROOT_PASSWORD' -h localhost" diff --git a/images/develop/docker-run.sh b/images/develop/docker-run.sh index 5fc2048..10fa974 100755 --- a/images/develop/docker-run.sh +++ b/images/develop/docker-run.sh @@ -32,11 +32,6 @@ function get_env_value() { # Function to create directories, create conf.php file and set permissions on files function initDolibarr() { - local CURRENT_UID=$(id -u www-data) - local CURRENT_GID=$(id -g www-data) - usermod -u ${WWW_USER_ID} www-data - groupmod -g ${WWW_GROUP_ID} www-data - if [[ ! -d /var/www/documents ]]; then echo "[INIT] => create volume directory /var/www/documents ..." mkdir -p /var/www/documents @@ -109,16 +104,6 @@ EOF else chmod 400 /var/www/html/conf/conf.php fi - - if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then - # Refresh file ownership cause it has changed - echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." - chown -R www-data:www-data /var/www - else - # Reducing load on init : change ownership only for volumes declared in docker - echo "[INIT] => update ownership for files in /var/www/documents ..." - chown -R www-data:www-data /var/www/documents - fi } @@ -416,7 +401,22 @@ function run() # Run scripts before starting runScripts "before-starting.d" - + + local CURRENT_UID=$(id -u www-data) + local CURRENT_GID=$(id -g www-data) + usermod -u ${WWW_USER_ID} www-data + groupmod -g ${WWW_GROUP_ID} www-data + + if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then + # Refresh file ownership cause it has changed + echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." + chown -R www-data:www-data /var/www + else + # Reducing load on init : change ownership only for volumes declared in docker + echo "[INIT] => update ownership for files in /var/www/documents ..." + chown -R www-data:www-data /var/www/documents + fi + echo "*** You can connect to the docker Mariadb with:" echo "sudo docker exec -it nameofmariadbcontainer bash" echo "mysql -uroot -p'MYSQL_ROOT_PASSWORD' -h localhost"