Skip to content

Commit a748aaf

Browse files
authored
Merge pull request #351 from infosiftr/no-overwrite-dir
Add "--no-overwrite-dir" to "tar" invocation for running as an arbitrary user
2 parents 90d235a + 5bad0cb commit a748aaf

File tree

13 files changed

+260
-65
lines changed

13 files changed

+260
-65
lines changed

docker-entrypoint.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
2929
apache2*)
3030
user="${APACHE_RUN_USER:-www-data}"
3131
group="${APACHE_RUN_GROUP:-www-data}"
32+
33+
# strip off any '#' symbol ('#1000' is valid syntax for Apache)
34+
pound='#'
35+
user="${user#$pound}"
36+
group="${group#$pound}"
3237
;;
3338
*) # php-fpm
3439
user='www-data'
@@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
4550
if [ -n "$(ls -A)" ]; then
4651
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
4752
fi
48-
tar --create \
49-
--file - \
50-
--directory /usr/src/wordpress \
51-
--owner "$user" --group "$group" \
52-
. | tar --extract --file -
53+
sourceTarArgs=(
54+
--create
55+
--file -
56+
--directory /usr/src/wordpress
57+
--owner "$user" --group "$group"
58+
)
59+
targetTarArgs=(
60+
--extract
61+
--file -
62+
)
63+
if [ "$user" != '0' ]; then
64+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
65+
targetTarArgs+=( --no-overwrite-dir )
66+
fi
67+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
5368
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
5469
if [ ! -e .htaccess ]; then
5570
# NOTE: The "Indexes" option is disabled in the php:apache base image

php5.6/apache/docker-entrypoint.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
2929
apache2*)
3030
user="${APACHE_RUN_USER:-www-data}"
3131
group="${APACHE_RUN_GROUP:-www-data}"
32+
33+
# strip off any '#' symbol ('#1000' is valid syntax for Apache)
34+
pound='#'
35+
user="${user#$pound}"
36+
group="${group#$pound}"
3237
;;
3338
*) # php-fpm
3439
user='www-data'
@@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
4550
if [ -n "$(ls -A)" ]; then
4651
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
4752
fi
48-
tar --create \
49-
--file - \
50-
--directory /usr/src/wordpress \
51-
--owner "$user" --group "$group" \
52-
. | tar --extract --file -
53+
sourceTarArgs=(
54+
--create
55+
--file -
56+
--directory /usr/src/wordpress
57+
--owner "$user" --group "$group"
58+
)
59+
targetTarArgs=(
60+
--extract
61+
--file -
62+
)
63+
if [ "$user" != '0' ]; then
64+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
65+
targetTarArgs+=( --no-overwrite-dir )
66+
fi
67+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
5368
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
5469
if [ ! -e .htaccess ]; then
5570
# NOTE: The "Indexes" option is disabled in the php:apache base image

php5.6/fpm-alpine/docker-entrypoint.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
2929
apache2*)
3030
user="${APACHE_RUN_USER:-www-data}"
3131
group="${APACHE_RUN_GROUP:-www-data}"
32+
33+
# strip off any '#' symbol ('#1000' is valid syntax for Apache)
34+
pound='#'
35+
user="${user#$pound}"
36+
group="${group#$pound}"
3237
;;
3338
*) # php-fpm
3439
user='www-data'
@@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
4550
if [ -n "$(ls -A)" ]; then
4651
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
4752
fi
48-
tar --create \
49-
--file - \
50-
--directory /usr/src/wordpress \
51-
--owner "$user" --group "$group" \
52-
. | tar --extract --file -
53+
sourceTarArgs=(
54+
--create
55+
--file -
56+
--directory /usr/src/wordpress
57+
--owner "$user" --group "$group"
58+
)
59+
targetTarArgs=(
60+
--extract
61+
--file -
62+
)
63+
if [ "$user" != '0' ]; then
64+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
65+
targetTarArgs+=( --no-overwrite-dir )
66+
fi
67+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
5368
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
5469
if [ ! -e .htaccess ]; then
5570
# NOTE: The "Indexes" option is disabled in the php:apache base image

php5.6/fpm/docker-entrypoint.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
2929
apache2*)
3030
user="${APACHE_RUN_USER:-www-data}"
3131
group="${APACHE_RUN_GROUP:-www-data}"
32+
33+
# strip off any '#' symbol ('#1000' is valid syntax for Apache)
34+
pound='#'
35+
user="${user#$pound}"
36+
group="${group#$pound}"
3237
;;
3338
*) # php-fpm
3439
user='www-data'
@@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
4550
if [ -n "$(ls -A)" ]; then
4651
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
4752
fi
48-
tar --create \
49-
--file - \
50-
--directory /usr/src/wordpress \
51-
--owner "$user" --group "$group" \
52-
. | tar --extract --file -
53+
sourceTarArgs=(
54+
--create
55+
--file -
56+
--directory /usr/src/wordpress
57+
--owner "$user" --group "$group"
58+
)
59+
targetTarArgs=(
60+
--extract
61+
--file -
62+
)
63+
if [ "$user" != '0' ]; then
64+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
65+
targetTarArgs+=( --no-overwrite-dir )
66+
fi
67+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
5368
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
5469
if [ ! -e .htaccess ]; then
5570
# NOTE: The "Indexes" option is disabled in the php:apache base image

php7.0/apache/docker-entrypoint.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
2929
apache2*)
3030
user="${APACHE_RUN_USER:-www-data}"
3131
group="${APACHE_RUN_GROUP:-www-data}"
32+
33+
# strip off any '#' symbol ('#1000' is valid syntax for Apache)
34+
pound='#'
35+
user="${user#$pound}"
36+
group="${group#$pound}"
3237
;;
3338
*) # php-fpm
3439
user='www-data'
@@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
4550
if [ -n "$(ls -A)" ]; then
4651
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
4752
fi
48-
tar --create \
49-
--file - \
50-
--directory /usr/src/wordpress \
51-
--owner "$user" --group "$group" \
52-
. | tar --extract --file -
53+
sourceTarArgs=(
54+
--create
55+
--file -
56+
--directory /usr/src/wordpress
57+
--owner "$user" --group "$group"
58+
)
59+
targetTarArgs=(
60+
--extract
61+
--file -
62+
)
63+
if [ "$user" != '0' ]; then
64+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
65+
targetTarArgs+=( --no-overwrite-dir )
66+
fi
67+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
5368
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
5469
if [ ! -e .htaccess ]; then
5570
# NOTE: The "Indexes" option is disabled in the php:apache base image

php7.0/fpm-alpine/docker-entrypoint.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
2929
apache2*)
3030
user="${APACHE_RUN_USER:-www-data}"
3131
group="${APACHE_RUN_GROUP:-www-data}"
32+
33+
# strip off any '#' symbol ('#1000' is valid syntax for Apache)
34+
pound='#'
35+
user="${user#$pound}"
36+
group="${group#$pound}"
3237
;;
3338
*) # php-fpm
3439
user='www-data'
@@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
4550
if [ -n "$(ls -A)" ]; then
4651
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
4752
fi
48-
tar --create \
49-
--file - \
50-
--directory /usr/src/wordpress \
51-
--owner "$user" --group "$group" \
52-
. | tar --extract --file -
53+
sourceTarArgs=(
54+
--create
55+
--file -
56+
--directory /usr/src/wordpress
57+
--owner "$user" --group "$group"
58+
)
59+
targetTarArgs=(
60+
--extract
61+
--file -
62+
)
63+
if [ "$user" != '0' ]; then
64+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
65+
targetTarArgs+=( --no-overwrite-dir )
66+
fi
67+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
5368
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
5469
if [ ! -e .htaccess ]; then
5570
# NOTE: The "Indexes" option is disabled in the php:apache base image

php7.0/fpm/docker-entrypoint.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
2929
apache2*)
3030
user="${APACHE_RUN_USER:-www-data}"
3131
group="${APACHE_RUN_GROUP:-www-data}"
32+
33+
# strip off any '#' symbol ('#1000' is valid syntax for Apache)
34+
pound='#'
35+
user="${user#$pound}"
36+
group="${group#$pound}"
3237
;;
3338
*) # php-fpm
3439
user='www-data'
@@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
4550
if [ -n "$(ls -A)" ]; then
4651
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
4752
fi
48-
tar --create \
49-
--file - \
50-
--directory /usr/src/wordpress \
51-
--owner "$user" --group "$group" \
52-
. | tar --extract --file -
53+
sourceTarArgs=(
54+
--create
55+
--file -
56+
--directory /usr/src/wordpress
57+
--owner "$user" --group "$group"
58+
)
59+
targetTarArgs=(
60+
--extract
61+
--file -
62+
)
63+
if [ "$user" != '0' ]; then
64+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
65+
targetTarArgs+=( --no-overwrite-dir )
66+
fi
67+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
5368
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
5469
if [ ! -e .htaccess ]; then
5570
# NOTE: The "Indexes" option is disabled in the php:apache base image

