Update Installers and Terminal Commander

- add zip to ubuntu and centos installers.
- add script to create terminal commander on shinobi start or manually by terminal
- update terminal commander to use dynamic value for shinobi path
merge-requests/49/head
Moe 2019-01-13 13:42:11 -08:00
parent 84a1311b2e
commit a3646a6209
5 changed files with 107 additions and 14 deletions

View File

@ -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"

View File

@ -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

View File

@ -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()

View File

@ -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 "============="

View File

@ -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)