Skip to content

Commit d18e212

Browse files
skjnldsvbackportbot[bot]
authored andcommitted
feat: allow to provide manual URL
Signed-off-by: skjnldsv <[email protected]> [skip ci]
1 parent c47c8a5 commit d18e212

3 files changed

Lines changed: 47 additions & 13 deletions

File tree

index.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,17 @@ private function getUpdateServerResponse(): array {
546546
*
547547
* @throws \Exception
548548
*/
549-
public function downloadUpdate(): void {
549+
public function downloadUpdate(?string $url = null): void {
550550
$this->silentLog('[info] downloadUpdate()');
551551

552-
$downloadURLs = $this->getDownloadURLs();
552+
if ($url) {
553+
// If a URL is provided, use it directly
554+
$downloadURLs = [$url];
555+
} else {
556+
// Otherwise, get the download URLs from the update server
557+
$downloadURLs = $this->getDownloadURLs();
558+
}
559+
553560
$this->silentLog('[info] will try to download archive from: ' . implode(', ', $downloadURLs));
554561

555562
$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/downloads/';
@@ -743,14 +750,19 @@ private function getDownloadedFilePath(): string {
743750
*
744751
* @throws \Exception
745752
*/
746-
public function verifyIntegrity(): void {
753+
public function verifyIntegrity(?string $urlOverride = null): void {
747754
$this->silentLog('[info] verifyIntegrity()');
748755

749756
if ($this->getCurrentReleaseChannel() === 'daily') {
750757
$this->silentLog('[info] current channel is "daily" which is not signed. Skipping verification.');
751758
return;
752759
}
753760

761+
if ($urlOverride) {
762+
$this->silentLog('[info] custom download url provided, cannot verify signature');
763+
return;
764+
}
765+
754766
$response = $this->getUpdateServerResponse();
755767
if (empty($response['signature'])) {
756768
throw new \Exception('No signature specified for defined update');

lib/UpdateCommand.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class UpdateCommand extends Command {
2121
protected bool $shouldStop = false;
2222
protected bool $skipBackup = false;
2323
protected bool $skipUpgrade = false;
24+
protected string $urlOverride = '';
2425

2526
/** @var list<string> strings of text for stages of updater */
2627
protected array $checkTexts = [
@@ -45,7 +46,8 @@ protected function configure(): void {
4546
->setDescription('Updates the code of an Nextcloud instance')
4647
->setHelp("This command fetches the latest code that is announced via the updater server and safely replaces the existing code with the new one.")
4748
->addOption('no-backup', null, InputOption::VALUE_NONE, 'Skip backup of current Nextcloud version')
48-
->addOption('no-upgrade', null, InputOption::VALUE_NONE, "Don't automatically run occ upgrade");
49+
->addOption('no-upgrade', null, InputOption::VALUE_NONE, "Don't automatically run occ upgrade")
50+
->addOption('url', null, InputOption::VALUE_OPTIONAL, 'The URL of the Nextcloud release to download');
4951
}
5052

5153
public static function getUpdaterVersion(): string {
@@ -60,6 +62,7 @@ public static function getUpdaterVersion(): string {
6062
protected function execute(InputInterface $input, OutputInterface $output) {
6163
$this->skipBackup = (bool)$input->getOption('no-backup');
6264
$this->skipUpgrade = (bool)$input->getOption('no-upgrade');
65+
$this->urlOverride = (string)$input->getOption('url');
6366

6467
$version = static::getUpdaterVersion();
6568
$output->writeln('Nextcloud Updater - version: ' . $version);
@@ -133,7 +136,12 @@ protected function execute(InputInterface $input, OutputInterface $output) {
133136
$output->writeln('Current version is ' . $this->updater->getCurrentVersion() . '.');
134137

135138
// needs to be called that early because otherwise updateAvailable() returns false
136-
$updateString = $this->updater->checkForUpdate();
139+
if ($this->urlOverride) {
140+
$this->updater->log('[info] Using URL override: ' . $this->urlOverride);
141+
$updateString = 'Update check forced with URL override: ' . $this->urlOverride;
142+
} else {
143+
$updateString = $this->updater->checkForUpdate();
144+
}
137145

138146
$output->writeln('');
139147

@@ -146,9 +154,11 @@ protected function execute(InputInterface $input, OutputInterface $output) {
146154

147155
$output->writeln('');
148156

149-
if (!$this->updater->updateAvailable() && $stepNumber === 0) {
150-
$output->writeln('Nothing to do.');
151-
return 0;
157+
if (!$this->urlOverride) {
158+
if (!$this->updater->updateAvailable() && $stepNumber === 0) {
159+
$output->writeln('Nothing to do.');
160+
return 0;
161+
}
152162
}
153163

154164
$questionText = 'Start update';
@@ -360,10 +370,10 @@ protected function executeStep(int $step): array {
360370
}
361371
break;
362372
case 4:
363-
$this->updater->downloadUpdate();
373+
$this->updater->downloadUpdate($this->urlOverride);
364374
break;
365375
case 5:
366-
$this->updater->verifyIntegrity();
376+
$this->updater->verifyIntegrity($this->urlOverride);
367377
break;
368378
case 6:
369379
$this->updater->extractDownload();

lib/Updater.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,17 @@ private function getUpdateServerResponse(): array {
508508
*
509509
* @throws \Exception
510510
*/
511-
public function downloadUpdate(): void {
511+
public function downloadUpdate(?string $url = null): void {
512512
$this->silentLog('[info] downloadUpdate()');
513513

514-
$downloadURLs = $this->getDownloadURLs();
514+
if ($url) {
515+
// If a URL is provided, use it directly
516+
$downloadURLs = [$url];
517+
} else {
518+
// Otherwise, get the download URLs from the update server
519+
$downloadURLs = $this->getDownloadURLs();
520+
}
521+
515522
$this->silentLog('[info] will try to download archive from: ' . implode(', ', $downloadURLs));
516523

517524
$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/downloads/';
@@ -705,14 +712,19 @@ private function getDownloadedFilePath(): string {
705712
*
706713
* @throws \Exception
707714
*/
708-
public function verifyIntegrity(): void {
715+
public function verifyIntegrity(?string $urlOverride = null): void {
709716
$this->silentLog('[info] verifyIntegrity()');
710717

711718
if ($this->getCurrentReleaseChannel() === 'daily') {
712719
$this->silentLog('[info] current channel is "daily" which is not signed. Skipping verification.');
713720
return;
714721
}
715722

723+
if ($urlOverride) {
724+
$this->silentLog('[info] custom download url provided, cannot verify signature');
725+
return;
726+
}
727+
716728
$response = $this->getUpdateServerResponse();
717729
if (empty($response['signature'])) {
718730
throw new \Exception('No signature specified for defined update');

0 commit comments

Comments
 (0)