php7.1/apache/docker-entrypoint.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
2929
apache2*)
3030
user="${APACHE_RUN_USER:-www-data}"
3131
group="${APACHE_RUN_GROUP:-www-data}"
32+
33+
# strip off any '#' symbol ('#1000' is valid syntax for Apache)
34+
pound='#'
35+
user="${user#$pound}"
36+
group="${group#$pound}"
3237
;;
3338
*) # php-fpm
3439
user='www-data'
@@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
4550
if [ -n "$(ls -A)" ]; then
4651
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
4752
fi
48-
tar --create \
49-
--file - \
50-
--directory /usr/src/wordpress \
51-
--owner "$user" --group "$group" \
52-
. | tar --extract --file -
53+
sourceTarArgs=(
54+
--create
55+
--file -
56+
--directory /usr/src/wordpress
57+
--owner "$user" --group "$group"
58+
)
59+
targetTarArgs=(
60+
--extract
61+
--file -
62+
)
63+
if [ "$user" != '0' ]; then
64+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
65+
targetTarArgs+=( --no-overwrite-dir )
66+
fi
67+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
5368
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
5469
if [ ! -e .htaccess ]; then
5570
# NOTE: The "Indexes" option is disabled in the php:apache base image

php7.1/fpm-alpine/docker-entrypoint.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
2929
apache2*)
3030
user="${APACHE_RUN_USER:-www-data}"
3131
group="${APACHE_RUN_GROUP:-www-data}"
32+
33+
# strip off any '#' symbol ('#1000' is valid syntax for Apache)
34+
pound='#'
35+
user="${user#$pound}"
36+
group="${group#$pound}"
3237
;;
3338
*) # php-fpm
3439
user='www-data'
@@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
4550
if [ -n "$(ls -A)" ]; then
4651
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
4752
fi
48-
tar --create \
49-
--file - \
50-
--directory /usr/src/wordpress \
51-
--owner "$user" --group "$group" \
52-
. | tar --extract --file -
53+
sourceTarArgs=(
54+
--create
55+
--file -
56+
--directory /usr/src/wordpress
57+
--owner "$user" --group "$group"
58+
)
59+
targetTarArgs=(
60+
--extract
61+
--file -
62+
)
63+
if [ "$user" != '0' ]; then
64+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
65+
targetTarArgs+=( --no-overwrite-dir )
66+
fi
67+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
5368
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
5469
if [ ! -e .htaccess ]; then
5570
# NOTE: The "Indexes" option is disabled in the php:apache base image

php7.1/fpm/docker-entrypoint.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
2929
apache2*)
3030
user="${APACHE_RUN_USER:-www-data}"
3131
group="${APACHE_RUN_GROUP:-www-data}"
32+
33+
# strip off any '#' symbol ('#1000' is valid syntax for Apache)
34+
pound='#'
35+
user="${user#$pound}"
36+
group="${group#$pound}"
3237
;;
3338
*) # php-fpm
3439
user='www-data'
@@ -45,11 +50,21 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
4550
if [ -n "$(ls -A)" ]; then
4651
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
4752
fi
48-
tar --create \
49-
--file - \
50-
--directory /usr/src/wordpress \
51-
--owner "$user" --group "$group" \
52-
. | tar --extract --file -
53+
sourceTarArgs=(
54+
--create
55+
--file -
56+
--directory /usr/src/wordpress
57+
--owner "$user" --group "$group"
58+
)
59+
targetTarArgs=(
60+
--extract
61+
--file -
62+
)
63+
if [ "$user" != '0' ]; then
64+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
65+
targetTarArgs+=( --no-overwrite-dir )
66+
fi
67+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
5368
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
5469
if [ ! -e .htaccess ]; then
5570
# NOTE: The "Indexes" option is disabled in the php:apache base image

0 commit comments

Comments
 (0)