Skip to content

Commit f65e41a

Browse files
committed
flags for setup scripts, closes pterodactyl#134
1 parent 90240bf commit f65e41a

File tree

4 files changed

+66
-34
lines changed

4 files changed

+66
-34
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
88
### Added
99
* Return node configuration from remote API by using `/api/nodes/{id}/config` endpoint. Only accepts SSL connections.
1010
* Support for filtering servers within Admin CP to narrow down results by name, email, allocation, or defined fields.
11+
* Setup scripts (user, mail, env) now support argument flags for use in containers and other non-terminal environments.
1112

1213
### Changed
1314
* Creating a user, server, or node now returns `HTTP/1.1 200` and a JSON element with the user/server/node's ID.
15+
* Environment setting script is much more user friendly and does not require an excessive amount of clicking and typing.
1416

1517
## v0.5.0-pre.2 (Bodacious Boreopterus)
1618

app/Console/Commands/MakeUser.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ class MakeUser extends Command
3535
*
3636
* @var string
3737
*/
38-
protected $signature = 'pterodactyl:user';
38+
protected $signature = 'pterodactyl:user
39+
{--email= : Email address to use for this account.}
40+
{--password= : Password to assign to the user.}
41+
{--admin= : Boolean flag for if user should be an admin.}';
3942

