From 4dbf86a3283d7df0d181054d7dda1e283596ccd1 Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Thu, 9 Jul 2020 04:52:53 +0100 Subject: [PATCH] Add installation command Adds an installation and .env modification commands for better usability --- app/Console/Commands/Install.php | 137 +++++++++++++++++++++++++++++++ app/Console/Commands/SetEnv.php | 53 ++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 app/Console/Commands/Install.php create mode 100644 app/Console/Commands/SetEnv.php diff --git a/app/Console/Commands/Install.php b/app/Console/Commands/Install.php new file mode 100644 index 0000000..0fc9d41 --- /dev/null +++ b/app/Console/Commands/Install.php @@ -0,0 +1,137 @@ +missing('INSTALLED')) + { + + + $this->info('[!! Welcome to Rasberry Teams !!]'); + $this->info('>> Installing...'); + + copy($basePath . '/.env.example', $basePath . '/.env'); + Artisan::call('key:generate'); + + + // Command stack + $composer = new Process('composer install', $basePath); + $npm = new Process('npm install', $basePath); + $npmBuild = new Process('npm run dev', $basePath); + + + $this->info('>> Installing and preparing dependencies...'); + + try + { + $composer->mustRun(); + $npm->mustRun(); + $npmBuild->mustRun(); + } + catch(ProcessFailedException $pfe) + { + $this->error('[!] One or more errors have ocurred whilst attempting to install dependencies. This is the error message: ' . $pfe->getMessage()); + $this->error('[!] It is recommended to run this command again, and report a bug if it keeps happening.'); + + return false; + } + + $settings = []; + + $this->info('>> Configuring application - We\'re going to ask a few questions here!'); + $this->info('>> Questions with a value in brackets are optional and you may leave them empty to use it'); + + do + { + $this->info('== Database Settings (1/6) =='); + + $settings['DB_USERNAME'] = $this->ask('Database username [root]: ') ?? 'root'; + $settings['DB_PASSWORD'] = $this->secret('Database password (Input won\'t be seen): '); + $settings['DB_DATABASE'] = $this->ask('Database name: '); + $settings['DB_PORT'] = $this->ask('Database port [3306]: ') ?? 3306; + $settings['DB_HOST'] = $this->ask('Database hostname [localhost]: ') ?? 'localhost'; + + $this->info('== Antispam Settings (2/6) (Recaptcha v2) =='); + $settings['RECAPTCHA_SITE_KEY'] = $this->ask('Site key: '); + $settings['RECAPTCHA_PRIVATE_KEY'] = $this->ask('Private site key: '); + + $this->info('== IP Geolocation Settings (3/6) (refer to README.md) =='); + $settings['APIGEO_API_KEY'] = $this->ask('API Key: '); + + $this->info('== Notification Settings (4/6) (Email) =='); + $settings['MAIL_USERNAME'] = $this->ask('SMTP Username: '); + $settings['MAIL_PASSWORD'] = $this->secret('SMTP Password (Input won\'t be seen): '); + $settings['MAIL_PORT'] = $this->ask('SMTP Server Port [25]: ') ?? 25; + $settings['MAIL_HOST'] = $this->ask('SMTP Server Hostname: '); + + $this->info('== Notification Settings (5/6) (Slack) =='); + $settings['SLACK_INTEGRATION_WEBHOOK'] = $this->ask('Integration webhook URL: '); + + $this->info('== Web Settings (6/6) =='); + $settings['APP_URL'] = $this->ask('Application\'s URL [http://localhost]: ') ?? 'http://localhost'; + + } while(!$this->confirm('Are you sure you want to save these settings? You can always go back and try again.')); + + foreach($settings as $keyname => $value) + { + $this->callSilent('environment:modify', [ + 'key' => $keyname, + 'value' => $value + ]); + } + + $this->info('>> Saved configuration settings!'); + $this->info('>> Preparing database...'); + + $this->call('migrate'); + $this->call('db:seed'); + $this->call('config:cache'); + + touch($basePath . '/INSTALLED'); + $this->info('>> All done! Visit ' . $baseURL . ' to start using your brand new installation of Raspberry Teams!'); + + } + else + { + $this->error('[!] The application is already installed!'); + } + } +} diff --git a/app/Console/Commands/SetEnv.php b/app/Console/Commands/SetEnv.php new file mode 100644 index 0000000..aabb43a --- /dev/null +++ b/app/Console/Commands/SetEnv.php @@ -0,0 +1,53 @@ +argument('key'); + $value = $this->argument('value'); + + if (file_exists($path)) + { + file_put_contents($path, str_replace( + $name . '=' . env($name), $name . '=' . $value, file_get_contents($path) + )); + } + + $this->info('>> Changed value! It may now be accessed via env() or config() if there\'s a file for it.'); + } +}