<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use LaravelZero\Framework\Commands\Command;
|
|
|
|
use App\Facades\Install;
|
|
|
|
/**
|
|
* Install Nodejs
|
|
*
|
|
* @author Björn Hase, Tentakelfabrik
|
|
* @license http://opensource.org/licenses/MIT The MIT License
|
|
* @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
|
|
*
|
|
*/
|
|
class NodejsInstallCommand extends Command
|
|
{
|
|
/**
|
|
* The signature of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'nodejs:install {version}';
|
|
|
|
/**
|
|
* The description of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Install Nodejs';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
// getting configuration
|
|
$version = $this->argument('version');
|
|
|
|
$this->info('Nodejs installing...');
|
|
|
|
system('curl -sL https://deb.nodesource.com/setup_'.$version.'.x | sudo -E bash -');
|
|
|
|
// @TODO apt add a Warning for no good, in a later version output will be scanned for helpfull infos
|
|
exec('apt-get install -y nodejs 2>&1', $output);
|
|
$this->line(implode("\n", Install::filterAptMessages($output)));
|
|
|
|
$this->info('Nodejs add user...');
|
|
system('useradd -d /home/nodejs -m nodejs');
|
|
|
|
system('sudo -Hu nodejs mkdir /home/nodejs/.npm');
|
|
system('sudo -Hu nodejs npm config set prefix /home/nodejs/.npm');
|
|
system('echo -e "export PATH=/home/nodejs/.npm/bin:\$PATH" >> /home/nodejs/.bashrc');
|
|
|
|
$this->info('Nodejs install npm & pm2...');
|
|
system('npm install -g npm && npm install -g pm2');
|
|
|
|
// check if nginx is ready and installed
|
|
if (Install::isReady('nodejs')) {
|
|
$this->info('Nginx installing...Success! \o/');
|
|
} else {
|
|
$this->error('Failed! Please check log-file!');
|
|
}
|
|
}
|
|
}
|