Skip to content

Commit f2879bd

Browse files
committed
Copy config, data, custom_apps, and themes to volume when empty
When Nextcloud performs an upgrade or clean installation, it will check whether /var/www/html/{config,data,custom_apps,themes} exist. If not, it will copy /usr/src/nextcloud/{config,data,custom_apps,themes} to /var/www/html. This leads to a problem: If those subdirectories are existent but empty, it will not do the copy. This situation is common when you mount volumes to those subdirectories, like: ``` version: "2.1" services: app: image: nextcloud:12-apache volumes: - nextcloud:/var/www/html:Z - nextcloud-custom_apps:/var/www/html/custom_apps:Z - nextcloud-config:/var/www/html/config:Z - nextcloud-data:/var/www/html/data:Z - nextcloud-themes:/var/www/html/themes:Z ports: - 8080:80/tcp db: image: mariadb volumes: - db:/var/lib/mysql:Z environment: MYSQL_USER: nextcloud MYSQL_DATABASE: nextcloud MYSQL_PASSWORD: nextcloud MYSQL_ROOT_PASSWORD: nextcloud volumes: nextcloud: nextcloud-custom_apps: nextcloud-config: nextcloud-data: nextcloud-themes: db: ``` This patch will fix this issue by checking whether those subdirectories are empty.
1 parent af79651 commit f2879bd

7 files changed

Lines changed: 91 additions & 126 deletions

File tree

10.0/apache/docker-entrypoint.sh

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ function version_greater() {
66
[[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ]];
77
}
88

9+
# return true if specified directory empty
10+
function directory_empty() {
11+
[ -n "$(find "$1"/ -prune -empty)" ]
12+
}
13+
14+
915
installed_version="0.0.0~unknown"
1016
if [ -f /var/www/html/version.php ]; then
1117
installed_version=$(php -r 'require "/var/www/html/version.php"; echo "$OC_VersionString";')
@@ -21,25 +27,14 @@ if version_greater "$image_version" "$installed_version"; then
2127
if [ "$installed_version" != "0.0.0~unknown" ]; then
2228
su - www-data -s /bin/bash -c 'php /var/www/html/occ app:list' > /tmp/list_before
2329
fi
24-
30+
2531
rsync -a --delete --exclude /config/ --exclude /data/ --exclude /custom_apps/ --exclude /themes/ /usr/src/nextcloud/ /var/www/html/
26-
27-
if [ ! -d /var/www/html/config ]; then
28-
cp -arT /usr/src/nextcloud/config /var/www/html/config
29-
fi
30-
31-
if [ ! -d /var/www/html/data ]; then
32-
cp -arT /usr/src/nextcloud/data /var/www/html/data
33-
fi
34-
35-
if [ ! -d /var/www/html/custom_apps ]; then
36-
cp -arT /usr/src/nextcloud/custom_apps /var/www/html/custom_apps
37-
cp -a /usr/src/nextcloud/config/apps.config.php /var/www/html/config/apps.config.php
38-
fi
39-
40-
if [ ! -d /var/www/html/themes ]; then
41-
cp -arT /usr/src/nextcloud/themes /var/www/html/themes
42-
fi
32+
33+
for dir in config data custom_apps themes; do
34+
if [ ! -d /var/www/html/"$dir" ] || directory_empty /var/www/html/"$dir"; then
35+
cp -arT /usr/src/nextcloud/"$dir" /var/www/html/"$dir"
36+
fi
37+
done
4338

4439
if [ "$installed_version" != "0.0.0~unknown" ]; then
4540
su - www-data -s /bin/bash -c 'php /var/www/html/occ upgrade --no-app-disable'

10.0/fpm/docker-entrypoint.sh

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ function version_greater() {
66
[[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ]];
77
}
88

