diff --git a/index.php b/index.php index dd787d2f..7ebb6fd2 100644 --- a/index.php +++ b/index.php @@ -546,10 +546,17 @@ private function getUpdateServerResponse(): array { * * @throws \Exception */ - public function downloadUpdate(): void { + public function downloadUpdate(?string $url = null): void { $this->silentLog('[info] downloadUpdate()'); - $downloadURLs = $this->getDownloadURLs(); + if ($url) { + // If a URL is provided, use it directly + $downloadURLs = [$url]; + } else { + // Otherwise, get the download URLs from the update server + $downloadURLs = $this->getDownloadURLs(); + } + $this->silentLog('[info] will try to download archive from: ' . implode(', ', $downloadURLs)); $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/downloads/'; @@ -743,7 +750,7 @@ private function getDownloadedFilePath(): string { * * @throws \Exception */ - public function verifyIntegrity(): void { + public function verifyIntegrity(?string $urlOverride = null): void { $this->silentLog('[info] verifyIntegrity()'); if ($this->getCurrentReleaseChannel() === 'daily') { @@ -751,6 +758,11 @@ public function verifyIntegrity(): void { return; } + if ($urlOverride) { + $this->silentLog('[info] custom download url provided, cannot verify signature'); + return; + } + $response = $this->getUpdateServerResponse(); if (empty($response['signature'])) { throw new \Exception('No signature specified for defined update'); diff --git a/lib/UpdateCommand.php b/lib/UpdateCommand.php index 718f224b..9a410ad5 100644 --- a/lib/UpdateCommand.php +++ b/lib/UpdateCommand.php @@ -21,6 +21,7 @@ class UpdateCommand extends Command { protected bool $shouldStop = false; protected bool $skipBackup = false; protected bool $skipUpgrade = false; + protected string $urlOverride = ''; /** @var list strings of text for stages of updater */ protected array $checkTexts = [ @@ -45,7 +46,8 @@ protected function configure(): void { ->setDescription('Updates the code of an Nextcloud instance') ->setHelp("This command fetches the latest code that is announced via the updater server and safely replaces the existing code with the new one.") ->addOption('no-backup', null, InputOption::VALUE_NONE, 'Skip backup of current Nextcloud version') - ->addOption('no-upgrade', null, InputOption::VALUE_NONE, "Don't automatically run occ upgrade"); + ->addOption('no-upgrade', null, InputOption::VALUE_NONE, "Don't automatically run occ upgrade") + ->addOption('url', null, InputOption::VALUE_OPTIONAL, 'The URL of the Nextcloud release to download'); } public static function getUpdaterVersion(): string { @@ -60,6 +62,7 @@ public static function getUpdaterVersion(): string { protected function execute(InputInterface $input, OutputInterface $output) { $this->skipBackup = (bool)$input->getOption('no-backup'); $this->skipUpgrade = (bool)$input->getOption('no-upgrade'); + $this->urlOverride = (string)$input->getOption('url'); $version = static::getUpdaterVersion(); $output->writeln('Nextcloud Updater - version: ' . $version); @@ -133,7 +136,12 @@ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('Current version is ' . $this->updater->getCurrentVersion() . '.'); // needs to be called that early because otherwise updateAvailable() returns false - $updateString = $this->updater->checkForUpdate(); + if ($this->urlOverride) { + $this->updater->log('[info] Using URL override: ' . $this->urlOverride); + $updateString = 'Update check forced with URL override: ' . $this->urlOverride; + } else { + $updateString = $this->updater->checkForUpdate(); + } $output->writeln(''); @@ -146,9 +154,11 @@ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln(''); - if (!$this->updater->updateAvailable() && $stepNumber === 0) { - $output->writeln('Nothing to do.'); - return 0; + if (!$this->urlOverride) { + if (!$this->updater->updateAvailable() && $stepNumber === 0) { + $output->writeln('Nothing to do.'); + return 0; + } } $questionText = 'Start update'; @@ -360,10 +370,10 @@ protected function executeStep(int $step): array { } break; case 4: - $this->updater->downloadUpdate(); + $this->updater->downloadUpdate($this->urlOverride); break; case 5: - $this->updater->verifyIntegrity(); + $this->updater->verifyIntegrity($this->urlOverride); break; case 6: $this->updater->extractDownload(); diff --git a/lib/Updater.php b/lib/Updater.php index 70f06bcc..87fa4698 100644 --- a/lib/Updater.php +++ b/lib/Updater.php @@ -508,10 +508,17 @@ private function getUpdateServerResponse(): array { * * @throws \Exception */ - public function downloadUpdate(): void { + public function downloadUpdate(?string $url = null): void { $this->silentLog('[info] downloadUpdate()'); - $downloadURLs = $this->getDownloadURLs(); + if ($url) { + // If a URL is provided, use it directly + $downloadURLs = [$url]; + } else { + // Otherwise, get the download URLs from the update server + $downloadURLs = $this->getDownloadURLs(); + } + $this->silentLog('[info] will try to download archive from: ' . implode(', ', $downloadURLs)); $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/downloads/'; @@ -705,7 +712,7 @@ private function getDownloadedFilePath(): string { * * @throws \Exception */ - public function verifyIntegrity(): void { + public function verifyIntegrity(?string $urlOverride = null): void { $this->silentLog('[info] verifyIntegrity()'); if ($this->getCurrentReleaseChannel() === 'daily') { @@ -713,6 +720,11 @@ public function verifyIntegrity(): void { return; } + if ($urlOverride) { + $this->silentLog('[info] custom download url provided, cannot verify signature'); + return; + } + $response = $this->getUpdateServerResponse(); if (empty($response['signature'])) { throw new \Exception('No signature specified for defined update'); diff --git a/updater.phar b/updater.phar index ab9b1183..1081ba2f 100755 Binary files a/updater.phar and b/updater.phar differ diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 480c81a8..2658558b 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'bbd6e8e521f3fd1d02d34e3c9eda83c4c8d4c460', + 'reference' => 'd57261832b96a413d7ae92aa66ac15054ae8f4d5', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'bbd6e8e521f3fd1d02d34e3c9eda83c4c8d4c460', + 'reference' => 'd57261832b96a413d7ae92aa66ac15054ae8f4d5', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(),