diff --git a/index.php b/index.php index 62d7606c..8c4f5bbd 100644 --- a/index.php +++ b/index.php @@ -567,7 +567,7 @@ private function getUpdateServerResponse(): array { * * @throws \Exception */ - public function downloadUpdate(): void { + public function downloadUpdate(?string $url = null): void { $this->silentLog('[info] downloadUpdate()'); $response = $this->getUpdateServerResponse(); @@ -662,7 +662,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') { @@ -670,6 +670,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 22cc87d0..8db68550 100644 --- a/lib/UpdateCommand.php +++ b/lib/UpdateCommand.php @@ -36,6 +36,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 = [ @@ -60,7 +61,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 { @@ -75,6 +77,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); @@ -148,7 +151,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(''); @@ -161,9 +169,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'; @@ -375,10 +385,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 f1725aa1..708f1295 100644 --- a/lib/Updater.php +++ b/lib/Updater.php @@ -529,7 +529,7 @@ private function getUpdateServerResponse(): array { * * @throws \Exception */ - public function downloadUpdate(): void { + public function downloadUpdate(?string $url = null): void { $this->silentLog('[info] downloadUpdate()'); $response = $this->getUpdateServerResponse(); @@ -624,7 +624,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') { @@ -632,6 +632,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/vendor/composer/platform_check.php b/vendor/composer/platform_check.php index 580fa960..d2225c7d 100644 --- a/vendor/composer/platform_check.php +++ b/vendor/composer/platform_check.php @@ -19,8 +19,7 @@ echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL; } } - trigger_error( - 'Composer detected issues in your platform: ' . implode(' ', $issues), - E_USER_ERROR + throw new \RuntimeException( + 'Composer detected issues in your platform: ' . implode(' ', $issues) ); }