9+
# return true if specified directory empty
10+
function directory_empty() {
11+
[ -n "$(find "$1"/ -prune -empty)" ]
12+
}
13+
14+
915
installed_version="0.0.0~unknown"
1016
if [ -f /var/www/html/version.php ]; then
1117
installed_version=$(php -r 'require "/var/www/html/version.php"; echo "$OC_VersionString";')
@@ -21,25 +27,14 @@ if version_greater "$image_version" "$installed_version"; then
2127
if [ "$installed_version" != "0.0.0~unknown" ]; then
2228
su - www-data -s /bin/bash -c 'php /var/www/html/occ app:list' > /tmp/list_before
2329
fi
24-
30+
2531
rsync -a --delete --exclude /config/ --exclude /data/ --exclude /custom_apps/ --exclude /themes/ /usr/src/nextcloud/ /var/www/html/
26-
27-
if [ ! -d /var/www/html/config ]; then
28-
cp -arT /usr/src/nextcloud/config /var/www/html/config
29-
fi
30-
31-
if [ ! -d /var/www/html/data ]; then
32-
cp -arT /usr/src/nextcloud/data /var/www/html/data
33-
fi
34-
35-
if [ ! -d /var/www/html/custom_apps ]; then
36-
cp -arT /usr/src/nextcloud/custom_apps /var/www/html/custom_apps
37-
cp -a /usr/src/nextcloud/config/apps.config.php /var/www/html/config/apps.config.php
38-
fi
39-
40-
if [ ! -d /var/www/html/themes ]; then
41-
cp -arT /usr/src/nextcloud/themes /var/www/html/themes
42-
fi
32+
33+
for dir in config data custom_apps themes; do
34+
if [ ! -d /var/www/html/"$dir" ] || directory_empty /var/www/html/"$dir"; then
35+
cp -arT /usr/src/nextcloud/"$dir" /var/www/html/"$dir"
36+
fi
37+
done
4338

4439
if [ "$installed_version" != "0.0.0~unknown" ]; then
4540
su - www-data -s /bin/bash -c 'php /var/www/html/occ upgrade --no-app-disable'

11.0/apache/docker-entrypoint.sh

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ function version_greater() {
66
[[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ]];
77
}
88

9+
# return true if specified directory empty
10+
function directory_empty() {
11+
[ -n "$(find "$1"/ -prune -empty)" ]
12+
}
13+
14+
915
installed_version="0.0.0~unknown"
1016
if [ -f /var/www/html/version.php ]; then
1117
installed_version=$(php -r 'require "/var/www/html/version.php"; echo "$OC_VersionString";')
@@ -21,25 +27,14 @@ if version_greater "$image_version" "$installed_version"; then
2127
if [ "$installed_version" != "0.0.0~unknown" ]; then
2228
su - www-data -s /bin/bash -c 'php /var/www/html/occ app:list' > /tmp/list_before
2329
fi
24-
30+
2531
rsync -a --delete --exclude /config/ --exclude /data/ --exclude /custom_apps/ --exclude /themes/ /usr/src/nextcloud/ /var/www/html/
26-
27-
if [ ! -d /var/www/html/config ]; then
28-
cp -arT /usr/src/nextcloud/config /var/www/html/config
29-
fi
30-
31-
if [ ! -d /var/www/html/data ]; then
32-
cp -arT /usr/src/nextcloud/data /var/www/html/data
33-
fi
34-
35-
if [ ! -d /var/www/html/custom_apps ]; then
36-
cp -arT /usr/src/nextcloud/custom_apps /var/www/html/custom_apps
37-
cp -a /usr/src/nextcloud/config/apps.config.php /var/www/html/config/apps.config.php
38-
fi
39-
40-
if [ ! -d /var/www/html/themes ]; then
41-
cp -arT /usr/src/nextcloud/themes /var/www/html/themes
42-
fi
32+
33+
for dir in config data custom_apps themes; do
34+
if [ ! -d /var/www/html/"$dir" ] || directory_empty /var/www/html/"$dir"; then
35+
cp -arT /usr/src/nextcloud/"$dir" /var/www/html/"$dir"
36+
fi
37+
done
4338

4439
if [ "$installed_version" != "0.0.0~unknown" ]; then
4540
su - www-data -s /bin/bash -c 'php /var/www/html/occ upgrade --no-app-disable'

11.0/fpm/docker-entrypoint.sh

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ function version_greater() {
66
[[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ]];
77
}
88

