Skip to content

Commit

Permalink
Merge pull request #351 from infosiftr/no-overwrite-dir
Browse files Browse the repository at this point in the history
Add "--no-overwrite-dir" to "tar" invocation for running as an arbitrary user
  • Loading branch information
yosifkit authored Nov 28, 2018
2 parents 90d235a + 5bad0cb commit a748aaf
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 65 deletions.
25 changes: 20 additions & 5 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
apache2*)
user="${APACHE_RUN_USER:-www-data}"
group="${APACHE_RUN_GROUP:-www-data}"

# strip off any '#' symbol ('#1000' is valid syntax for Apache)
pound='#'
user="${user#$pound}"
group="${group#$pound}"
;;
*) # php-fpm
user='www-data'
Expand All @@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
if [ -n "$(ls -A)" ]; then
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
fi
tar --create \
--file - \
--directory /usr/src/wordpress \
--owner "$user" --group "$group" \
. | tar --extract --file -
sourceTarArgs=(
--create
--file -
--directory /usr/src/wordpress
--owner "$user" --group "$group"
)
targetTarArgs=(
--extract
--file -
)
if [ "$user" != '0' ]; then
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
targetTarArgs+=( --no-overwrite-dir )
fi
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
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
Expand Down
25 changes: 20 additions & 5 deletions php5.6/apache/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
apache2*)
user="${APACHE_RUN_USER:-www-data}"
group="${APACHE_RUN_GROUP:-www-data}"

# strip off any '#' symbol ('#1000' is valid syntax for Apache)
pound='#'
user="${user#$pound}"
group="${group#$pound}"
;;
*) # php-fpm
user='www-data'
Expand All @@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
if [ -n "$(ls -A)" ]; then
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
fi
tar --create \
--file - \
--directory /usr/src/wordpress \
--owner "$user" --group "$group" \
. | tar --extract --file -
sourceTarArgs=(
--create
--file -
--directory /usr/src/wordpress
--owner "$user" --group "$group"
)
targetTarArgs=(
--extract
--file -
)
if [ "$user" != '0' ]; then
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
targetTarArgs+=( --no-overwrite-dir )
fi
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
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
Expand Down
25 changes: 20 additions & 5 deletions php5.6/fpm-alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
apache2*)
user="${APACHE_RUN_USER:-www-data}"
group="${APACHE_RUN_GROUP:-www-data}"

# strip off any '#' symbol ('#1000' is valid syntax for Apache)
pound='#'
user="${user#$pound}"
group="${group#$pound}"
;;
*) # php-fpm
user='www-data'
Expand All @@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
if [ -n "$(ls -A)" ]; then
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
fi
tar --create \
--file - \
--directory /usr/src/wordpress \
--owner "$user" --group "$group" \
. | tar --extract --file -
sourceTarArgs=(
--create
--file -
--directory /usr/src/wordpress
--owner "$user" --group "$group"
)
targetTarArgs=(
--extract
--file -
)
if [ "$user" != '0' ]; then
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
targetTarArgs+=( --no-overwrite-dir )
fi
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
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
Expand Down
25 changes: 20 additions & 5 deletions php5.6/fpm/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
apache2*)
user="${APACHE_RUN_USER:-www-data}"
group="${APACHE_RUN_GROUP:-www-data}"

# strip off any '#' symbol ('#1000' is valid syntax for Apache)
pound='#'
user="${user#$pound}"
group="${group#$pound}"
;;
*) # php-fpm
user='www-data'
Expand All @@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
if [ -n "$(ls -A)" ]; then
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
fi
tar --create \
--file - \
--directory /usr/src/wordpress \
--owner "$user" --group "$group" \
. | tar --extract --file -
sourceTarArgs=(
--create
--file -
--directory /usr/src/wordpress
--owner "$user" --group "$group"
)
targetTarArgs=(
--extract
--file -
)
if [ "$user" != '0' ]; then
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
targetTarArgs+=( --no-overwrite-dir )
fi
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
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
Expand Down
25 changes: 20 additions & 5 deletions php7.0/apache/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
apache2*)
user="${APACHE_RUN_USER:-www-data}"
group="${APACHE_RUN_GROUP:-www-data}"

# strip off any '#' symbol ('#1000' is valid syntax for Apache)
pound='#'
user="${user#$pound}"
group="${group#$pound}"
;;
*) # php-fpm
user='www-data'
Expand All @@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
if [ -n "$(ls -A)" ]; then
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
fi
tar --create \
--file - \
--directory /usr/src/wordpress \
--owner "$user" --group "$group" \
. | tar --extract --file -
sourceTarArgs=(
--create
--file -
--directory /usr/src/wordpress
--owner "$user" --group "$group"
)
targetTarArgs=(
--extract
--file -
)
if [ "$user" != '0' ]; then
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
targetTarArgs+=( --no-overwrite-dir )
fi
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
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
Expand Down
25 changes: 20 additions & 5 deletions php7.0/fpm-alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
apache2*)
user="${APACHE_RUN_USER:-www-data}"
group="${APACHE_RUN_GROUP:-www-data}"

