mirror of
https://github.com/koel/koel
synced 2024-11-24 13:13:05 +00:00
A more intuitive init command
This commit is contained in:
parent
946f335cc2
commit
dde43d6184
5 changed files with 96 additions and 16 deletions
19
.env.example
19
.env.example
|
@ -1,7 +1,17 @@
|
|||
APP_ENV=production
|
||||
APP_DEBUG=true
|
||||
APP_KEY=SomeRandomString
|
||||
JWT_SECRET=SomeRandom32CharString
|
||||
|
||||
DB_CONNECTION=
|
||||
DB_HOST=
|
||||
DB_DATABASE=
|
||||
DB_USERNAME=
|
||||
DB_PASSWORD=
|
||||
|
||||
# A random 32-char string
|
||||
APP_KEY=
|
||||
|
||||
# Another random 32-char string
|
||||
JWT_SECRET=
|
||||
|
||||
# Username and password for the initial admin account
|
||||
# This info will be populated into the database during `php artisan db:seed`
|
||||
|
@ -22,11 +32,6 @@ STREAMING_METHOD=php
|
|||
LASTFM_API_KEY=
|
||||
LASTFM_API_SECRET=
|
||||
|
||||
DB_HOST=localhost
|
||||
DB_DATABASE=homestead
|
||||
DB_USERNAME=homestead
|
||||
DB_PASSWORD=secret
|
||||
|
||||
CACHE_DRIVER=file
|
||||
SESSION_DRIVER=file
|
||||
QUEUE_DRIVER=sync
|
||||
|
|
40
app/Console/Commands/GenerateJWTSecret.php
Normal file
40
app/Console/Commands/GenerateJWTSecret.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class GenerateJWTSecret extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'koel:generate-jwt-secret';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Set the JWTAuth secret key used to sign the tokens';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$key = Str::random(32);
|
||||
|
||||
$path = base_path('.env');
|
||||
$content = file_get_contents($path);
|
||||
|
||||
if (strpos($content, 'JWT_SECRET=') !== false) {
|
||||
file_put_contents($path, str_replace('JWT_SECRET=', "JWT_SECRET=$key", $content));
|
||||
} else {
|
||||
file_put_contents($path, $content.PHP_EOL."JWT_SECRET=$key");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use DB;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
|
@ -12,14 +14,14 @@ class Init extends Command
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'init';
|
||||
protected $signature = 'koel:init';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Initialize a new koel project.';
|
||||
protected $description = 'Install or upgrade Koel';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
|
@ -28,18 +30,50 @@ class Init extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('php artisan key:generate');
|
||||
try {
|
||||
DB::connection();
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Unable to connect to database.');
|
||||
$this->error('Please fill valid database credentials into .env and rerun this command.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->comment('Attempting to install or upgrade Koel.');
|
||||
$this->comment('Remember, you can always install/upgrade manually following the guide here:');
|
||||
$this->info("📙 https://github.com/phanan/koel/wiki\n");
|
||||
|
||||
if (!env('APP_KEY')) {
|
||||
$this->info('Generating app key');
|
||||
Artisan::call('key:generate');
|
||||
} else {
|
||||
$this->comment('App key exists -- skipping');
|
||||
}
|
||||
|
||||
$this->info('php artisan migrate --force');
|
||||
if (!env('JWT_SECRET')) {
|
||||
$this->info('Generating JWT secret');
|
||||
Artisan::call('koel:generate-jwt-secret');
|
||||
} else {
|
||||
$this->comment('JWT secret exists -- skipping');
|
||||
}
|
||||
|
||||
$this->info('Migrating database');
|
||||
Artisan::call('migrate', ['--force' => true]);
|
||||
|
||||
$this->info('php artisan db:seed --force');
|
||||
|
||||
if (!User::count()) {
|
||||
$this->info('Seeding initial data');
|
||||
Artisan::call('db:seed', ['--force' => true]);
|
||||
} else {
|
||||
$this->comment('Data seeded -- skipping');
|
||||
}
|
||||
|
||||
$this->comment("\nProject initialized.");
|
||||
$this->info('Executing npm install, bower install, gulp and whatnot');
|
||||
system('npm install');
|
||||
|
||||
$this->comment("\n🎆 Success! You can now run Koel from localhost with `php artisan serve`.");
|
||||
$this->comment('Again, for more configuration guidance, refer to');
|
||||
$this->info('📙 https://github.com/phanan/koel/wiki.');
|
||||
$this->comment('WIKI ROCKS WIKI RULES.');
|
||||
$this->comment('KTHXBYE.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ class Kernel extends ConsoleKernel
|
|||
protected $commands = [
|
||||
\App\Console\Commands\SyncMedia::class,
|
||||
\App\Console\Commands\Init::class,
|
||||
\App\Console\Commands\GenerateJWTSecret::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,7 +12,7 @@ return [
|
|||
|
|
||||
*/
|
||||
|
||||
'secret' => env('JWT_SECRET', 'YTAOH41t3QYSCVYuJfGKzSSJ6l1sBtvG'),
|
||||
'secret' => env('JWT_SECRET'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue