aio-interface: extract Nextcloud latest-major upgrade logic to dedicated script and add UI trigger button (#7988)

* Extract Nextcloud major upgrade logic to script and add UI button

Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/8cd11b09-5073-4e27-8e59-9afffaf96c1f

Rename sendNotification to execCommandInContainer and reuse for upgrade method

Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/88744552-9d64-4de2-9f64-5a98a5e3b200

Add $cmd array validation to execCommandInContainer

Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/45d5228c-7834-404e-ba54-90b5c8c207c8

Apply suggestion from @szaimen

Signed-off-by: Simon L. <szaimen@e.mail.de>

Apply suggestion from @szaimen

Signed-off-by: Simon L. <szaimen@e.mail.de>

Apply suggestion from @szaimen

Signed-off-by: Simon L. <szaimen@e.mail.de>

Apply suggestion from @szaimen

Signed-off-by: Simon L. <szaimen@e.mail.de>

Set installLatestMajor when upgrade-to-latest-major button is clicked

Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/7b977c85-9b74-4027-a536-152e49a01976

Extract getLatestMajorVersion() to avoid duplicating the version string

Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/d5ec921f-8629-4f6e-949a-e8f89f1eb85f

Address PR review comments and hardcode updater channel to stable

Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/c40941ff-2bf8-4a57-82be-2a0bd22b19a2

Restore sendNotification(), update cron files, extract getPlainStreamingCallback()

Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/a5b6cd86-d278-4771-8a11-976c4a862966

Remove getPlainStreamingCallback, unify on getAddToStreamingResponseBody

Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/15a4b815-076b-469f-95b2-c61df688a28d

Revert "Remove getPlainStreamingCallback, unify on getAddToStreamingResponseBody"

This reverts commit 6846c3a99549703121461f910cc26e6c116e0dc4.

* Refactor creating and using addToStreamingResponseBody()

This way we stick to having one implementation of the function, not three.

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Read streamed output line by line, not via buffer

This way the code doesn't wait for a buffer to be filled, and we don't need to
implement logic ourselves that is provided by a present library already.

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Ensure all HTTP requests are proxied, even with streaming

When requesting a streamed response, Guzzle apparently doesn't use curl, and thus we have to specify the unix socket proxy differently.

We can't specify it when creating the client, though (Guzzle complains).

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Fix syntax errors

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Remove broken code

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Fix readline line from streaming response

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Strip ANSI codes from command output before sending it to the browser

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Run PHP commands as www-data

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Properly compare version numbers

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Fix using memory limits from env

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Fix return type spec

This method always returns a closure, never null.

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Use more general return type

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Avoid psalm complaint

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Fix namespace of return type

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>

* Apply suggestion from @szaimen

Signed-off-by: Simon L. <szaimen@e.mail.de>

---------

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
Signed-off-by: Simon L. <szaimen@e.mail.de>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Pablo Zmdl <pablo@nextcloud.com>
Co-authored-by: Simon L. <szaimen@e.mail.de>
This commit is contained in:
Copilot
2026-06-03 12:38:50 +02:00
committed by GitHub
parent 335db2aac2
commit 1f94bc8af0
7 changed files with 174 additions and 96 deletions
@@ -2,4 +2,5 @@
$CONFIG = array (
'one-click-instance' => true,
'one-click-instance.user-limit' => 100,
'update_channel' => 'stable',
);
+2 -31
View File
@@ -419,41 +419,12 @@ EOF
# AIO update to latest start # Do not remove or change this line!
if [ "$INSTALL_LATEST_MAJOR" = yes ]; then
php /var/www/html/occ config:system:set updatedirectory --value="/nc-updater"
INSTALLED_AT="$(php /var/www/html/occ config:app:get core installedat)"
if [ -n "${INSTALLED_AT}" ]; then
# Set the installdat to 00 which will allow to skip staging and install the next major directly
# shellcheck disable=SC2001
INSTALLED_AT="$(echo "${INSTALLED_AT}" | sed "s|[0-9][0-9]$|00|")"
php /var/www/html/occ config:app:set core installedat --value="${INSTALLED_AT}"
fi
php /var/www/html/updater/updater.phar --no-interaction --no-backup
if ! php /var/www/html/occ -V || php /var/www/html/occ status | grep maintenance | grep -q 'true'; then
echo "Installation of Nextcloud failed!"
touch "$NEXTCLOUD_DATA_DIR/install.failed"
if ! bash /upgrade-latest-major.sh; then
echo "Upgrade to latest major version failed! Check the output above for details."
exit 1
fi
# shellcheck disable=SC2016
installed_version="$(php -r 'require "/var/www/html/version.php"; echo implode(".", $OC_Version);')"
INSTALLED_MAJOR="${installed_version%%.*}"
IMAGE_MAJOR="${image_version%%.*}"
# If a valid upgrade path, trigger the Nextcloud built-in Updater
if ! [ "$INSTALLED_MAJOR" -gt "$IMAGE_MAJOR" ]; then
php /var/www/html/updater/updater.phar --no-interaction --no-backup
if ! php /var/www/html/occ -V || php /var/www/html/occ status | grep maintenance | grep -q 'true'; then
echo "Installation of Nextcloud failed!"
# TODO: Add a hint here about what to do / where to look / updater.log?
touch "$NEXTCLOUD_DATA_DIR/install.failed"
exit 1
fi
# shellcheck disable=SC2016
installed_version="$(php -r 'require "/var/www/html/version.php"; echo implode(".", $OC_Version);')"
fi
php /var/www/html/occ config:system:set updatechecker --type=bool --value=true
php /var/www/html/occ app:enable nextcloud-aio --force
php /var/www/html/occ db:add-missing-columns
php /var/www/html/occ db:add-missing-primary-keys
yes | php /var/www/html/occ db:convert-filecache-bigint
fi
# AIO update to latest end # Do not remove or change this line!
@@ -0,0 +1,43 @@
#!/bin/bash
PHP_CLI="php"
if [[ "$EUID" = 0 ]]; then
PHP_CLI="sudo -u www-data -E $PHP_CLI"
fi
# shellcheck disable=SC2016
image_version="$($PHP_CLI -r 'require "/var/www/html/version.php"; echo implode(".", $OC_Version);')"
export IMAGE_MAJOR="${image_version%%.*}"
$PHP_CLI /var/www/html/occ config:system:set updatedirectory --value="/nc-updater"
INSTALLED_AT="$($PHP_CLI /var/www/html/occ config:app:get core installedat)"
if [ -n "${INSTALLED_AT}" ]; then
# Set the installedat to 00 which will allow to skip staging and install the next major directly
# shellcheck disable=SC2001
INSTALLED_AT="$(echo "${INSTALLED_AT}" | sed "s|[0-9][0-9]$|00|")"
$PHP_CLI /var/www/html/occ config:app:set core installedat --value="${INSTALLED_AT}"
fi
$PHP_CLI /var/www/html/updater/updater.phar --no-interaction --no-backup
if ! $PHP_CLI /var/www/html/occ -V || $PHP_CLI /var/www/html/occ status | grep maintenance | grep -q 'true'; then
echo "Installation of Nextcloud failed!"
touch "$NEXTCLOUD_DATA_DIR/install.failed"
exit 1
fi
# shellcheck disable=SC2016
installed_version="$($PHP_CLI -r 'require "/var/www/html/version.php"; echo implode(".", $OC_Version);')"
export INSTALLED_MAJOR="${installed_version%%.*}"
# If a valid upgrade path, trigger the Nextcloud built-in Updater
if ! $PHP_CLI -r "version_compare(getenv('INSTALLED_MAJOR'), getenv('IMAGE_MAJOR'), '>') || exit(1);"; then
$PHP_CLI /var/www/html/updater/updater.phar --no-interaction --no-backup
if ! $PHP_CLI /var/www/html/occ -V || $PHP_CLI /var/www/html/occ status | grep maintenance | grep -q 'true'; then
echo "Installation of Nextcloud failed!"
# TODO: Add a hint here about what to do / where to look / updater.log?
touch "$NEXTCLOUD_DATA_DIR/install.failed"
exit 1
fi
fi
$PHP_CLI /var/www/html/occ config:system:set updatechecker --type=bool --value=true
$PHP_CLI /var/www/html/occ app:enable nextcloud-aio --force
$PHP_CLI /var/www/html/occ db:add-missing-columns
$PHP_CLI /var/www/html/occ db:add-missing-primary-keys
yes | $PHP_CLI /var/www/html/occ db:convert-filecache-bigint