9+
# return true if specified directory empty
10+
function directory_empty() {
11+
[ -n "$(find "$1"/ -prune -empty)" ]
12+
}
13+
14+
915
installed_version="0.0.0~unknown"
1016
if [ -f /var/www/html/version.php ]; then
1117
installed_version=$(php -r 'require "/var/www/html/version.php"; echo "$OC_VersionString";')
@@ -21,25 +27,14 @@ if version_greater "$image_version" "$installed_version"; then
2127
if [ "$installed_version" != "0.0.0~unknown" ]; then
2228
su - www-data -s /bin/bash -c 'php /var/www/html/occ app:list' > /tmp/list_before
2329
fi
24-
30+
2531
rsync -a --delete --exclude /config/ --exclude /data/ --exclude /custom_apps/ --exclude /themes/ /usr/src/nextcloud/ /var/www/html/
26-
27-
if [ ! -d /var/www/html/config ]; then
28-
cp -arT /usr/src/nextcloud/config /var/www/html/config
29-
fi
30-
31-
if [ ! -d /var/www/html/data ]; then
32-
cp -arT /usr/src/nextcloud/data /var/www/html/data
33-
fi
34-
35-
if [ ! -d /var/www/html/custom_apps ]; then
36-
cp -arT /usr/src/nextcloud/custom_apps /var/www/html/custom_apps
37-
cp -a /usr/src/nextcloud/config/apps.config.php /var/www/html/config/apps.config.php
38-
fi
39-
40-
if [ ! -d /var/www/html/themes ]; then
41-
cp -arT /usr/src/nextcloud/themes /var/www/html/themes
42-
fi
32+
33+
for dir in config data custom_apps themes; do
34+
if [ ! -d /var/www/html/"$dir" ] || directory_empty /var/www/html/"$dir"; then
35+
cp -arT /usr/src/nextcloud/"$dir" /var/www/html/"$dir"
36+
fi
37+
done
4338

4439
if [ "$installed_version" != "0.0.0~unknown" ]; then
4540
su - www-data -s /bin/bash -c 'php /var/www/html/occ upgrade --no-app-disable'

12.0/apache/docker-entrypoint.sh

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ function version_greater() {
66
[[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ]];
77
}
88

9+
# return true if specified directory empty
10+
function directory_empty() {
11+
[ -n "$(find "$1"/ -prune -empty)" ]
12+
}
13+
14+
915
installed_version="0.0.0~unknown"
1016
if [ -f /var/www/html/version.php ]; then
1117
installed_version=$(php -r 'require "/var/www/html/version.php"; echo "$OC_VersionString";')
@@ -21,25 +27,14 @@ if version_greater "$image_version" "$installed_version"; then
2127
if [ "$installed_version" != "0.0.0~unknown" ]; then
2228
su - www-data -s /bin/bash -c 'php /var/www/html/occ app:list' > /tmp/list_before
2329
fi
24-
30+
2531
rsync -a --delete --exclude /config/ --exclude /data/ --exclude /custom_apps/ --exclude /themes/ /usr/src/nextcloud/ /var/www/html/
26-
27-
if [ ! -d /var/www/html/config ]; then
28-
cp -arT /usr/src/nextcloud/config /var/www/html/config
29-
fi
30-
31-
if [ ! -d /var/www/html/data ]; then
32-
cp -arT /usr/src/nextcloud/data /var/www/html/data
33-
fi
34-
35-
if [ ! -d /var/www/html/custom_apps ]; then
36-
cp -arT /usr/src/nextcloud/custom_apps /var/www/html/custom_apps
37-
cp -a /usr/src/nextcloud/config/apps.config.php /var/www/html/config/apps.config.php
38-
fi
39-
40-
if [ ! -d /var/www/html/themes ]; then
41-
cp -arT /usr/src/nextcloud/themes /var/www/html/themes
42-
fi
32+
33+
for dir in config data custom_apps themes; do
34+
if [ ! -d /var/www/html/"$dir" ] || directory_empty /var/www/html/"$dir"; then
35+
cp -arT /usr/src/nextcloud/"$dir" /var/www/html/"$dir"
36+
fi
37+
done
4338

4439
if [ "$installed_version" != "0.0.0~unknown" ]; then
4540
su - www-data -s /bin/bash -c 'php /var/www/html/occ upgrade --no-app-disable'

12.0/fpm/docker-entrypoint.sh

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ function version_greater() {
66
[[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ]];
77
}
88

