@@ -19,6 +19,37 @@ run_as() {
1919 fi
2020}
2121
22+ # Function to get and validate Nextcloud version from version.php
23+ # Arguments:
24+ # $1 - path to version.php file
25+ # $2 - description (e.g., "installed" or "image") for error messages
26+ # Returns: version string on success, exits on failure
27+ get_nextcloud_version () {
28+ version_file=" $1 "
29+ description=" $2 "
30+
31+ # shellcheck disable=SC2016
32+ php_output=" $( php -r ' require "' " $version_file " ' "; echo implode(".", $OC_Version);' 2>&1 ) "
33+ php_exit_code=$?
34+
35+ if [ $php_exit_code -ne 0 ] || echo " $php_output " | grep -qiE ' (error|warning|fatal)' ; then
36+ echo " Error: Failed to determine $description Nextcloud version." >&2
37+ echo " PHP output: $php_output " >&2
38+ echo " This usually indicates PHP is broken or missing required modules." >&2
39+ exit 1
40+ fi
41+
42+ # Validate version format (should be at least 3 numeric parts, optionally 4)
43+ # e.g., "32.0.3" or "32.0.3.2" - but NOT "32.0"
44+ if ! echo " $php_output " | grep -qE ' ^[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?$' ; then
45+ echo " Error: Invalid $description version format: $php_output " >&2
46+ echo " Expected version number format with at least 3 parts (e.g., 32.0.3 or 32.0.3.2), but got unexpected output." >&2
47+ exit 1
48+ fi
49+
50+ echo " $php_output "
51+ }
52+
2253# Execute all executable files in a given directory in alphanumeric order
2354run_path () {
2455 local hook_folder_path=" /docker-entrypoint-hooks.d/$1 "
@@ -159,10 +190,10 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
159190 installed_version=" 0.0.0.0"
160191 if [ -f /var/www/html/version.php ]; then
161192 # shellcheck disable=SC2016
162- installed_version=" $( php -r ' require "/var/www/html/version.php"; echo implode(".", $OC_Version); ' ) "
193+ installed_version=" $( get_nextcloud_version " /var/www/html/version.php" " installed " ) "
163194 fi
164195 # shellcheck disable=SC2016
165- image_version=" $( php -r ' require "/usr/src/nextcloud/version.php"; echo implode(".", $OC_Version); ' ) "
196+ image_version=" $( get_nextcloud_version " /usr/src/nextcloud/version.php" " image " ) "
166197
167198 if version_greater " $installed_version " " $image_version " ; then
168199 echo " Can't start Nextcloud because the version of the data ($installed_version ) is higher than the docker image version ($image_version ) and downgrading is not supported. Are you sure you have pulled the newest image version?"
0 commit comments