Skip to content

Commit db5c9b3

Browse files
committed
Allow specification of a version
1 parent fb98b18 commit db5c9b3

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

app/Console/Commands/UpgradeCommand.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010

1111
class UpgradeCommand extends Command
1212
{
13-
protected const DEFAULT_URL = 'https://github.com/pterodactyl/panel/releases/latest/download/panel.tar.gz';
13+
protected const DEFAULT_URL = 'https://github.com/pterodactyl/panel/releases/%s/panel.tar.gz';
1414

1515
/** @var string */
16-
protected $signature = 'p:upgrade {--url=} {--skip-download}';
16+
protected $signature = 'p:upgrade
17+
{--url= : The specific archive to download.}
18+
{--release= : A specific Pterodactyl version to download from GitHub. Leave blank to use latest.}
19+
{--skip-download : If set no archive will be downloaded.}';
1720

1821
/** @var string */
1922
protected $description = 'Downloads a new archive for Pterodactyl from GitHub and then executes the normal upgrade commands.';
@@ -35,7 +38,7 @@ public function handle()
3538
if (!$skipDownload) {
3639
$this->output->warning('This command does not verify the integrity of downloaded assets. Please ensure that you trust the download source before continuing. If you do not wish to download an archive, please indicate that using the --skip-download flag, or answering "no" to the question below.');
3740
$this->output->comment('Download Source (set with --url=):');
38-
$this->line($this->option('url') ?? self::DEFAULT_URL);
41+
$this->line($this->getUrl());
3942
}
4043

4144
if ($this->input->isInteractive()) {
@@ -54,9 +57,8 @@ public function handle()
5457

5558
if (!$skipDownload) {
5659
$this->withProgress($bar, function () {
57-
$url = $this->option('url') ?? self::DEFAULT_URL;
58-
$this->line("\$upgrader> curl -L \"$url\" | tar -xzv");
59-
$process = Process::fromShellCommandline("curl -L \"$url\" | tar -xzvf");
60+
$this->line("\$upgrader> curl -L \"{$this->getUrl()}\" | tar -xzv");
61+
$process = Process::fromShellCommandline("curl -L \"{$this->getUrl()}\" | tar -xzvf");
6062
$process->run(function ($type, $buffer) {
6163
$this->{$type === Process::ERR ? 'error' : 'line'}($buffer);
6264
});
@@ -133,4 +135,13 @@ protected function withProgress(ProgressBar $bar, Closure $callback)
133135
$bar->advance();
134136
$bar->display();
135137
}
138+
139+
protected function getUrl(): string
140+
{
141+
if ($this->option('url')) {
142+
return $this->option('url');
143+
}
144+
145+
return sprintf(self::DEFAULT_URL, $this->option('release') ? 'download/v' . $this->option('release') : 'latest/download');
146+
}
136147
}

0 commit comments

Comments
 (0)