Last active
April 30, 2017 07:11
-
-
Save ToroNZ/a60a46dd18b7eb2aae5211c42c646dec to your computer and use it in GitHub Desktop.
Shinobi instal script for Ubuntu (tested on 16.04)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# check if I am sudo | |
if [ "$EUID" -ne 0 ] | |
then echo "Only sudoers please" | |
exit | |
fi | |
# Proceed | |
DEBIAN_FRONTEND=noninteractive | |
echo "Shinobi - Getting dependencies..." | |
#Install ffmpeg 3.2 | |
apt update -y && apt upgrade -y && apt autoremove -y | |
apt install -y software-properties-common | |
add-apt-repository -y ppa:jonathonf/ffmpeg-3 | |
apt update -y && apt upgrade -y | |
apt install -y ffmpeg libav-tools x264 x265 flac git pwgen | |
#Download prod repo | |
git clone -b master https://github.com/moeiscool/Shinobi | |
cd Shinobi | |
donde=$(pwd) | |
#Install MariaDB repo | |
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 | |
add-apt-repository -y 'deb [arch=amd64,i386,ppc64el] http://mariadb.mirror.digitalpacific.com.au/repo/10.1/ubuntu xenial main' | |
#Install NodeJS Repo | |
curl -sL https://deb.nodesource.com/setup_6.x -o ~/nodesource_setup.sh | |
bash ~/nodesource_setup.sh | |
#Install nodejs, npm, mariadb | |
apt update && apt install -y nodejs mariadb-server mariadb-client build-essential | |
npm cache clean -f | |
npm install -g n | |
n latest | |
#chmode -R 755 . | |
#Start mysql and enable on boot | |
systemctl start mariadb | |
systemctl enable mariadb | |
#Run mysql install | |
mysql_secure_installation | |
echo "Shinobi - Database Installation" | |
echo "What is your root SQL Password?" | |
echo "**You set this just a few moments ago if MariaDB was installed during this installer." | |
read sqlpass | |
# Create random username/password for first WebGUI user | |
read -p "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;" | |
echo "Shinobi - Install NPM Libraries" | |
npm install | |
echo "Shinobi - Install PM2" | |
npm install pm2 -g | |
cp $donde/conf.sample.json $donde/conf.json | |
sed -i 's/-0800/+1300/' $donde/conf.json | |
sed -i 's/majesticflame/toroloco/' $donde/conf.json | |
sed -i 's/"password": ""/"password": "'$PASSWDDB'"/' $donde/conf.json | |
sed -i 's/"DropboxAppKey": "mwgh09b16myew4s"/"DropboxAppKey": "INSERT_YOUR_KEY"/' $donde/conf.json | |
sed -i 's/"port": 8080/"port": 3000/' $donde/conf.json | |
cp $donde/super.sample.json $donde/super.json | |
sed -i 's/"admin@shinobi.video"/"'$USRNAM'"/' $donde/super.json | |
echo "SuperAdmin account - Set a password for $USRNAM" | |
read superpasswd | |
sed -i 's/"21232f297a57a5a743894a0e4a801fc3"/"'$superpasswd'"/' $donde/super.json | |
# Set firewall | |
apt update -y && apt autoremove -y | |
apt install -y ufw | |
ufw enable | |
ufw allow 3000/tcp | |
ufw allow ssh | |
ufw allow 3306/tcp | |
ufw reload | |
# Install Motion Detection dependencies | |
echo "Do you wish to install Motion Detection feature?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) apt-get install -y libcairo2-dev libjpeg-dev libpango1.0-dev libgif-dev build-essential g++ libjpeg8-dev; | |
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" |
@moeiscool
Righto:
-Fixed the add-apt-repository stuff, looks to be a Debian/Ubuntu bug where it needs an update first. So i change the order and I made it bit overkill so pretty much everyone starts with a clean slate.
-I don't really know why you got that lock issue when installing ufw... but I've included an update/clean command first to clear any lock on apt. TBH the whole firewall thing could be optional, but it's a good practice.
-Added the cron.js process (doh!)
Thx mate
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey just wanna let you know
add-apt-repository
came up not found on vps im using. i had toapt update
thenapt-get install software-properties-common
and when it got to
apt install -y ufw
i gotthe admin username has to be an email as well or the forum will fail saying the username isnt a valid email.
and cron isnt started after camera.js
pm2 start $donde/cron.js
should do it