9+
# return true if specified directory empty
10+
function directory_empty() {
11+
[ -n "$(find "$1"/ -prune -empty)" ]
12+
}
13+
14+
915
installed_version="0.0.0~unknown"
1016
if [ -f /var/www/html/version.php ]; then
1117
installed_version=$(php -r 'require "/var/www/html/version.php"; echo "$OC_VersionString";')
@@ -21,25 +27,14 @@ if version_greater "$image_version" "$installed_version"; then
2127
if [ "$installed_version" != "0.0.0~unknown" ]; then
2228
su - www-data -s /bin/bash -c 'php /var/www/html/occ app:list' > /tmp/list_before
2329
fi
24-
30+
2531
rsync -a --delete --exclude /config/ --exclude /data/ --exclude /custom_apps/ --exclude /themes/ /usr/src/nextcloud/ /var/www/html/
26-
27-
if [ ! -d /var/www/html/config ]; then
28-
cp -arT /usr/src/nextcloud/config /var/www/html/config
29-
fi
30-
31-
if [ ! -d /var/www/html/data ]; then
32-
cp -arT /usr/src/nextcloud/data /var/www/html/data
33-
fi
34-
35-
if [ ! -d /var/www/html/custom_apps ]; then
36-
cp -arT /usr/src/nextcloud/custom_apps /var/www/html/custom_apps
37-
cp -a /usr/src/nextcloud/config/apps.config.php /var/www/html/config/apps.config.php
38-
fi
39-
40-
if [ ! -d /var/www/html/themes ]; then
41-
cp -arT /usr/src/nextcloud/themes /var/www/html/themes
42-
fi
32+
33+
for dir in config data custom_apps themes; do
34+
if [ ! -d /var/www/html/"$dir" ] || directory_empty /var/www/html/"$dir"; then
35+
cp -arT /usr/src/nextcloud/"$dir" /var/www/html/"$dir"
36+
fi
37+
done
4338

4439
if [ "$installed_version" != "0.0.0~unknown" ]; then
4540
su - www-data -s /bin/bash -c 'php /var/www/html/occ upgrade --no-app-disable'

docker-entrypoint.sh

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ function version_greater() {
66
[[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ]];
77
}
88

9+
# return true if specified directory empty
10+
function directory_empty() {
11+
[ -n "$(find "$1"/ -prune -empty)" ]
12+
}
13+
14+
915
installed_version="0.0.0~unknown"
1016
if [ -f /var/www/html/version.php ]; then
1117
installed_version=$(php -r 'require "/var/www/html/version.php"; echo "$OC_VersionString";')
@@ -21,25 +27,14 @@ if version_greater "$image_version" "$installed_version"; then
2127
if [ "$installed_version" != "0.0.0~unknown" ]; then
2228
su - www-data -s /bin/bash -c 'php /var/www/html/occ app:list' > /tmp/list_before
2329
fi
24-
30+
2531
rsync -a --delete --exclude /config/ --exclude /data/ --exclude /custom_apps/ --exclude /themes/ /usr/src/nextcloud/ /var/www/html/
26-
27-
if [ ! -d /var/www/html/config ]; then
28-
cp -arT /usr/src/nextcloud/config /var/www/html/config
29-
fi
30-
31-
if [ ! -d /var/www/html/data ]; then
32-
cp -arT /usr/src/nextcloud/data /var/www/html/data
33-
fi
34-
35-
if [ ! -d /var/www/html/custom_apps ]; then
36-
cp -arT /usr/src/nextcloud/custom_apps /var/www/html/custom_apps
37-
cp -a /usr/src/nextcloud/config/apps.config.php /var/www/html/config/apps.config.php
38-
fi
39-
40-
if [ ! -d /var/www/html/themes ]; then
41-
cp -arT /usr/src/nextcloud/themes /var/www/html/themes
42-
fi
32+
33+
for dir in config data custom_apps themes; do
34+
if [ ! -d /var/www/html/"$dir" ] || directory_empty /var/www/html/"$dir"; then
35+
cp -arT /usr/src/nextcloud/"$dir" /var/www/html/"$dir"
36+
fi
37+
done
4338

4439
if [ "$installed_version" != "0.0.0~unknown" ]; then
4540
su - www-data -s /bin/bash -c 'php /var/www/html/occ upgrade --no-app-disable'

0 commit comments

Comments
 (0)