4043
/**
4144
* The console command description.
@@ -61,15 +64,15 @@ public function __construct()
6164
*/
6265
public function handle()
6366
{
64-
$email = $this->ask('Email');
65-
$password = $this->secret('Password');
66-
$password_confirmation = $this->secret('Confirm Password');
67+
$email = is_null($this->option('email')) ? $this->ask('Email') : $this->option('email');
68+
$password = is_null($this->option('password')) ? $this->secret('Password') : $this->option('password');
69+
$password_confirmation = is_null($this->option('password')) ? $this->secret('Confirm Password') : $this->option('password');
6770

6871
if ($password !== $password_confirmation) {
6972
return $this->error('The passwords provided did not match!');
7073
}
7174

72-
$admin = $this->confirm('Is this user a root administrator?');
75+
$admin = is_null($this->option('admin')) ? $this->confirm('Is this user a root administrator?') : $this->option('admin');
7376

7477
try {
7578
$user = new UserRepository;

app/Console/Commands/UpdateEmailSettings.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ class UpdateEmailSettings extends Command
3232
*
3333
* @var string
3434
*/
35-
protected $signature = 'pterodactyl:mail';
35+
protected $signature = 'pterodactyl:mail
36+
{--driver=}
37+
{--email=}
38+
{--host=}
39+
{--port=}
40+
{--username=}
41+
{--password=}';
3642

3743
/**
3844
* The console command description.
@@ -92,35 +98,35 @@ public function handle()
9298
'Postmark Transactional Email Service'
9399
]
94100
]);
95-
$variables['MAIL_DRIVER'] = $this->choice('Which email driver would you like to use?', [
101+
$variables['MAIL_DRIVER'] = is_null($this->option('driver')) ? $this->choice('Which email driver would you like to use?', [
96102
'smtp',
97103
'mail',
98104
'mailgun',
99105
'mandrill',
100106
'postmark'
101-
]);
107+
]) : $this->option('driver');
102108

103109
switch ($variables['MAIL_DRIVER']) {
104110
case 'smtp':
105-
$variables['MAIL_HOST'] = $this->ask('SMTP Host (e.g smtp.google.com)');
106-
$variables['MAIL_PORT'] = $this->anticipate('SMTP Host Port (e.g 587)', ['587']);
107-
$variables['MAIL_USERNAME'] = $this->ask('SMTP Username');
108-
$variables['MAIL_PASSWORD'] = $this->secret('SMTP Password');
111+
$variables['MAIL_HOST'] = is_null($this->option('host')) ? $this->ask('SMTP Host (e.g smtp.google.com)') : $this->option('host');
112+
$variables['MAIL_PORT'] = is_null($this->option('port')) ? $this->anticipate('SMTP Host Port (e.g 587)', ['587']) : $this->option('port');
113+
$variables['MAIL_USERNAME'] = is_null($this->option('username')) ? $this->ask('SMTP Username') : $this->option('password');
114+
$variables['MAIL_PASSWORD'] = is_null($this->option('password')) ? $this->secret('SMTP Password') : $this->option('password');
109115
break;
110116
case 'mail':
111117
break;
112118
case 'mailgun':
113-
$variables['MAILGUN_DOMAIN'] = $this->ask('Mailgun Domain');
114-
$variables['MAILGUN_KEY'] = $this->ask('Mailgun Key');
119+
$variables['MAILGUN_DOMAIN'] = is_null($this->option('host')) ? $this->ask('Mailgun Domain') : $this->option('host');
120+
$variables['MAILGUN_KEY'] = is_null($this->option('username')) ? $this->ask('Mailgun Key') : $this->option('username');
115121
break;
116122
case 'mandrill':
117-
$variables['MANDRILL_SECRET'] = $this->ask('Mandrill Secret');
123+
$variables['MANDRILL_SECRET'] = is_null($this->option('username')) ? $this->ask('Mandrill Secret') : $this->option('username');
118124
break;
119125
case 'postmark':
120126
$variables['MAIL_DRIVER'] = 'smtp';
121127
$variables['MAIL_HOST'] = 'smtp.postmarkapp.com';
122128
$variables['MAIL_PORT'] = 587;
123-
$variables['MAIL_USERNAME'] = $this->ask('Postmark API Token');
129+
$variables['MAIL_USERNAME'] = is_null($this->option('username')) ? $this->ask('Postmark API Token') : $this->option('username');
124130
$variables['MAIL_PASSWORD'] = $variables['MAIL_USERNAME'];
125131
break;
126132
default:
@@ -129,7 +135,7 @@ public function handle()
129135
break;
130136
}
131137

132-
$variables['MAIL_FROM'] = $this->ask('Email address emails should originate from');
138+
$variables['MAIL_FROM'] = is_null($this->option('email')) ? $this->ask('Email address emails should originate from') : $this->option('email');
133139
$variables['MAIL_ENCRYPTION'] = 'tls';
134140

135141
$bar = $this->output->createProgressBar(count($variables));

app/Console/Commands/UpdateEnvironment.php

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ class UpdateEnvironment extends Command
3333
*
3434
* @var string
3535
*/
36-
protected $signature = 'pterodactyl:env';
36+
protected $signature = 'pterodactyl:env
37+
{--dbhost=}
38+
{--dbport=}
39+
{--dbname=}
40+
{--dbuser=}
41+
{--dbpass=}
42+
{--url=}
43+
{--timezone=}';
3744

3845
/**
3946
* The console command description.
@@ -69,40 +76,54 @@ public function handle()
6976

7077
$envContents = file_get_contents($file);
7178

79+
$this->info('Simply leave blank and press enter to fields that you do not wish to update.');
7280
if (!env('SERVICE_AUTHOR', false)) {
7381
$this->info('No service author set, setting one now.');
7482
$variables['SERVICE_AUTHOR'] = env('SERVICE_AUTHOR', (string) Uuid::generate(4));
7583
}
7684

77-
// DB info
78-
if($this->confirm('Update database host? [' . env('DB_HOST') . ']')) {
79-
$variables['DB_HOST'] = $this->anticipate('Database Host (usually \'localhost\' or \'127.0.0.1\')', [ 'localhost', '127.0.0.1', env('DB_HOST') ]);
85+
if (is_null($this->option('dbhost'))) {
86+
$variables['DB_HOST'] = $this->anticipate('Database Host', [ 'localhost', '127.0.0.1', env('DB_HOST') ], env('DB_HOST'));
87+
} else {
88+
$variables['DB_HOST'] = $this->option('dbhost');
8089
}
8190

82-
if($this->confirm('Update database port? [' . env('DB_PORT') . ']')) {
83-
$variables['DB_PORT'] = $this->anticipate('Database Port', [ 3306, env('DB_PORT') ]);
91+
if (is_null($this->option('dbport'))) {
92+
$variables['DB_PORT'] = $this->anticipate('Database Port', [ 3306, env('DB_PORT') ], env('DB_PORT'));
93+
} else {
94+
$variables['DB_PORT'] = $this->option('dbport');
8495
}
8596

86-
if($this->confirm('Update database name? [' . env('DB_DATABASE') . ']')) {
87-
$variables['DB_DATABASE'] = $this->anticipate('Database Name', [ 'pterodactyl', 'homestead', ENV('DB_DATABASE') ]);
97+
if (is_null($this->option('dbname'))) {
98+
$variables['DB_DATABASE'] = $this->anticipate('Database Name', [ 'pterodactyl', 'homestead', ENV('DB_DATABASE') ], env('DB_DATABASE'));
99+
} else {
100+
$variables['DB_DATABASE'] = $this->option('dbname');
88101
}
89102

90-
if($this->confirm('Update database username? [' . env('DB_USERNAME') . ']')) {
91-
$variables['DB_USERNAME'] = $this->anticipate('Database Username', [ env('DB_USERNAME') ]);
103+
if (is_null($this->option('dbuser'))) {
104+
$variables['DB_USERNAME'] = $this->anticipate('Database Username', [ ENV('DB_DATABASE') ], env('DB_USERNAME'));
105+
} else {
106+
$variables['DB_USERNAME'] = $this->option('dbuser');
92107
}
93108

94-
if($this->confirm('Update database password?')) {
95-
$variables['DB_PASSWORD'] = $this->secret('Database User\'s Password');
109+
if (is_null($this->option('dbpass'))) {
110+
$this->line('The Database Password field is required; you cannot hit enter and use a default value.');
111+
$variables['DB_PASSWORD'] = $this->secret('Database User Password');
112+
} else {
113+
$variables['DB_PASSWORD'] = $this->option('dbpass');
96114
}
97115

98-
// Other Basic Information
99-
if($this->confirm('Update panel URL? [' . env('APP_URL') . ']')) {
100-
$variables['APP_URL'] = $this->anticipate('Enter your current panel URL (include http or https).', [ env('APP_URL', 'http://localhost') ]);
116+
if (is_null($this->option('url'))) {
117+
$variables['APP_URL'] = $this->ask('Panel URL', env('APP_URL'));
118+
} else {
119+
$variables['APP_URL'] = $this->option('url');
101120
}
102121

103-
if($this->confirm('Update panel timezone? [' . env('APP_TIMEZONE') . ']')) {
122+
if (is_null($this->option('timezone'))) {
104123
$this->line('The timezone should match one of the supported timezones according to http://php.net/manual/en/timezones.php');
105-
$variables['APP_TIMEZONE'] = $this->anticipate('Enter the timezone for this panel to run with', \DateTimeZone::listIdentifiers(\DateTimeZone::ALL));
124+
$variables['APP_TIMEZONE'] = $this->anticipate('Panel Timezone', \DateTimeZone::listIdentifiers(\DateTimeZone::ALL), env('APP_TIMEZONE'));
125+
} else {
126+
$variables['APP_TIMEZONE'] = $this->option('timezone');
106127
}
107128

108129
$bar = $this->output->createProgressBar(count($variables));

0 commit comments

Comments
 (0)