Advertisement
tjone270

install-qlstats.sh

Jan 6th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.56 KB | None | 0 0
  1. #! /bin/bash
  2. if [ "$EUID" -ne 0 ]; then
  3.   echo "This script needs to be run as root."
  4.   echo "HINT: Run 'sudo !!' to run this script as root."
  5.   exit 1
  6. fi
  7.  
  8. export PYTHONPATH=/home/qlstats/XonStat/lib/python
  9.  
  10. clear
  11.  
  12. echo "Welcome to Install-QLStats.sh"
  13. echo "Created by Thomas Jones (thomas@tomtecsolutions.com)"
  14. echo -e "\n"
  15.  
  16. read -p "Ready to install QLStats? [y/n]" -n 1
  17.  
  18. if [ $REPLY != "y" ]; then
  19.   echo -e "\nResponse was not 'y', exiting..."
  20. fi
  21.  
  22. echo -e "\nInstalling packages..."
  23. echo "Installing git..."; sudo apt-get -y install git > ~/qlstatsinstall-log.txt
  24. echo "Installing node.js..."; sudo apt-get -y install nodejs > ~/qlstatsinstall-log.txt
  25. echo "Softlinking node.js..."; sudo ln -s /usr/bin/nodejs /usr/bin/node > ~/qlstatsinstall-log.txt 2>&1
  26. echo "Installing npm..."; sudo apt-get -y install npm > ~/qlstatsinstall-log.txt
  27. echo "Installing python 2.7..."; sudo apt-get -y install python > ~/qlstatsinstall-log.txt
  28. echo "Installing python 3.4..."; sudo apt-get -y install python3 > ~/qlstatsinstall-log.txt
  29. echo "Installing python-setuptools..."; sudo apt-get -y install python-setuptools > ~/qlstatsinstall-log.txt
  30. echo "Installing python-pip and python-dev..."; sudo apt-get -y install python-pip python-dev > ~/qlstatsinstall-log.txt
  31. echo "Installing pyzmq..."; sudo easy-install pyzmq > ~/qlstatsinstall-log.txt
  32. echo "Installing libzmq3, libzmq3-dev and libzmq3-dbg..."; sudo apt-get -y install libzmq3 libzmq3-dev libzmq3-dbg > ~/qlstatsinstall-log.txt
  33. echo "Installing postgresql..."; sudo apt-get -y install postgresql postgresql-server-dev-9.4 > ~/qlstatsinstall-log.txt
  34. echo "Installing pastescript..."; sudo python -m pip install pastescript > ~/qlstatsinstall-log.txt
  35.  
  36. echo "Creating the QLStats account...";
  37. echo "Please enter a password for the new QLStats account:"; adduser --quiet --shell /bin/bash --gecos 0 qlstats
  38.  
  39. cd /home/qlstats
  40.  
  41. echo "export PYTHONPATH=/home/qlstats/XonStat/lib/python" >> .bashrc
  42.  
  43. sudo -u qlstats git clone https://github.com/PredatH0r/XonStat.git
  44. sudo -u qlstats git clone https://github.com/antzucaro/xonstatdb.git
  45.  
  46. cd XonStat/feeder; npm install; mkdir ql-match-jsons; mkdir lib; mkdir lib/python
  47.  
  48. cd /var/lib/postgresql
  49.  
  50. echo "Enter 'xonstat' (no quotes) at this password prompt:"; sudo -u postgres createuser -P xonstat
  51. if ! $(sudo -u postgres psql template1 -c 'SHOW SERVER_ENCODING' | grep -q UTF8); then
  52.   sudo -u postgres psql postgres -c "update pg_database set datallowconn = TRUE where datname = 'template0';"
  53.   sudo -u postgres psql template0 -c "update pg_database set datistemplate = FALSE where datname = 'template1';"
  54.   sudo -u postgres psql template0 -c "drop database template1;"
  55.   sudo -u postgres psql template0 -c "create database template1 with template = template0 encoding = 'UTF8';"
  56.   sudo -u postgres psql template0 -c "update pg_database set datistemplate = TRUE where datname = 'template1';"
  57.   sudo -u postgres psql template1 -c "update pg_database set datallowconn = FALSE where datname = 'template0';"
  58. fi
  59. sudo -u postgres psql postgres -c "CREATE DATABASE xonstatdb WITH ENCODING='UTF8' OWNER=xonstat CONNECTION LIMIT=-1;"
  60. sed '90s/peer/md5/' /etc/postgresql/9.4/main/pg_hba.conf
  61.  
  62. cd /home/qlstats
  63.  
  64. export PGPASSWORD="xonstat"
  65. sudo -u postgres psql -U xonstat xonstatdb -c "CREATE SCHEMA xonstat AUTHORIZATION xonstat; CREATE LANGUAGE plpgsql;"
  66. sudo -u postgres psql -U xonstat xonstatdb -c "\i /home/qlstats/xonstatdb/build/build_full.sql"
  67. sudo -u postgres psql -U xonstat xonstatdb -c "\i /home/qlstats/XonStat/sql/qlstats-init.sql"
  68.  
  69. python setup.py install --home=/home/qlstats/XonStat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement