Skip to content

Commit 870b34d

Browse files
skjnldsvbackportbot[bot]
authored andcommitted
feat: allow to provide manual URL
Signed-off-by: skjnldsv <skjnldsv@protonmail.com> [skip ci]
1 parent 28e95dd commit 870b34d

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

index.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ private function getUpdateServerResponse(): array {
555555
*
556556
* @throws \Exception
557557
*/
558-
public function downloadUpdate(): void {
558+
public function downloadUpdate(?string $url = null): void {
559559
$this->silentLog('[info] downloadUpdate()');
560560

561561
$response = $this->getUpdateServerResponse();
@@ -652,14 +652,19 @@ private function getDownloadedFilePath(): string {
652652
*
653653
* @throws \Exception
654654
*/
655-
public function verifyIntegrity(): void {
655+
public function verifyIntegrity(?string $urlOverride = null): void {
656656
$this->silentLog('[info] verifyIntegrity()');
657657

658658
if ($this->getCurrentReleaseChannel() === 'daily') {
659659
$this->silentLog('[info] current channel is "daily" which is not signed. Skipping verification.');
660660
return;
661661
}
662662

663+
if ($urlOverride) {
664+
$this->silentLog('[info] custom download url provided, cannot verify signature');
665+
return;
666+
}
667+
663668
$response = $this->getUpdateServerResponse();
664669
if (empty($response['signature'])) {
665670
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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ private function getUpdateServerResponse(): array {
517517
*
518518
* @throws \Exception
519519
*/
520-
public function downloadUpdate(): void {
520+
public function downloadUpdate(?string $url = null): void {
521521
$this->silentLog('[info] downloadUpdate()');
522522

523523
$response = $this->getUpdateServerResponse();
@@ -614,14 +614,19 @@ private function getDownloadedFilePath(): string {
614614
*
615615
* @throws \Exception
616616
*/
617-
public function verifyIntegrity(): void {
617+
public function verifyIntegrity(?string $urlOverride = null): void {
618618
$this->silentLog('[info] verifyIntegrity()');
619619

620620
if ($this->getCurrentReleaseChannel() === 'daily') {
621621
$this->silentLog('[info] current channel is "daily" which is not signed. Skipping verification.');
622622
return;
623623
}
624624

625+
if ($urlOverride) {
626+
$this->silentLog('[info] custom download url provided, cannot verify signature');
627+
return;
628+
}
629+
625630
$response = $this->getUpdateServerResponse();
626631
if (empty($response['signature'])) {
627632
throw new \Exception('No signature specified for defined update');

vendor/composer/platform_check.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
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;
2020
}
2121
}
22-
trigger_error(
23-
'Composer detected issues in your platform: ' . implode(' ', $issues),
24-
E_USER_ERROR
22+
throw new \RuntimeException(
23+
'Composer detected issues in your platform: ' . implode(' ', $issues)
2524
);
2625
}

0 commit comments

Comments
 (0)