diff --git a/INSTALL/centos.sh b/INSTALL/centos.sh index e6b9879f..c762adb8 100644 --- a/INSTALL/centos.sh +++ b/INSTALL/centos.sh @@ -27,7 +27,7 @@ if [ ! -e "./super.json" ]; then fi echo "Shinobi - Run yum update" sudo yum update -y -sudo yum install make -y +sudo yum install make zip -y echo "=============" echo "Shinobi - Do you want to Install FFMPEG?" echo "(y)es or (N)o" diff --git a/INSTALL/shinobi b/INSTALL/shinobi index 30b94016..2e2cc788 100644 --- a/INSTALL/shinobi +++ b/INSTALL/shinobi @@ -1,12 +1,22 @@ #!/bin/bash -installationDirectory="/home/Shinobi" -if [ ! "$1" ]; then +if [ ! -e "/etc/shinobisystems/path.txt" ]; then + installationDirectory="/home/Shinobi" +else + installationDirectory=$(cat /etc/shinobisystems/cctv.txt) +fi +if [[ $@ == *'help'* ]] || [ ! "$1" ]; then echo "=========================================================" echo "==!! Shinobi : The Open Source CCTV and NVR Solution !!==" echo "=========================================================" - echo "You are missing function parameters." - echo "Example : shinobi [command] .." - echo "Example : shinobi flush restart logs" + if [ ! "$1" ]; then + echo "You are missing function parameters." + echo "Example : shinobi [command] .." + echo "Example : shinobi flush restart logs" + else + echo "Hello there! if you need support come on over" + echo "to the Shinobi Community Chat! :)" + echo "https://discordapp.com/invite/mdhmvuH/" + fi echo "=========================================================" echo "Your available options for COMMAND are as follows" echo "=========================================================" @@ -19,12 +29,21 @@ if [ ! "$1" ]; then echo "| stop, exit, or e :" echo "|--> Stop all processes running under the PM2 daemon." echo "-" + echo "| version :" + echo "|--> get version of your current build by git." + echo "-" echo "| logs :" echo "|--> Get PM2 log stream with last 100 lines." echo "-" echo "| clear, flush, or f :" echo "|--> Clear all PM2 logs." echo "-" + echo "| startupEnable :" + echo "|--> Start Shinobi on OS reboot." + echo "-" + echo "| startupDisable :" + echo "|--> Disable starting Shinobi on OS reboot." + echo "-" echo "| kill :" echo "|--> Stop the entire PM2 daemon." fi @@ -34,7 +53,8 @@ fi if [[ $@ == *'restart'* ]]; then proccessAlive=$(pm2 list | grep camera) if [ "$proccessAlive" ]; then - pm2 restart all + pm2 restart $installationDirectory/camera.js + pm2 restart $installationDirectory/cron.js else echo "Shinobi process is not running." fi @@ -58,11 +78,23 @@ fi if [[ $@ == *'stop'* ]] || [[ $@ == *'exit'* ]]; then proccessAlive=$(pm2 list | grep camera) if [ "$proccessAlive" ]; then - pm2 kill + pm2 stop $installationDirectory/camera.js + pm2 stop $installationDirectory/cron.js else echo "Shinobi process is not running." fi fi +if [[ $@ == *'version'* ]]; then + git show --oneline -s +fi +if [[ $@ == *'startupEnable'* ]] || [[ $@ == *'startupenable'* ]]; then + pm2 startup + pm2 save +fi +if [[ $@ == *'startupDisable'* ]] || [[ $@ == *'startupdisable'* ]]; then + pm2 unstartup + pm2 save +fi if [[ $@ == *'kill'* ]]; then pm2 kill fi diff --git a/INSTALL/terminalCommands.js b/INSTALL/terminalCommands.js new file mode 100644 index 00000000..bc6e4e7a --- /dev/null +++ b/INSTALL/terminalCommands.js @@ -0,0 +1,41 @@ +var fs = require('fs'); +var moment = require('moment'); +var exec = require('child_process').exec; +var execSync = require('child_process').execSync; +s = { + isWin: (process.platform === 'win32' || process.platform === 'win64'), + mainDirectory: __dirname.split('/INSTALL')[0] +} +var createTerminalCommands = function(callback){ + var next = function(){ + if(callback)callback() + } + if(!s.isWin){ + var etcPath = '/etc/shinobisystems/' + console.log('Creating "' + etcPath + '"...') + var createPathFile = function(){ + var pathTxt = etcPath + 'cctv.txt' + console.log('Creating "' + pathTxt + '"...') + fs.writeFile(pathTxt,s.mainDirectory,function(err){ + if(err)console.log(err) + fs.chmod(pathTxt,0o777,function(err){ + if(err)console.log(err) + console.log('Linking "' + s.mainDirectory + '/INSTALL/shinobi" to "/usr/bin/shinobi"...') + fs.symlink(s.mainDirectory + '/INSTALL/shinobi', '/usr/bin/shinobi', next) + console.log('You can now use `shinobi` in terminal.') + }) + }) + } + fs.stat(etcPath,function(err,stat){ + if(!err && stat){ + createPathFile() + }else{ + fs.mkdir(etcPath,createPathFile) + } + }) + }else{ + //no commands for windows yet + next() + } +} +createTerminalCommands() diff --git a/INSTALL/ubuntu.sh b/INSTALL/ubuntu.sh index 286b0432..87bd23f7 100644 --- a/INSTALL/ubuntu.sh +++ b/INSTALL/ubuntu.sh @@ -49,7 +49,7 @@ fi if ! [ -x "$(command -v npm)" ]; then sudo apt install npm -y fi -sudo apt install make -y +sudo apt install make zip -y if ! [ -x "$(command -v ffmpeg)" ]; then if [ "$getubuntuversion" = "16" ] || [ "$getubuntuversion" < "16" ]; then echo "=============" diff --git a/libs/startup.js b/libs/startup.js index 459a4795..4d664330 100644 --- a/libs/startup.js +++ b/libs/startup.js @@ -14,6 +14,24 @@ module.exports = function(s,config,lang,io,){ }) process.send('ready') } + var checkForTerminalCommands = function(callback){ + var next = function(){ + if(callback)callback() + } + if(!s.isWin){ + var etcPath = '/etc/shinobisystems/cctv.txt' + fs.stat(etcPath,function(err,stat){ + if(err || !stat){ + exec('node '+ s.mainDirectory + '/INSTALL/terminalCommands.js',function(err){ + console.log(err) + }) + } + next() + }) + }else{ + next() + } + } var loadedAccounts = [] var loadMonitors = function(callback){ s.systemLog(lang.startUpText4) @@ -157,11 +175,13 @@ module.exports = function(s,config,lang,io,){ //run prerequsite queries s.preQueries() setTimeout(function(){ - //load administrators (groups) - loadAdminUsers(function(){ - //load monitors (for groups) - loadMonitors(function(){ - s.processReady() + checkForTerminalCommands(function(){ + //load administrators (groups) + loadAdminUsers(function(){ + //load monitors (for groups) + loadMonitors(function(){ + s.processReady() + }) }) }) },1500)