Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/';
Expand Down Expand Up @@ -743,14 +750,19 @@ 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') {
$this->silentLog('[info] current channel is "daily" which is not signed. Skipping verification.');
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');
Expand Down
24 changes: 17 additions & 7 deletions lib/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> strings of text for stages of updater */
protected array $checkTexts = [
Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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('');

Expand All @@ -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';
Expand Down Expand Up @@ -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();
Expand Down
18 changes: 15 additions & 3 deletions lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/';
Expand Down Expand Up @@ -705,14 +712,19 @@ 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') {
$this->silentLog('[info] current channel is "daily" which is not signed. Skipping verification.');
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');
Expand Down
Binary file modified updater.phar
Binary file not shown.
4 changes: 2 additions & 2 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => '__root__',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'bbd6e8e521f3fd1d02d34e3c9eda83c4c8d4c460',
'reference' => 'd57261832b96a413d7ae92aa66ac15054ae8f4d5',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'__root__' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'bbd6e8e521f3fd1d02d34e3c9eda83c4c8d4c460',
'reference' => 'd57261832b96a413d7ae92aa66ac15054ae8f4d5',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down