From d6b4877b36c743ba1b72c294e30f1cf7494aaf32 Mon Sep 17 00:00:00 2001 From: Stephan Brunner Date: Sun, 2 Mar 2025 09:31:13 +0100 Subject: [PATCH] Add ability to force reinitialization by putting a marker file in the tmp folder We have a custom image where we'd like to recopy all of nextcloud's source code again when we update some internal thing without a change in Nextcloud's version. The newly added pre-initialization hook can be used to determine this and force a rerun. Signed-off-by: Stephan Brunner --- 29/apache/entrypoint.sh | 17 ++++++++++++++++- 29/fpm-alpine/entrypoint.sh | 17 ++++++++++++++++- 29/fpm/entrypoint.sh | 17 ++++++++++++++++- 30/apache/entrypoint.sh | 17 ++++++++++++++++- 30/fpm-alpine/entrypoint.sh | 17 ++++++++++++++++- 30/fpm/entrypoint.sh | 17 ++++++++++++++++- 31/apache/entrypoint.sh | 17 ++++++++++++++++- 31/fpm-alpine/entrypoint.sh | 17 ++++++++++++++++- 31/fpm/entrypoint.sh | 17 ++++++++++++++++- README.md | 10 ++++++++++ docker-entrypoint.sh | 15 +++++++++++++++ 11 files changed, 169 insertions(+), 9 deletions(-) diff --git a/29/apache/entrypoint.sh b/29/apache/entrypoint.sh index 118e9b73..17b85355 100755 --- a/29/apache/entrypoint.sh +++ b/29/apache/entrypoint.sh @@ -156,7 +156,18 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP exit 1 fi + need_initialization=false + if version_greater "$image_version" "$installed_version"; then + need_initialization=true + fi + + if [ -f /tmp/nextcloud-force-initialization ]; then + echo Found /tmp/nextcloud-force-initialization, forcing initialization + need_initialization=true + fi + + if [ "true" = "$need_initialization" ]; then echo "Initializing nextcloud $image_version ..." if [ "$installed_version" != "0.0.0.0" ]; then if [ "${image_version%%.*}" -gt "$((${installed_version%%.*} + 1))" ]; then @@ -248,7 +259,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP fi run_path post-installation - fi + fi fi # not enough specified to do a fully automated installation if [ "$install" = false ]; then @@ -269,6 +280,10 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP run_path post-upgrade fi + if [ -f /tmp/nextcloud-force-initialization ]; then + rm /tmp/nextcloud-force-initialization + fi + echo "Initializing finished" fi diff --git a/29/fpm-alpine/entrypoint.sh b/29/fpm-alpine/entrypoint.sh index 118e9b73..17b85355 100755 --- a/29/fpm-alpine/entrypoint.sh +++ b/29/fpm-alpine/entrypoint.sh @@ -156,7 +156,18 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP exit 1 fi + need_initialization=false + if version_greater "$image_version" "$installed_version"; then + need_initialization=true + fi + + if [ -f /tmp/nextcloud-force-initialization ]; then + echo Found /tmp/nextcloud-force-initialization, forcing initialization + need_initialization=true + fi + + if [ "true" = "$need_initialization" ]; then echo "Initializing nextcloud $image_version ..." if [ "$installed_version" != "0.0.0.0" ]; then if [ "${image_version%%.*}" -gt "$((${installed_version%%.*} + 1))" ]; then @@ -248,7 +259,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP fi run_path post-installation - fi + fi fi # not enough specified to do a fully automated installation if [ "$install" = false ]; then @@ -269,6 +280,10 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP run_path post-upgrade fi + if [ -f /tmp/nextcloud-force-initialization ]; then + rm /tmp/nextcloud-force-initialization + fi + echo "Initializing finished" fi diff --git a/29/fpm/entrypoint.sh b/29/fpm/entrypoint.sh index 118e9b73..17b85355 100755 --- a/29/fpm/entrypoint.sh +++ b/29/fpm/entrypoint.sh @@ -156,7 +156,18 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP exit 1 fi + need_initialization=false + if version_greater "$image_version" "$installed_version"; then + need_initialization=true + fi + + if [ -f /tmp/nextcloud-force-initialization ]; then + echo Found /tmp/nextcloud-force-initialization, forcing initialization + need_initialization=true + fi + + if [ "true" = "$need_initialization" ]; then echo "Initializing nextcloud $image_version ..." if [ "$installed_version" != "0.0.0.0" ]; then if [ "${image_version%%.*}" -gt "$((${installed_version%%.*} + 1))" ]; then @@ -248,7 +259,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP fi run_path post-installation - fi + fi fi # not enough specified to do a fully automated installation if [ "$install" = false ]; then @@ -269,6 +280,10 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP run_path post-upgrade fi + if [ -f /tmp/nextcloud-force-initialization ]; then + rm /tmp/nextcloud-force-initialization + fi + echo "Initializing finished" fi diff --git a/30/apache/entrypoint.sh b/30/apache/entrypoint.sh index 118e9b73..17b85355 100755 --- a/30/apache/entrypoint.sh +++ b/30/apache/entrypoint.sh @@ -156,7 +156,18 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP exit 1 fi + need_initialization=false + if version_greater "$image_version" "$installed_version"; then + need_initialization=true + fi + + if [ -f /tmp/nextcloud-force-initialization ]; then + echo Found /tmp/nextcloud-force-initialization, forcing initialization + need_initialization=true + fi + + if [ "true" = "$need_initialization" ]; then echo "Initializing nextcloud $image_version ..." if [ "$installed_version" != "0.0.0.0" ]; then if [ "${image_version%%.*}" -gt "$((${installed_version%%.*} + 1))" ]; then @@ -248,7 +259,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP fi run_path post-installation - fi + fi fi # not enough specified to do a fully automated installation if [ "$install" = false ]; then @@ -269,6 +280,10 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP run_path post-upgrade fi + if [ -f /tmp/nextcloud-force-initialization ]; then + rm /tmp/nextcloud-force-initialization + fi + echo "Initializing finished" fi diff --git a/30/fpm-alpine/entrypoint.sh b/30/fpm-alpine/entrypoint.sh index 118e9b73..17b85355 100755 --- a/30/fpm-alpine/entrypoint.sh +++ b/30/fpm-alpine/entrypoint.sh @@ -156,7 +156,18 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP exit 1 fi + need_initialization=false + if version_greater "$image_version" "$installed_version"; then + need_initialization=true + fi + + if [ -f /tmp/nextcloud-force-initialization ]; then + echo Found /tmp/nextcloud-force-initialization, forcing initialization + need_initialization=true + fi + + if [ "true" = "$need_initialization" ]; then echo "Initializing nextcloud $image_version ..." if [ "$installed_version" != "0.0.0.0" ]; then if [ "${image_version%%.*}" -gt "$((${installed_version%%.*} + 1))" ]; then @@ -248,7 +259,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP fi run_path post-installation - fi + fi fi # not enough specified to do a fully automated installation if [ "$install" = false ]; then @@ -269,6 +280,10 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP run_path post-upgrade fi + if [ -f /tmp/nextcloud-force-initialization ]; then + rm /tmp/nextcloud-force-initialization + fi + echo "Initializing finished" fi diff --git a/30/fpm/entrypoint.sh b/30/fpm/entrypoint.sh index 118e9b73..17b85355 100755 --- a/30/fpm/entrypoint.sh +++ b/30/fpm/entrypoint.sh @@ -156,7 +156,18 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP exit 1 fi + need_initialization=false + if version_greater "$image_version" "$installed_version"; then + need_initialization=true + fi + + if [ -f /tmp/nextcloud-force-initialization ]; then + echo Found /tmp/nextcloud-force-initialization, forcing initialization + need_initialization=true + fi + + if [ "true" = "$need_initialization" ]; then echo "Initializing nextcloud $image_version ..." if [ "$installed_version" != "0.0.0.0" ]; then if [ "${image_version%%.*}" -gt "$((${installed_version%%.*} + 1))" ]; then @@ -248,7 +259,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP fi run_path post-installation - fi + fi fi # not enough specified to do a fully automated installation if [ "$install" = false ]; then @@ -269,6 +280,10 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP run_path post-upgrade fi + if [ -f /tmp/nextcloud-force-initialization ]; then + rm /tmp/nextcloud-force-initialization + fi + echo "Initializing finished" fi diff --git a/31/apache/entrypoint.sh b/31/apache/entrypoint.sh index 118e9b73..17b85355 100755 --- a/31/apache/entrypoint.sh +++ b/31/apache/entrypoint.sh @@ -156,7 +156,18 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP exit 1 fi + need_initialization=false + if version_greater "$image_version" "$installed_version"; then + need_initialization=true + fi + + if [ -f /tmp/nextcloud-force-initialization ]; then + echo Found /tmp/nextcloud-force-initialization, forcing initialization + need_initialization=true + fi + + if [ "true" = "$need_initialization" ]; then echo "Initializing nextcloud $image_version ..." if [ "$installed_version" != "0.0.0.0" ]; then if [ "${image_version%%.*}" -gt "$((${installed_version%%.*} + 1))" ]; then @@ -248,7 +259,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP fi run_path post-installation - fi + fi fi # not enough specified to do a fully automated installation if [ "$install" = false ]; then @@ -269,6 +280,10 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP run_path post-upgrade fi + if [ -f /tmp/nextcloud-force-initialization ]; then + rm /tmp/nextcloud-force-initialization + fi + echo "Initializing finished" fi diff --git a/31/fpm-alpine/entrypoint.sh b/31/fpm-alpine/entrypoint.sh index 118e9b73..17b85355 100755 --- a/31/fpm-alpine/entrypoint.sh +++ b/31/fpm-alpine/entrypoint.sh @@ -156,7 +156,18 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP exit 1 fi + need_initialization=false + if version_greater "$image_version" "$installed_version"; then + need_initialization=true + fi + + if [ -f /tmp/nextcloud-force-initialization ]; then + echo Found /tmp/nextcloud-force-initialization, forcing initialization + need_initialization=true + fi + + if [ "true" = "$need_initialization" ]; then echo "Initializing nextcloud $image_version ..." if [ "$installed_version" != "0.0.0.0" ]; then if [ "${image_version%%.*}" -gt "$((${installed_version%%.*} + 1))" ]; then @@ -248,7 +259,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP fi run_path post-installation - fi + fi fi # not enough specified to do a fully automated installation if [ "$install" = false ]; then @@ -269,6 +280,10 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP run_path post-upgrade fi + if [ -f /tmp/nextcloud-force-initialization ]; then + rm /tmp/nextcloud-force-initialization + fi + echo "Initializing finished" fi diff --git a/31/fpm/entrypoint.sh b/31/fpm/entrypoint.sh index 118e9b73..17b85355 100755 --- a/31/fpm/entrypoint.sh +++ b/31/fpm/entrypoint.sh @@ -156,7 +156,18 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP exit 1 fi + need_initialization=false + if version_greater "$image_version" "$installed_version"; then + need_initialization=true + fi + + if [ -f /tmp/nextcloud-force-initialization ]; then + echo Found /tmp/nextcloud-force-initialization, forcing initialization + need_initialization=true + fi + + if [ "true" = "$need_initialization" ]; then echo "Initializing nextcloud $image_version ..." if [ "$installed_version" != "0.0.0.0" ]; then if [ "${image_version%%.*}" -gt "$((${installed_version%%.*} + 1))" ]; then @@ -248,7 +259,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP fi run_path post-installation - fi + fi fi # not enough specified to do a fully automated installation if [ "$install" = false ]; then @@ -269,6 +280,10 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP run_path post-upgrade fi + if [ -f /tmp/nextcloud-force-initialization ]; then + rm /tmp/nextcloud-force-initialization + fi + echo "Initializing finished" fi diff --git a/README.md b/README.md index f67f9ffc..7fcc3ef1 100644 --- a/README.md +++ b/README.md @@ -393,6 +393,16 @@ To use the hooks triggered by the `entrypoint` script, either ... ``` +## Forcing an upgrade run + +Sometimes you need to force an explicit upgrade run even when the bundled Nextcloud version did not change. +An example would be when you have custom apps bundled and you want to update those. + +To do this, you can simply create a file `/tmp/nextcloud-force-initialization` before the need for an upgrade is determined. +The content is irrelevant. +You can either create this file before starting the container, or you can use the `pre-initialization` hook to create it. +After the update has successfully run, the file is removed automatically. + # Running this image with `docker compose` The easiest way to get a fully featured and functional setup is using a `compose.yaml` file. There are too many different possibilities to setup your system, so here are only some examples of what you have to look for. diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 118e9b73..b68a96b8 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -156,7 +156,18 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP exit 1 fi + need_initialization=false + if version_greater "$image_version" "$installed_version"; then + need_initialization=true + fi + + if [ -f /tmp/nextcloud-force-initialization ]; then + echo Found /tmp/nextcloud-force-initialization, forcing initialization + need_initialization=true + fi + + if [ "true" = "$need_initialization" ]; then echo "Initializing nextcloud $image_version ..." if [ "$installed_version" != "0.0.0.0" ]; then if [ "${image_version%%.*}" -gt "$((${installed_version%%.*} + 1))" ]; then @@ -269,6 +280,10 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP run_path post-upgrade fi + if [ -f /tmp/nextcloud-force-initialization ]; then + rm /tmp/nextcloud-force-initialization + fi + echo "Initializing finished" fi