From dde43d6184985f7e2b5613606e6002182c7eb75d Mon Sep 17 00:00:00 2001 From: An Phan Date: Fri, 15 Jan 2016 10:16:58 +0800 Subject: [PATCH] A more intuitive init command --- .env.example | 19 +++++--- app/Console/Commands/GenerateJWTSecret.php | 40 +++++++++++++++++ app/Console/Commands/Init.php | 50 ++++++++++++++++++---- app/Console/Kernel.php | 1 + config/jwt.php | 2 +- 5 files changed, 96 insertions(+), 16 deletions(-) create mode 100644 app/Console/Commands/GenerateJWTSecret.php diff --git a/.env.example b/.env.example index a9194e28..dbce1aa0 100644 --- a/.env.example +++ b/.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 diff --git a/app/Console/Commands/GenerateJWTSecret.php b/app/Console/Commands/GenerateJWTSecret.php new file mode 100644 index 00000000..42229c1d --- /dev/null +++ b/app/Console/Commands/GenerateJWTSecret.php @@ -0,0 +1,40 @@ +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.'); - Artisan::call('key:generate'); + 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"); - $this->info('php artisan migrate --force'); + if (!env('APP_KEY')) { + $this->info('Generating app key'); + Artisan::call('key:generate'); + } else { + $this->comment('App key exists -- skipping'); + } + 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'); + } - Artisan::call('db:seed', ['--force' => true]); + $this->info('Executing npm install, bower install, gulp and whatnot'); + system('npm install'); - $this->comment("\nProject initialized."); + $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.'); } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 30c10670..fefb7d57 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -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, ]; /** diff --git a/config/jwt.php b/config/jwt.php index 4001ee84..25cca202 100644 --- a/config/jwt.php +++ b/config/jwt.php @@ -12,7 +12,7 @@ return [ | */ - 'secret' => env('JWT_SECRET', 'YTAOH41t3QYSCVYuJfGKzSSJ6l1sBtvG'), + 'secret' => env('JWT_SECRET'), /* |--------------------------------------------------------------------------