Skip to content

Instantly share code, notes, and snippets.

@ToroNZ
Last active April 30, 2017 07:02
Show Gist options
  • Save ToroNZ/ed62dc33c90be219121a0c92dd973750 to your computer and use it in GitHub Desktop.
Save ToroNZ/ed62dc33c90be219121a0c92dd973750 to your computer and use it in GitHub Desktop.
Shinobi instal script for Centos (tested on v7)
#!/bin/bash
set -e
# check if I am sudo
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# Proceed
#Download prod repo
yum update -y
git clone -b master https://github.com/moeiscool/Shinobi
donde=$(pwd)
echo "Shinobi - Get dependencies"
#Install EPEL Repo
yum install epel-release -y && yum update -y
#Enable Nux Dextop repo for FFMPEG
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
yum install ffmpeg ffmpeg-devel nodejs npm mariadb mariadb-server -y
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
#Start mysql and enable on boot
systemctl start mariadb
systemctl enable mariadb
#Run mysql install
mysql_secure_installation
echo "Shinobi - Linking node to nodejs"
ln -s /usr/bin/nodejs /usr/bin/node
#Important stuff - otherwise you won't be able to delete stuff and things are funny
chmod -R 755 .
#SQL Shinobi stuff
echo "Shinobi - Database Installation"
echo "What is your SQL Password?"
echo "**You set this just a few moments ago if MySQL was installed during this installer."
read sqlpass
# Create username/password for first WebGUI user
echo "This will set your first Shinobi user (WebUI)"
read -p "Please insert your email: " USRNAM
sed -i "s/ccio@m03.ca/$USRNAM/" $donde/sql/default_data.sql
# Create DB
mysql -u root -p$sqlpass -e "source sql/framework.sql" || true
mysql -u root -p$sqlpass --database ccio -e "source sql/default_data.sql" || true
# Create MariaDB User
# Create random password
PASSWDDB="$(openssl rand -base64 12)"
# replace "-" with "_" for database username
echo "Set MariaDB User for DB..."
read MAINDB
# Enough var, go..
mysql -uroot -p$sqlpass -e "CREATE USER ${MAINDB}@localhost IDENTIFIED BY '${PASSWDDB}';"
mysql -uroot -p$sqlpass -e "GRANT ALL PRIVILEGES ON ccio.* TO '${MAINDB}'@'localhost';"
mysql -uroot -p$sqlpass -e "FLUSH PRIVILEGES;"
# Install more dependencies
echo "Shinobi - Install NPM Libraries"
npm install
echo "Shinobi - Install PM2"
npm install pm2 -g
cp $donde/conf.sample.json $donde/conf.json
# Get system timezone
tzone=$(date +%z)
sed -i "s/-0800/"$tzone"/" $donde/conf.json
# Start inserting users and passwords to make this install unique (security-wise)
sed -i "s/majesticflame/"$MAINDB"/" $donde/conf.json
sed -i 's/"password": ""/"password": "'$PASSWDDB'"/' $donde/conf.json
sed -i 's/"DropboxAppKey": "mwgh09b16myew4s"/"DropboxAppKey": "INSERT_YOUR_KEY"/' $donde/conf.json
cp $donde/super.sample.json $donde/super.json
echo "Now to create a superuser - Type what username you want"
read superadmin
sed -i 's/"admin@shinobi.video"/"'$superadmin'"/' $donde/super.json
echo "Now password for $superadmin"
read superpasswd
sed -i 's/"21232f297a57a5a743894a0e4a801fc3"/"'$superpasswd'"/' $donde/super.json
# Set firewall
yum install -y ufw
firewall-cmd --permanent --add-port=3000/tcp
firewall-cmd --reload
# Install Motion Detection dependencies
echo "Do you wish to install Motion Detection feature?"
select yn in "Yes" "No"; do
case $yn in
Yes ) yum install -y cairo cairo-devel cairomm-devel libjpeg-turbo-devel pango pango-devel pangomm pangomm-devel giflib-devel liberation-sans-fonts.noarch;
yum groupinstall -y 'Development Tools';
npm install canvas;
cp $donde/plugins/motion/conf.sample.json $donde/plugins/motion/conf.json;
sed -i 's/"port":8080/"port":3000/' $donde/plugins/motion/conf.json
break;;
No ) break;;
esac
done
# Start PM2
pm2 start $donde/camera.js
pm2 start $donde/cron.js
pm2 start $donde/plugins/motion/shinobi-motion.js
# Set things to start at boot time
pm2 startup
# Save PM2 settings
pm2 save
IP=$(hostname -I)
echo "Please browse to http://$IP:3000 and be amazed > $USRNAM/password will get you going"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment