Skip to content

Commit fb98b18

Browse files
committed
Add simple logic to download and unpack the archive
1 parent 6f3ea46 commit fb98b18

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

app/Console/Commands/UpgradeCommand.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +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';
14+
1315
/** @var string */
14-
protected $signature = 'p:upgrade {--force}';
16+
protected $signature = 'p:upgrade {--url=} {--skip-download}';
1517

1618
/** @var string */
17-
protected $description = 'Executes the commands necessary for getting Pterodactyl operational after installing new files.';
19+
protected $description = 'Downloads a new archive for Pterodactyl from GitHub and then executes the normal upgrade commands.';
1820

1921
/**
2022
* Executes an upgrade command which will run through all of our standard
@@ -28,16 +30,39 @@ class UpgradeCommand extends Command
2830
*/
2931
public function handle()
3032
{
33+
$skipDownload = $this->option('skip-download');
34+
35+
if (!$skipDownload) {
36+
$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.');
37+
$this->output->comment('Download Source (set with --url=):');
38+
$this->line($this->option('url') ?? self::DEFAULT_URL);
39+
}
40+
3141
if ($this->input->isInteractive()) {
42+
if (!$skipDownload) {
43+
$skipDownload = !$this->confirm('Would you like to download and unpack the archive files for the latest version?', true);
44+
}
45+
3246
if (!$this->confirm('Are you sure you want to run the upgrade process for your Panel?')) {
3347
return;
3448
}
3549
}
3650

3751
ini_set('output_buffering', 0);
38-
$bar = $this->output->createProgressBar(8);
52+
$bar = $this->output->createProgressBar($skipDownload ? 8 : 9);
3953
$bar->start();
4054

55+
if (!$skipDownload) {
56+
$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+
$process->run(function ($type, $buffer) {
61+
$this->{$type === Process::ERR ? 'error' : 'line'}($buffer);
62+
});
63+
});
64+
}
65+
4166
$this->withProgress($bar, function () {
4267
$this->line('$upgrader> php artisan down');
4368
$this->call('down');

0 commit comments

Comments
 (0)