From 91b3d0811b41641156f7e540f33e7e9b844f9f26 Mon Sep 17 00:00:00 2001 From: Andrey Kolnoochenko Date: Fri, 10 Nov 2017 09:33:35 +0300 Subject: [PATCH 1/4] Change hardcoded www-data:www-data user to APACHE_RUN_USER:APACHE_RUN_GROUP env --- docker-entrypoint.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2e92d65680..dca71edae7 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -31,6 +31,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then ( set -x; ls -A; sleep 10 ) fi tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + chown -R ${APACHE_RUN_USER:-www-data}:${APACHE_RUN_GROUP:-www-data} $PWD echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -46,7 +47,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown www-data:www-data .htaccess + chown ${APACHE_RUN_USER:-www-data}:${APACHE_RUN_GROUP:-www-data} .htaccess fi fi @@ -115,7 +116,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown www-data:www-data wp-config.php + chown ${APACHE_RUN_USER:-www-data}:${APACHE_RUN_GROUP:-www-data} wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 From 6f6ea033bb551a667cb27eec317003a14aa422f3 Mon Sep 17 00:00:00 2001 From: akolnoochenko Date: Wed, 15 Nov 2017 13:13:36 +0300 Subject: [PATCH 2/4] Use tar based solution to manage permissions of WP copied files --- docker-entrypoint.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index dca71edae7..fd256a1cc1 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -24,14 +24,22 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + : "${APACHE_RUN_USER:-www-data}" + : "${APACHE_RUN_GROUP:-www-data}" + export APACHE_RUN_USER APACHE_RUN_GROUP + if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." if [ "$(ls -A)" ]; then echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" ( set -x; ls -A; sleep 10 ) fi - tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - - chown -R ${APACHE_RUN_USER:-www-data}:${APACHE_RUN_GROUP:-www-data} $PWD + tar --create \ + --file - \ + --one-file-system \ + --directory /usr/src/wordpress \ + --owner "${APACHE_RUN_USER}" --group "${APACHE_RUN_GROUP}" \ + . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -47,7 +55,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown ${APACHE_RUN_USER:-www-data}:${APACHE_RUN_GROUP:-www-data} .htaccess + chown ${APACHE_RUN_USER}:${APACHE_RUN_GROUP} .htaccess fi fi @@ -116,7 +124,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown ${APACHE_RUN_USER:-www-data}:${APACHE_RUN_GROUP:-www-data} wp-config.php + chown ${APACHE_RUN_USER}:${APACHE_RUN_GROUP} wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 From 5af0b0cc2586dcb40fb22f88c9ba5cb4e508c7d8 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Thu, 21 Dec 2017 14:58:26 -0800 Subject: [PATCH 3/4] Adjust user:group values for FPM and non-root usage (which doesn't use the APACHE_RUN_* environment variables) --- docker-entrypoint.sh | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index fd256a1cc1..a91cd2dc7f 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -24,9 +24,21 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then - : "${APACHE_RUN_USER:-www-data}" - : "${APACHE_RUN_GROUP:-www-data}" - export APACHE_RUN_USER APACHE_RUN_GROUP + if [ "$(id -u)" = '0' ]; then + case "$1" in + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; + esac + else + user="$(id -u)" + group="$(id -g)" + fi if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." @@ -38,7 +50,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then --file - \ --one-file-system \ --directory /usr/src/wordpress \ - --owner "${APACHE_RUN_USER}" --group "${APACHE_RUN_GROUP}" \ + --owner "$user" --group "$group" \ . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then @@ -55,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown ${APACHE_RUN_USER}:${APACHE_RUN_GROUP} .htaccess + chown "$user:$group" .htaccess fi fi @@ -124,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown ${APACHE_RUN_USER}:${APACHE_RUN_GROUP} wp-config.php + chown "$user:$group" wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 From 43d32697c6862dcb48ca520e87e1e0fb585aee03 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Thu, 21 Dec 2017 15:00:29 -0800 Subject: [PATCH 4/4] Apply update.sh --- php5.6/apache/docker-entrypoint.sh | 27 +++++++++++++++++++++++--- php5.6/fpm-alpine/docker-entrypoint.sh | 27 +++++++++++++++++++++++--- php5.6/fpm/docker-entrypoint.sh | 27 +++++++++++++++++++++++--- php7.0/apache/docker-entrypoint.sh | 27 +++++++++++++++++++++++--- php7.0/fpm-alpine/docker-entrypoint.sh | 27 +++++++++++++++++++++++--- php7.0/fpm/docker-entrypoint.sh | 27 +++++++++++++++++++++++--- php7.1/apache/docker-entrypoint.sh | 27 +++++++++++++++++++++++--- php7.1/fpm-alpine/docker-entrypoint.sh | 27 +++++++++++++++++++++++--- php7.1/fpm/docker-entrypoint.sh | 27 +++++++++++++++++++++++--- php7.2/apache/docker-entrypoint.sh | 27 +++++++++++++++++++++++--- php7.2/fpm-alpine/docker-entrypoint.sh | 27 +++++++++++++++++++++++--- php7.2/fpm/docker-entrypoint.sh | 27 +++++++++++++++++++++++--- 12 files changed, 288 insertions(+), 36 deletions(-) diff --git a/php5.6/apache/docker-entrypoint.sh b/php5.6/apache/docker-entrypoint.sh index 2e92d65680..a91cd2dc7f 100755 --- a/php5.6/apache/docker-entrypoint.sh +++ b/php5.6/apache/docker-entrypoint.sh @@ -24,13 +24,34 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + if [ "$(id -u)" = '0' ]; then + case "$1" in + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; + esac + else + user="$(id -u)" + group="$(id -g)" + fi + if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." if [ "$(ls -A)" ]; then echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" ( set -x; ls -A; sleep 10 ) fi - tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + tar --create \ + --file - \ + --one-file-system \ + --directory /usr/src/wordpress \ + --owner "$user" --group "$group" \ + . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -46,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown www-data:www-data .htaccess + chown "$user:$group" .htaccess fi fi @@ -115,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown www-data:www-data wp-config.php + chown "$user:$group" wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 diff --git a/php5.6/fpm-alpine/docker-entrypoint.sh b/php5.6/fpm-alpine/docker-entrypoint.sh index 2e92d65680..a91cd2dc7f 100755 --- a/php5.6/fpm-alpine/docker-entrypoint.sh +++ b/php5.6/fpm-alpine/docker-entrypoint.sh @@ -24,13 +24,34 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + if [ "$(id -u)" = '0' ]; then + case "$1" in + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; + esac + else + user="$(id -u)" + group="$(id -g)" + fi + if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." if [ "$(ls -A)" ]; then echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" ( set -x; ls -A; sleep 10 ) fi - tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + tar --create \ + --file - \ + --one-file-system \ + --directory /usr/src/wordpress \ + --owner "$user" --group "$group" \ + . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -46,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown www-data:www-data .htaccess + chown "$user:$group" .htaccess fi fi @@ -115,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown www-data:www-data wp-config.php + chown "$user:$group" wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 diff --git a/php5.6/fpm/docker-entrypoint.sh b/php5.6/fpm/docker-entrypoint.sh index 2e92d65680..a91cd2dc7f 100755 --- a/php5.6/fpm/docker-entrypoint.sh +++ b/php5.6/fpm/docker-entrypoint.sh @@ -24,13 +24,34 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + if [ "$(id -u)" = '0' ]; then + case "$1" in + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; + esac + else + user="$(id -u)" + group="$(id -g)" + fi + if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." if [ "$(ls -A)" ]; then echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" ( set -x; ls -A; sleep 10 ) fi - tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + tar --create \ + --file - \ + --one-file-system \ + --directory /usr/src/wordpress \ + --owner "$user" --group "$group" \ + . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -46,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown www-data:www-data .htaccess + chown "$user:$group" .htaccess fi fi @@ -115,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown www-data:www-data wp-config.php + chown "$user:$group" wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 diff --git a/php7.0/apache/docker-entrypoint.sh b/php7.0/apache/docker-entrypoint.sh index 2e92d65680..a91cd2dc7f 100755 --- a/php7.0/apache/docker-entrypoint.sh +++ b/php7.0/apache/docker-entrypoint.sh @@ -24,13 +24,34 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + if [ "$(id -u)" = '0' ]; then + case "$1" in + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; + esac + else + user="$(id -u)" + group="$(id -g)" + fi + if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." if [ "$(ls -A)" ]; then echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" ( set -x; ls -A; sleep 10 ) fi - tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + tar --create \ + --file - \ + --one-file-system \ + --directory /usr/src/wordpress \ + --owner "$user" --group "$group" \ + . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -46,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown www-data:www-data .htaccess + chown "$user:$group" .htaccess fi fi @@ -115,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown www-data:www-data wp-config.php + chown "$user:$group" wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 diff --git a/php7.0/fpm-alpine/docker-entrypoint.sh b/php7.0/fpm-alpine/docker-entrypoint.sh index 2e92d65680..a91cd2dc7f 100755 --- a/php7.0/fpm-alpine/docker-entrypoint.sh +++ b/php7.0/fpm-alpine/docker-entrypoint.sh @@ -24,13 +24,34 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + if [ "$(id -u)" = '0' ]; then + case "$1" in + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; + esac + else + user="$(id -u)" + group="$(id -g)" + fi + if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." if [ "$(ls -A)" ]; then echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" ( set -x; ls -A; sleep 10 ) fi - tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + tar --create \ + --file - \ + --one-file-system \ + --directory /usr/src/wordpress \ + --owner "$user" --group "$group" \ + . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -46,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown www-data:www-data .htaccess + chown "$user:$group" .htaccess fi fi @@ -115,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown www-data:www-data wp-config.php + chown "$user:$group" wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 diff --git a/php7.0/fpm/docker-entrypoint.sh b/php7.0/fpm/docker-entrypoint.sh index 2e92d65680..a91cd2dc7f 100755 --- a/php7.0/fpm/docker-entrypoint.sh +++ b/php7.0/fpm/docker-entrypoint.sh @@ -24,13 +24,34 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + if [ "$(id -u)" = '0' ]; then + case "$1" in + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; + esac + else + user="$(id -u)" + group="$(id -g)" + fi + if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." if [ "$(ls -A)" ]; then echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" ( set -x; ls -A; sleep 10 ) fi - tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + tar --create \ + --file - \ + --one-file-system \ + --directory /usr/src/wordpress \ + --owner "$user" --group "$group" \ + . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -46,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown www-data:www-data .htaccess + chown "$user:$group" .htaccess fi fi @@ -115,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown www-data:www-data wp-config.php + chown "$user:$group" wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 diff --git a/php7.1/apache/docker-entrypoint.sh b/php7.1/apache/docker-entrypoint.sh index 2e92d65680..a91cd2dc7f 100755 --- a/php7.1/apache/docker-entrypoint.sh +++ b/php7.1/apache/docker-entrypoint.sh @@ -24,13 +24,34 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + if [ "$(id -u)" = '0' ]; then + case "$1" in + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; + esac + else + user="$(id -u)" + group="$(id -g)" + fi + if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." if [ "$(ls -A)" ]; then echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" ( set -x; ls -A; sleep 10 ) fi - tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + tar --create \ + --file - \ + --one-file-system \ + --directory /usr/src/wordpress \ + --owner "$user" --group "$group" \ + . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -46,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown www-data:www-data .htaccess + chown "$user:$group" .htaccess fi fi @@ -115,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown www-data:www-data wp-config.php + chown "$user:$group" wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 diff --git a/php7.1/fpm-alpine/docker-entrypoint.sh b/php7.1/fpm-alpine/docker-entrypoint.sh index 2e92d65680..a91cd2dc7f 100755 --- a/php7.1/fpm-alpine/docker-entrypoint.sh +++ b/php7.1/fpm-alpine/docker-entrypoint.sh @@ -24,13 +24,34 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + if [ "$(id -u)" = '0' ]; then + case "$1" in + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; + esac + else + user="$(id -u)" + group="$(id -g)" + fi + if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." if [ "$(ls -A)" ]; then echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" ( set -x; ls -A; sleep 10 ) fi - tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + tar --create \ + --file - \ + --one-file-system \ + --directory /usr/src/wordpress \ + --owner "$user" --group "$group" \ + . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -46,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown www-data:www-data .htaccess + chown "$user:$group" .htaccess fi fi @@ -115,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown www-data:www-data wp-config.php + chown "$user:$group" wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 diff --git a/php7.1/fpm/docker-entrypoint.sh b/php7.1/fpm/docker-entrypoint.sh index 2e92d65680..a91cd2dc7f 100755 --- a/php7.1/fpm/docker-entrypoint.sh +++ b/php7.1/fpm/docker-entrypoint.sh @@ -24,13 +24,34 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + if [ "$(id -u)" = '0' ]; then + case "$1" in + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; + esac + else + user="$(id -u)" + group="$(id -g)" + fi + if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." if [ "$(ls -A)" ]; then echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" ( set -x; ls -A; sleep 10 ) fi - tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + tar --create \ + --file - \ + --one-file-system \ + --directory /usr/src/wordpress \ + --owner "$user" --group "$group" \ + . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -46,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown www-data:www-data .htaccess + chown "$user:$group" .htaccess fi fi @@ -115,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown www-data:www-data wp-config.php + chown "$user:$group" wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 diff --git a/php7.2/apache/docker-entrypoint.sh b/php7.2/apache/docker-entrypoint.sh index 2e92d65680..a91cd2dc7f 100755 --- a/php7.2/apache/docker-entrypoint.sh +++ b/php7.2/apache/docker-entrypoint.sh @@ -24,13 +24,34 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + if [ "$(id -u)" = '0' ]; then + case "$1" in + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; + esac + else + user="$(id -u)" + group="$(id -g)" + fi + if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." if [ "$(ls -A)" ]; then echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" ( set -x; ls -A; sleep 10 ) fi - tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + tar --create \ + --file - \ + --one-file-system \ + --directory /usr/src/wordpress \ + --owner "$user" --group "$group" \ + . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -46,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown www-data:www-data .htaccess + chown "$user:$group" .htaccess fi fi @@ -115,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown www-data:www-data wp-config.php + chown "$user:$group" wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 diff --git a/php7.2/fpm-alpine/docker-entrypoint.sh b/php7.2/fpm-alpine/docker-entrypoint.sh index 2e92d65680..a91cd2dc7f 100755 --- a/php7.2/fpm-alpine/docker-entrypoint.sh +++ b/php7.2/fpm-alpine/docker-entrypoint.sh @@ -24,13 +24,34 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + if [ "$(id -u)" = '0' ]; then + case "$1" in + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; + esac + else + user="$(id -u)" + group="$(id -g)" + fi + if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." if [ "$(ls -A)" ]; then echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" ( set -x; ls -A; sleep 10 ) fi - tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + tar --create \ + --file - \ + --one-file-system \ + --directory /usr/src/wordpress \ + --owner "$user" --group "$group" \ + . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -46,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown www-data:www-data .htaccess + chown "$user:$group" .htaccess fi fi @@ -115,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown www-data:www-data wp-config.php + chown "$user:$group" wp-config.php fi # see http://stackoverflow.com/a/2705678/433558 diff --git a/php7.2/fpm/docker-entrypoint.sh b/php7.2/fpm/docker-entrypoint.sh index 2e92d65680..a91cd2dc7f 100755 --- a/php7.2/fpm/docker-entrypoint.sh +++ b/php7.2/fpm/docker-entrypoint.sh @@ -24,13 +24,34 @@ file_env() { } if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + if [ "$(id -u)" = '0' ]; then + case "$1" in + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; + esac + else + user="$(id -u)" + group="$(id -g)" + fi + if ! [ -e index.php -a -e wp-includes/version.php ]; then echo >&2 "WordPress not found in $PWD - copying now..." if [ "$(ls -A)" ]; then echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" ( set -x; ls -A; sleep 10 ) fi - tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + tar --create \ + --file - \ + --one-file-system \ + --directory /usr/src/wordpress \ + --owner "$user" --group "$group" \ + . | tar --extract --file - echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image @@ -46,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # END WordPress EOF - chown www-data:www-data .htaccess + chown "$user:$group" .htaccess fi fi @@ -115,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT } EOPHP - chown www-data:www-data wp-config.php + chown "$user:$group" wp-config.php fi # see http://stackoverflow.com/a/2705678/433558