From db5c9b3675911b99c37b6742592ced2df42a5ed7 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 23 Jan 2021 16:12:13 -0800 Subject: [PATCH] Allow specification of a version --- app/Console/Commands/UpgradeCommand.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/UpgradeCommand.php b/app/Console/Commands/UpgradeCommand.php index 6da06038c..97fa37339 100644 --- a/app/Console/Commands/UpgradeCommand.php +++ b/app/Console/Commands/UpgradeCommand.php @@ -10,10 +10,13 @@ use Symfony\Component\Console\Helper\ProgressBar; class UpgradeCommand extends Command { - protected const DEFAULT_URL = 'https://github.com/pterodactyl/panel/releases/latest/download/panel.tar.gz'; + protected const DEFAULT_URL = 'https://github.com/pterodactyl/panel/releases/%s/panel.tar.gz'; /** @var string */ - protected $signature = 'p:upgrade {--url=} {--skip-download}'; + protected $signature = 'p:upgrade + {--url= : The specific archive to download.} + {--release= : A specific Pterodactyl version to download from GitHub. Leave blank to use latest.} + {--skip-download : If set no archive will be downloaded.}'; /** @var string */ protected $description = 'Downloads a new archive for Pterodactyl from GitHub and then executes the normal upgrade commands.'; @@ -35,7 +38,7 @@ class UpgradeCommand extends Command if (!$skipDownload) { $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.'); $this->output->comment('Download Source (set with --url=):'); - $this->line($this->option('url') ?? self::DEFAULT_URL); + $this->line($this->getUrl()); } if ($this->input->isInteractive()) { @@ -54,9 +57,8 @@ class UpgradeCommand extends Command if (!$skipDownload) { $this->withProgress($bar, function () { - $url = $this->option('url') ?? self::DEFAULT_URL; - $this->line("\$upgrader> curl -L \"$url\" | tar -xzv"); - $process = Process::fromShellCommandline("curl -L \"$url\" | tar -xzvf"); + $this->line("\$upgrader> curl -L \"{$this->getUrl()}\" | tar -xzv"); + $process = Process::fromShellCommandline("curl -L \"{$this->getUrl()}\" | tar -xzvf"); $process->run(function ($type, $buffer) { $this->{$type === Process::ERR ? 'error' : 'line'}($buffer); }); @@ -133,4 +135,13 @@ class UpgradeCommand extends Command $bar->advance(); $bar->display(); } + + protected function getUrl(): string + { + if ($this->option('url')) { + return $this->option('url'); + } + + return sprintf(self::DEFAULT_URL, $this->option('release') ? 'download/v' . $this->option('release') : 'latest/download'); + } }