OpenSource CLI-App to install and handle stuff related to Web-Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.7 KiB

  1. <?php
  2. namespace App\Commands;
  3. use Illuminate\Console\Scheduling\Schedule;
  4. use LaravelZero\Framework\Commands\Command;
  5. use App\Facades\Install;
  6. /**
  7. *
  8. *
  9. *
  10. */
  11. class NodejsInstallCommand extends Command
  12. {
  13. /**
  14. * The signature of the command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'nodejs:install {version}';
  19. /**
  20. * The description of the command.
  21. *
  22. * @var string
  23. */
  24. protected $description = 'Install Nodejs';
  25. /**
  26. * Execute the console command.
  27. *
  28. * @return mixed
  29. */
  30. public function handle()
  31. {
  32. // getting configuration
  33. $version = $this->argument('version');
  34. $this->info('Nodejs installing...');
  35. exec('curl -sL https://deb.nodesource.com/setup_'.$version.'.x | sudo -E bash -');
  36. exec('apt-get install -y nodejs 2>&1');
  37. // @TODO apt add a Warning for no good, in a later version output will be scanned for helpfull infos
  38. $this->line(implode("\n", Install::filterAptMessages($output)));
  39. $this->info('Nodejs add user...');
  40. exec('useradd -d /home/nodejs -m nodejs', $output);
  41. exec('sudo -Hu nodejs mkdir /home/nodejs/.npm');
  42. exec('sudo -Hu nodejs npm config set prefix /home/nodejs/.npm');
  43. exec('echo -e "export PATH=/home/nodejs/.npm/bin:\$PATH" >> /home/nodejs/.bashrc');
  44. $this->info('Nodejs install npm & pm2...');
  45. exec('npm install -g npm && npm install -g pm2');
  46. // check if nginx is ready and installed
  47. if (Install::isReady('nodejs')) {
  48. $this->info('Nginx installing...Success! \o/');
  49. } else {
  50. $this->error('Failed! Please check log-file!');
  51. }
  52. }
  53. }