Skip to content

Commit 8228dea

Browse files
committed
feat: allow to provide manual URL
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent b7afd33 commit 8228dea

File tree

5 files changed

+49
-15
lines changed

5 files changed

+49
-15
lines changed

index.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,17 @@ private function getUpdateServerResponse(): array {
554554
*
555555
* @throws \Exception
556556
*/
557-
public function downloadUpdate(): void {
557+
public function downloadUpdate(?string $url = null): void {
558558
$this->silentLog('[info] downloadUpdate()');
559559

560-
$downloadURLs = $this->getDownloadURLs();
560+
if ($url) {
561+
// If a URL is provided, use it directly
562+
$downloadURLs = [$url];
563+
} else {
564+
// Otherwise, get the download URLs from the update server
565+
$downloadURLs = $this->getDownloadURLs();
566+
}
567+
561568
$this->silentLog('[info] will try to download archive from: ' . implode(', ', $downloadURLs));
562569

563570
$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/downloads/';
@@ -751,14 +758,19 @@ private function getDownloadedFilePath(): string {
751758
*
752759
* @throws \Exception
753760
*/
754-
public function verifyIntegrity(): void {
761+
public function verifyIntegrity(?string $urlOverride = null): void {
755762
$this->silentLog('[info] verifyIntegrity()');
756763

757764
if ($this->getCurrentReleaseChannel() === 'daily') {
758765
$this->silentLog('[info] current channel is "daily" which is not signed. Skipping verification.');
759766
return;
760767
}
761768

769+
if ($urlOverride) {
770+
$this->silentLog('[info] custom download url provided, cannot verify signature');
771+
return;
772+
}
773+
762774
$response = $this->getUpdateServerResponse();
763775
if (empty($response['signature'])) {
764776
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 a 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';
@@ -394,10 +404,10 @@ protected function executeStep(int $step): array {
394404
}
395405
break;
396406
case 4:
397-
$this->updater->downloadUpdate();
407+
$this->updater->downloadUpdate($this->urlOverride);
398408
break;
399409
case 5:
400-
$this->updater->verifyIntegrity();
410+
$this->updater->verifyIntegrity($this->urlOverride);
401411
break;
402412
case 6:
403413
$this->updater->extractDownload();

lib/Updater.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,17 @@ private function getUpdateServerResponse(): array {
536536
*
537537
* @throws \Exception
538538
*/
539-
public function downloadUpdate(): void {
539+
public function downloadUpdate(?string $url = null): void {
540540
$this->silentLog('[info] downloadUpdate()');
541541

542-
$downloadURLs = $this->getDownloadURLs();
542+
if ($url) {
543+
// If a URL is provided, use it directly
544+
$downloadURLs = [$url];
545+
} else {
546+
// Otherwise, get the download URLs from the update server
547+
$downloadURLs = $this->getDownloadURLs();
548+
}
549+
543550
$this->silentLog('[info] will try to download archive from: ' . implode(', ', $downloadURLs));
544551

545552
$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/downloads/';
@@ -733,14 +740,19 @@ private function getDownloadedFilePath(): string {
733740
*
734741
* @throws \Exception
735742
*/
736-
public function verifyIntegrity(): void {
743+
public function verifyIntegrity(?string $urlOverride = null): void {
737744
$this->silentLog('[info] verifyIntegrity()');
738745

739746
if ($this->getCurrentReleaseChannel() === 'daily') {
740747
$this->silentLog('[info] current channel is "daily" which is not signed. Skipping verification.');
741748
return;
742749
}
743750

751+
if ($urlOverride) {
752+
$this->silentLog('[info] custom download url provided, cannot verify signature');
753+
return;
754+
}
755+
744756
$response = $this->getUpdateServerResponse();
745757
if (empty($response['signature'])) {
746758
throw new \Exception('No signature specified for defined update');

updater.phar

808 Bytes
Binary file not shown.

vendor/composer/installed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'name' => '__root__',
44
'pretty_version' => 'dev-master',
55
'version' => 'dev-master',
6-
'reference' => 'f5496edc4ab53b1f164b5df0056355272d3911ff',
6+
'reference' => '32b8a4525fb72023a82b5f99e69db0e7b0e87a60',
77
'type' => 'library',
88
'install_path' => __DIR__ . '/../../',
99
'aliases' => array(),
@@ -13,7 +13,7 @@
1313
'__root__' => array(
1414
'pretty_version' => 'dev-master',
1515
'version' => 'dev-master',
16-
'reference' => 'f5496edc4ab53b1f164b5df0056355272d3911ff',
16+
'reference' => '32b8a4525fb72023a82b5f99e69db0e7b0e87a60',
1717
'type' => 'library',
1818
'install_path' => __DIR__ . '/../../',
1919
'aliases' => array(),

0 commit comments

Comments
 (0)