Shinobi/INSTALL/CentOS - Quick Install.sh

286 lines
8.9 KiB
Bash
Raw Normal View History

2019-08-14 14:28:59 +00:00
#!/bin/bash
2020-10-01 13:55:16 +00:00
#Identify version of CentOS
version=$(rpm --eval %{centos_ver})
#Set script to use dnf or yum
if [ "$version" = 7 ]; then
pkgmgr="yum"
elif [ "$version" = 8 ]; then
pkgmgr="dnf"
else
echo "This version of CentOS is unsupported!"
read -p "Continue at your own risk? Y/N" osoverride
2020-10-01 17:16:25 +00:00
#Changes input to uppercase
osoverride=${osoverride^}
2020-10-01 17:16:25 +00:00
if [ ! "$osoverride" = "Y" ]; then
exit 1
else
pkgmgr="yum"
fi
2020-10-01 13:55:16 +00:00
fi
#Check to see if we are running on a virtual machine
2020-10-01 13:55:16 +00:00
if hostnamectl | grep -oq "Chassis: vm"; then
vm="open-vm-tools"
else
vm=""
fi
#Clear screen
clear
2019-08-14 14:28:59 +00:00
echo "========================================================="
echo "== Shinobi : The Open Source CCTV and NVR Solution =="
echo "========================================================="
2020-10-01 13:55:16 +00:00
echo "This script will install Shinobi CCTV on CentOS $version with"
echo "minimal user intervention."
echo
echo "You may skip any components you already have or do not"
2019-08-14 14:28:59 +00:00
echo "wish to install."
echo "========================================================="
read -p "Press [Enter] to begin..."
2020-10-01 13:55:16 +00:00
#Install dependencies
2020-10-01 17:16:25 +00:00
echo "Installing dependencies and tools..."
2020-10-01 13:55:16 +00:00
if [ "$version" = 7 ]; then
2019-11-04 20:51:11 +00:00
#Installing deltarpm first will greatly increase the download speed of the other packages
2020-10-01 13:55:16 +00:00
sudo yum install deltarpm -y -q -e 0
fi
#Install remaining packages
sudo $pkgmgr install $vm nano dos2unix net-tools curl wget git gcc gcc-c++ make zip -y -q -e 0
2019-08-14 14:28:59 +00:00
2020-10-01 13:55:16 +00:00
#Install updates
2020-10-01 17:16:25 +00:00
echo "Updating system..."
2020-10-01 13:55:16 +00:00
sudo $pkgmgr update -y -q -e 0
2019-08-14 14:28:59 +00:00
#Skip if running from the Ninja installer
if [ "$1" != 1 ]; then
#Clone git repo and change directory
2020-10-01 13:55:16 +00:00
sudo git clone -q https://gitlab.com/Shinobi-Systems/Shinobi.git Shinobi
cd Shinobi
2019-08-14 14:28:59 +00:00
echo "========================================================="
echo "Do you want to use the Master or Development branch of Shinobi?"
read -p "[M]aster or [D]ev " gitbranch
2020-10-01 13:55:16 +00:00
#Changes input to uppercase
gitbranch=${gitbranch^}
2020-10-01 13:55:16 +00:00
if [ "$gitbranch" = "D" ]; then
#Change to dev branch
sudo git checkout dev
sudo git pull
fi
2019-08-14 14:28:59 +00:00
fi
if ! [ -x "$(command -v node)" ]; then
echo "========================================================="
echo "Node.js not found, installing..."
2020-10-01 13:55:16 +00:00
sudo curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -
sudo $pkgmgr install nodejs -y -q -e 0
2019-08-14 14:28:59 +00:00
else
echo "Node.js is already installed..."
echo "Version : $(node -v)"
fi
if ! [ -x "$(command -v npm)" ]; then
2020-10-01 13:55:16 +00:00
sudo $pkgmgr install npm -y -q -e 0
2019-08-14 14:28:59 +00:00
fi
echo "========================================================="
read -p "Do you want to install FFMPEG? Y/N " ffmpeginstall
#Changes input to uppercase
ffmpeginstall=${ffmpeginstall^}
if [ "$ffmpeginstall" = "Y" ]; then
2019-08-14 14:28:59 +00:00
#Install EPEL Repo
2020-10-01 13:55:16 +00:00
sudo $pkgmgr install epel-release -y -q -e 0
if [ "$version" = 7 ]; then
#Enable Nux Dextop repo for FFMPEG (CentOS 7)
sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
sudo yum install ffmpeg ffmpeg-devel -y -q -e 0
elif [ "$version" = 8 ]; then
#Enable Negativo17 repo for FFMPEG (CentOS 8)
sudo dnf install epel-release dnf-utils -y -q -e 0
sudo yum-config-manager --set-enabled PowerTools
sudo yum-config-manager --add-repo=https://negativo17.org/repos/epel-multimedia.repo
sudo dnf install ffmpeg ffmpeg-devel -y -q -e 0
fi
2019-08-14 14:28:59 +00:00
fi
echo "========================================================="
2020-10-01 13:55:16 +00:00
read -p "Do you want to install MariaDB? Y/N " installdbserver
#Changes input to uppercase
2020-10-01 17:16:25 +00:00
installdbserver=${installdbserver^}
2020-10-01 16:54:48 +00:00
if [ "installdbserver" = "Y" ] || [ "$installdbserver" = "" ]; then
2019-08-14 14:28:59 +00:00
echo "========================================================="
echo "Installing MariaDB repository..."
#Add the MariaDB repository to yum
sudo curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --skip-maxscale
echo "Installing MariaDB..."
2020-10-01 13:55:16 +00:00
sudo $pkgmgr install mariadb mariadb-server -y -q -e 0
2019-08-14 14:28:59 +00:00
#Start mysql and enable on boot
sudo systemctl start mariadb
sudo systemctl enable mariadb
#Run mysql install
sudo mysql_secure_installation
2020-10-01 13:55:16 +00:00
2019-08-14 14:28:59 +00:00
echo "========================================================="
read -p "Install default database? Y/N " mysqlDefaultData
2020-10-01 13:55:16 +00:00
#Changes input to uppercase
mysqlDefaultData=${mysqlDefaultData^}
if [ "$mysqlDefaultData" = "Y" ]; then
#Get the username we will use to insert the database
until [ "$mariadbUserConfirmation" = "Y" ]; do
echo "Please enter your MariaDB Username"
read sqluser
echo "Please confirm your MariaDB Username"
read sqluserconfirm
if [ -z "$sqluser" ] || [ -z "$sqluserconfirm" ]; then
echo "Username field left blank. Please enter a valid username."
elif [ "$sqluser" == "$sqluserconfirm" ]; then
mariadbUserConfirmation="Y"
else
echo "Username did not match."
echo "Please try again."
fi
done
#Get the password for the database user
until [ "$mariadbPasswordConfirmation" = "Y" ]; do
echo "Please enter your MariaDB Password"
read -s sqlpass
2020-10-01 13:55:16 +00:00
echo "Please confirm your MariaDB Password"
read -s sqlpassconfirm
2020-10-01 13:55:16 +00:00
if [ -z "$sqlpass" ] || [ -z "$sqlpassconfirm" ]; then
echo "Password field left blank. To continue without a password"
echo "please type \"confirm\", to enter a pasword press any key"
read nopassconfirmation
if [ "$nopassconfirmation" == "confirm" ]; then
break
fi
elif [ "$sqlpass" == "$sqlpassconfirm" ]; then
mariadbPasswordConfirmation="Y"
else
echo "Passwords did not match."
echo "Please try again."
2020-10-01 13:55:16 +00:00
fi
done
2020-10-01 13:55:16 +00:00
2019-08-14 14:28:59 +00:00
sudo mysql -u $sqluser -p$sqlpass -e "source sql/user.sql" || true
sudo mysql -u $sqluser -p$sqlpass -e "source sql/framework.sql" || true
fi
2020-10-01 13:55:16 +00:00
2019-10-15 18:39:36 +00:00
elif [ "$installdbserver" = "N" ]; then
2019-08-14 14:28:59 +00:00
echo "========================================================="
echo "Skipping database server installation..."
fi
2020-10-01 13:55:16 +00:00
2019-08-14 14:28:59 +00:00
echo "========================================================="
echo "Installing NPM libraries..."
sudo npm i npm -g
sudo npm install --unsafe-perm
2019-08-14 18:09:51 +00:00
sudo npm install ffbinaries mp4frag@latest cws@latest
2019-08-14 14:28:59 +00:00
sudo npm audit fix --force
echo "========================================================="
echo "Installing PM2..."
sudo npm install pm2@latest -g
sudo chmod -R 755 .
touch INSTALL/installed.txt
dos2unix INSTALL/shinobi
ln -s INSTALL/shinobi /usr/bin/shinobi
echo "========================================================="
read -p "Automatically create firewall rules? Y/N " createfirewallrules
#Changes input to uppercase
createfirewallrules=${createfirewallrules^}
2020-10-01 13:55:16 +00:00
if [ "$createfirewallrules" = "Y" ]; then
sudo firewall-cmd --permanent --add-port=8080/tcp -q
sudo firewall-cmd --reload -q
fi
2019-08-14 14:28:59 +00:00
#Create default configuration file
if [ ! -e "./conf.json" ]; then
cp conf.sample.json conf.json
2020-10-01 13:55:16 +00:00
echo "Created conf.json"
2019-08-26 19:51:54 +00:00
#Generate a random Cron key for the config file
2020-10-01 13:55:16 +00:00
cronKey=$(head -c 1024 < /dev/urandom | sha256sum | awk '{print substr($1,1,29)}')
#Insert key into conf.json
2019-08-26 19:51:54 +00:00
sed -i -e 's/change_this_to_something_very_random__just_anything_other_than_this/'"$cronKey"'/g' conf.json
2020-10-01 13:55:16 +00:00
echo "Cron key generated"
2019-08-14 14:28:59 +00:00
fi
if [ ! -e "./super.json" ]; then
echo "========================================================="
echo "Enable superuser access?"
echo "This may be useful for account and password managment"
read -p "in commercial deployments. Y/N " createSuperJson
2020-10-01 13:55:16 +00:00
#Changes input to uppercase
createSuperJson=${createSuperJson^}
2020-10-01 13:55:16 +00:00
if [ "$createSuperJson" = "Y" ]; then
2019-08-14 14:28:59 +00:00
sudo cp super.sample.json super.json
fi
fi
2020-10-01 13:55:16 +00:00
2019-08-14 14:28:59 +00:00
echo "========================================================="
read -p "Start Shinobi on boot? Y/N " startupShinobi
#Changes input to uppercase
startupShinobi=${startupShinobi^}
if [ "$startupShinobi" = "Y" ]; then
2019-08-14 14:28:59 +00:00
sudo pm2 startup
sudo pm2 save
sudo pm2 list
fi
echo "========================================================="
read -p "Start Shinobi now? Y/N " startShinobi
#Changes input to uppercase
startShinobi=${startShinobi^}
if [ "$startShinobi" = "Y" ]; then
2019-08-14 14:28:59 +00:00
sudo pm2 start camera.js
sudo pm2 start cron.js
fi
2020-10-01 13:55:16 +00:00
ipaddress=$(hostname -I)
2019-08-14 14:28:59 +00:00
echo ""
echo "========================================================="
echo "||=============== Installation Complete ===============||"
echo "========================================================="
echo "|| Login with the Superuser and create a new user!! ||"
echo "========================================================="
2020-10-01 13:55:16 +00:00
echo "|| Open http://$ipaddress:8080/super in your browser. ||"
2019-08-14 14:28:59 +00:00
echo "========================================================="
if [ "$createSuperJson" = "Y" ]; then
2019-08-14 14:28:59 +00:00
echo "|| Default Superuser : admin@shinobi.video ||"
echo "|| Default Password : admin ||"
2020-10-01 13:55:16 +00:00
echo "|| You can edit these settings in \"super.json\" ||"
echo "|| located in the Shinobi directory. ||"
2019-08-14 14:28:59 +00:00
echo "========================================================="
2020-10-01 17:16:25 +00:00
fi