# strip off any '#' symbol ('#1000' is valid syntax for Apache)
pound='#'
user="${user#$pound}"
group="${group#$pound}"
;;
*) # php-fpm
user='www-data'
Expand All @@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
if [ -n "$(ls -A)" ]; then
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
fi
tar --create \
--file - \
--directory /usr/src/wordpress \
--owner "$user" --group "$group" \
. | tar --extract --file -
sourceTarArgs=(
--create
--file -
--directory /usr/src/wordpress
--owner "$user" --group "$group"
)
targetTarArgs=(
--extract
--file -
)
if [ "$user" != '0' ]; then
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
targetTarArgs+=( --no-overwrite-dir )
fi
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
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
Expand Down
25 changes: 20 additions & 5 deletions php7.0/fpm/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
apache2*)
user="${APACHE_RUN_USER:-www-data}"
group="${APACHE_RUN_GROUP:-www-data}"

# strip off any '#' symbol ('#1000' is valid syntax for Apache)
pound='#'
user="${user#$pound}"
group="${group#$pound}"
;;
*) # php-fpm
user='www-data'
Expand All @@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
if [ -n "$(ls -A)" ]; then
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
fi
tar --create \
--file - \
--directory /usr/src/wordpress \
--owner "$user" --group "$group" \
. | tar --extract --file -
sourceTarArgs=(
--create
--file -
--directory /usr/src/wordpress
--owner "$user" --group "$group"
)
targetTarArgs=(
--extract
--file -
)
if [ "$user" != '0' ]; then
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
targetTarArgs+=( --no-overwrite-dir )
fi
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
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
Expand Down
25 changes: 20 additions & 5 deletions php7.1/apache/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
apache2*)
user="${APACHE_RUN_USER:-www-data}"
group="${APACHE_RUN_GROUP:-www-data}"

# strip off any '#' symbol ('#1000' is valid syntax for Apache)
pound='#'
user="${user#$pound}"
group="${group#$pound}"
;;
*) # php-fpm
user='www-data'
Expand All @@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
if [ -n "$(ls -A)" ]; then
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
fi
tar --create \
--file - \
--directory /usr/src/wordpress \
--owner "$user" --group "$group" \
. | tar --extract --file -
sourceTarArgs=(
--create
--file -
--directory /usr/src/wordpress
--owner "$user" --group "$group"
)
targetTarArgs=(
--extract
--file -
)
if [ "$user" != '0' ]; then
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
targetTarArgs+=( --no-overwrite-dir )
fi
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
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
Expand Down
25 changes: 20 additions & 5 deletions php7.1/fpm-alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
apache2*)
user="${APACHE_RUN_USER:-www-data}"
group="${APACHE_RUN_GROUP:-www-data}"

# strip off any '#' symbol ('#1000' is valid syntax for Apache)
pound='#'
user="${user#$pound}"
group="${group#$pound}"
;;
*) # php-fpm
user='www-data'
Expand All @@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
if [ -n "$(ls -A)" ]; then
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
fi
tar --create \
--file - \
--directory /usr/src/wordpress \
--owner "$user" --group "$group" \
. | tar --extract --file -
sourceTarArgs=(
--create
--file -
--directory /usr/src/wordpress
--owner "$user" --group "$group"
)
targetTarArgs=(
--extract
--file -
)
if [ "$user" != '0' ]; then
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
targetTarArgs+=( --no-overwrite-dir )
fi
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
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
Expand Down
25 changes: 20 additions & 5 deletions php7.1/fpm/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
apache2*)
user="${APACHE_RUN_USER:-www-data}"
group="${APACHE_RUN_GROUP:-www-data}"

# strip off any '#' symbol ('#1000' is valid syntax for Apache)
pound='#'
user="${user#$pound}"
group="${group#$pound}"
;;
*) # php-fpm
user='www-data'
Expand All @@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
if [ -n "$(ls -A)" ]; then
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
fi
tar --create \
--file - \
--directory /usr/src/wordpress \
--owner "$user" --group "$group" \
. | tar --extract --file -
sourceTarArgs=(
--create
--file -
--directory /usr/src/wordpress
--owner "$user" --group "$group"
)
targetTarArgs=(
--extract
--file -
)
if [ "$user" != '0' ]; then
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
targetTarArgs+=( --no-overwrite-dir )
fi
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
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
Expand Down
Loading

0 comments on commit a748aaf

Please sign in to comment.