diff --git a/Containers/nextcloud/entrypoint.sh b/Containers/nextcloud/entrypoint.sh index 07e0ae24..98ebf8d0 100644 --- a/Containers/nextcloud/entrypoint.sh +++ b/Containers/nextcloud/entrypoint.sh @@ -419,41 +419,10 @@ 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! diff --git a/Containers/nextcloud/upgrade-latest-major.sh b/Containers/nextcloud/upgrade-latest-major.sh new file mode 100644 index 00000000..3729e2a4 --- /dev/null +++ b/Containers/nextcloud/upgrade-latest-major.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# shellcheck disable=SC2016 +image_version="$(php -r 'require "/var/www/html/version.php"; echo implode(".", $OC_Version);')" +IMAGE_MAJOR="${image_version%%.*}" + +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 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 /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" + exit 1 +fi +# shellcheck disable=SC2016 +installed_version="$(php -r 'require "/var/www/html/version.php"; echo implode(".", $OC_Version);')" +INSTALLED_MAJOR="${installed_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 diff --git a/php/public/index.php b/php/public/index.php index 4c64ab31..b4af0730 100644 --- a/php/public/index.php +++ b/php/public/index.php @@ -104,6 +104,7 @@ $app->post('/api/docker/backup-test', AIO\Controller\DockerController::class . ' $app->post('/api/docker/restore', AIO\Controller\DockerController::class . ':StartBackupContainerRestore'); $app->post('/api/docker/stop', AIO\Controller\DockerController::class . ':StopContainer'); $app->post('/api/docker/backup-reset-location', AIO\Controller\DockerController::class . ':DeleteBorgBackupConfig'); +$app->post('/api/docker/nextcloud-upgrade-to-latest-major', AIO\Controller\DockerController::class . ':RunNextcloudUpgradeToLatestMajor'); $app->post('/api/docker/prune', AIO\Controller\DockerController::class . ':SystemPrune'); $app->get('/api/docker/logs', AIO\Controller\DockerController::class . ':GetLogs'); $app->post('/api/auth/login', AIO\Controller\LoginController::class . ':TryLogin'); diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index 66e8a3e2..0b9b7e6a 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -333,6 +333,21 @@ readonly class DockerController { return $response->withStatus(201)->withHeader('Location', '.'); } + public function RunNextcloudUpgradeToLatestMajor(Request $request, Response $response, array $args) : Response { + // Get streaming response start and closure + $nonbufResp = $this->startStreamingResponse($response); + $body = $nonbufResp->getBody(); + $addToStreamingResponseBody = function (string $message) use ($body) : void { + $body->write("
" . htmlspecialchars($message, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . "
"); + }; + + $this->dockerActionManager->RunNextcloudUpgradeToLatestMajor($addToStreamingResponseBody); + + // End streaming response + $this->finalizeStreamingResponse($nonbufResp); + return $nonbufResp; + } + public function SystemPrune(Request $request, Response $response, array $args) : Response { // Get streaming response start and closure $nonbufResp = $this->startStreamingResponse($response); diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index ca6a4d72..b7f7d9f9 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -1027,6 +1027,66 @@ readonly class DockerActionManager { } } + public function RunNextcloudUpgradeToLatestMajor(\Closure $addToStreamingResponseBody): void { + $containerName = 'nextcloud-aio-nextcloud'; + + // Create exec instance + $url = $this->BuildApiUrl(sprintf('containers/%s/exec', urlencode($containerName))); + $response = json_decode( + $this->guzzleClient->request( + 'POST', + $url, + [ + 'json' => [ + 'AttachStdout' => true, + 'AttachStderr' => true, + 'Tty' => true, + 'Cmd' => ['bash', '/upgrade-latest-major.sh'], + ], + ] + )->getBody()->getContents(), + true, + 512, + JSON_THROW_ON_ERROR, + ); + + $execId = $response['Id']; + + // Start exec and stream output + $url = $this->BuildApiUrl(sprintf('exec/%s/start', $execId)); + $streamResponse = $this->guzzleClient->request( + 'POST', + $url, + [ + 'stream' => true, + 'json' => [ + 'Detach' => false, + 'Tty' => true, + ], + ] + ); + + $body = $streamResponse->getBody(); + $buffer = ''; + while (!$body->eof()) { + $chunk = $body->read(1024); + $buffer .= $chunk; + // Flush complete lines + while (($pos = strpos($buffer, "\n")) !== false) { + $line = substr($buffer, 0, $pos); + $buffer = substr($buffer, $pos + 1); + $line = rtrim($line, "\r"); + if ($line !== '') { + $addToStreamingResponseBody($line); + } + } + } + // Flush any remaining output + if (trim($buffer) !== '') { + $addToStreamingResponseBody(trim($buffer)); + } + } + public function SystemPrune(?\Closure $addToStreamingResponseBody = null): void { $endpoints = [ // Remove stopped containers diff --git a/php/templates/containers.twig b/php/templates/containers.twig index 8faa4474..ebcd8d1f 100644 --- a/php/templates/containers.twig +++ b/php/templates/containers.twig @@ -299,6 +299,12 @@
Note about Nextcloud Hub {{ newMajorVersionString }}

If you haven't upgraded to Nextcloud Hub {{ newMajorVersionString }} yet and want to do that now, feel free to follow this documentation

+

Alternatively, you can trigger the upgrade directly from here:

+
+ + + +
{% endif %} {% endif %}