haproxy-wi/install.sh

339 lines
8.7 KiB
Bash
Raw Normal View History

2019-02-02 00:01:57 +00:00
#!/bin/bash
2018-04-25 12:24:39 +00:00
PORT=8080
HOME_HAPROXY_WI=haproxy-wi
echo "Choose DB: (1)Sqlite or (2)Mysql? Default: Sqlite"
read DB
2018-04-25 12:24:39 +00:00
if [[ $DB == 2 ]];then
echo "Mysql server is (1)remote or (2)local?"
read REMOTE
if [[ $REMOTE == 1 ]];then
echo "Enter IP remote Mysql server"
read IP
else
MINSTALL=1
fi
fi
echo "Choose Haproxy-WI port. Default: [$PORT]"
read CHPORT
echo "Enter Haproxy-wi home dir. Default: /var/www/[$HOME_HAPROXY_WI]"
read CHHOME_HAPROXY
if [[ -z $HAPROXY ]];then
HAPROXY="no"
fi
if [[ -n $CHPORT ]];then
PORT=$CHPORT
fi
if [[ -n "$CHHOME_HAPROXY" ]];then
HOME_HAPROXY_WI=$CHHOME_HAPROXY
fi
echo "################################"
echo ""
echo ""
2018-04-25 12:24:39 +00:00
echo -e "Installing Required Software"
echo ""
echo ""
echo "################################"
2018-04-25 12:24:39 +00:00
2018-05-30 18:09:02 +00:00
if hash apt-get 2>/dev/null; then
2019-05-18 08:11:03 +00:00
apt-get install git net-tools lshw dos2unix apache2 gcc netcat python3.5 mod_ssl python3-pip g++ freetype2-demos libatlas-base-dev openldap-dev libpq-dev python-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libffi-dev python3-dev libssl-dev -y
2018-05-30 18:09:02 +00:00
HTTPD_CONFIG="/etc/apache2/apache2.conf"
HAPROXY_WI_VHOST_CONF="/etc/apache2/sites-enabled/haproxy-wi.conf"
HTTPD_NAME="apache2"
HTTPD_PORTS="/etc/apache2/ports.conf"
if [[ $MINSTALL == 1 ]];then
apt-get install software-properties-common -y
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
add-apt-repository 'deb [arch=amd64,i386,ppc64el] https://mirrors.evowise.com/mariadb/repo/10.1/ubuntu xenial main' -y
apt-get install mariadb-server -y
fi
else
if [[ $(cat /etc/*-rele* |grep NAME |head -1) == 'NAME="CentOS Linux"' ]];then
2018-04-28 04:06:48 +00:00
yum -y install epel-release
2018-05-30 18:09:02 +00:00
fi
2018-09-29 05:23:01 +00:00
yum -y install https://centos7.iuscommunity.org/ius-release.rpm
2019-09-04 06:26:52 +00:00
yum -y install git nmap-ncat net-tools python35u dos2unix python35u-pip mod_ssl httpd python35u-devel gcc-c++ openldap-devel python-devel python-jinja2
2018-05-30 18:09:02 +00:00
HTTPD_CONFIG="/etc/httpd/conf/httpd.conf"
HAPROXY_WI_VHOST_CONF="/etc/httpd/conf.d/haproxy-wi.conf"
HTTPD_NAME="httpd"
HTTPD_PORTS=$HTTPD_CONFIG
echo "Edit firewalld"
firewall-cmd --zone=public --add-port=$PORT/tcp --permanent
firewall-cmd --reload
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
if [[ $MINSTALL == 1 ]];then
yum -y install mariadb mariadb-server mysql-devel
fi
2018-04-28 04:06:48 +00:00
fi
2018-05-30 18:09:02 +00:00
2018-04-25 12:24:39 +00:00
if [ $? -eq 1 ]
then
echo "################################"
echo ""
echo ""
echo "Unable to install Required Packages Please check Yum config"
echo ""
echo ""
echo "################################"
exit 1
2018-04-25 12:24:39 +00:00
fi
echo "################################"
echo ""
echo ""
2018-04-25 12:24:39 +00:00
echo -e "Updating Apache config and Configuring Virtual Host"
echo ""
echo ""
echo "################################"
2018-05-30 18:09:02 +00:00
sudo sed -i "0,/^Listen .*/s//Listen $PORT/" $HTTPD_PORTS
2018-04-25 12:24:39 +00:00
echo "################################"
echo ""
echo ""
2018-04-25 12:24:39 +00:00
echo -e "Checking for Apache Vhost config"
echo ""
echo ""
echo "################################"
2018-04-25 12:24:39 +00:00
2018-05-30 18:09:02 +00:00
sudo touch $HAPROXY_WI_VHOST_CONF
/bin/cat $HAPROXY_WI_VHOST_CONF
2018-04-25 12:24:39 +00:00
if [ $? -eq 1 ]
then
echo "################################"
echo ""
echo ""
echo "Didnt Sense exisitng installation Proceeding ...."
echo ""
echo ""
echo "################################"
exit 1
2018-04-25 12:24:39 +00:00
else
echo "################################"
echo ""
echo ""
2018-07-15 19:49:11 +00:00
echo -e "Creating VirtualHost for Apache"
echo ""
echo ""
echo "################################"
2019-05-18 08:11:03 +00:00
2019-09-12 07:16:38 +00:00
sudo sed -i "s/haprox-wi/$HOME_HAPROXY_WI" config_other/*/*
sudo cp config_other/httpd/haprox-wi.conf $HAPROXY_WI_VHOST_CONF
sudo cp config_other/logrotate/* /etc/logrotate.d/
sudo cp config_other/syslog/* /etc/rsyslog.d/
sudo cp config_other/* /etc/systemd/system/
2018-11-26 10:00:25 +00:00
2018-07-25 15:57:42 +00:00
sed -i 's/#$UDPServerRun 514/$UDPServerRun 514/g' /etc/rsyslog.conf
sed -i 's/#$ModLoad imudp/$ModLoad imudp/g' /etc/rsyslog.conf
systemctl daemon-reload
2018-07-25 15:57:42 +00:00
systemctl restart rsyslog
2018-08-23 06:48:10 +00:00
systemctl restart metrics_haproxy.service
2018-07-25 15:57:42 +00:00
systemctl restart checker_haproxy.service
2018-11-26 10:00:25 +00:00
systemctl restart keep_alive.service
systemctl enable metrics_haproxy.service
systemctl enable checker_haproxy.service
2018-11-26 10:00:25 +00:00
systemctl enable keep_alive.service
2018-05-30 18:09:02 +00:00
if hash apt-get 2>/dev/null; then
sed -i 's|/var/log/httpd/|/var/log/apache2/|g' $HAPROXY_WI_VHOST_CONF
cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/cgi.load
2018-04-25 12:24:39 +00:00
fi
2018-05-30 18:09:02 +00:00
echo "################################"
echo ""
echo ""
2018-04-25 12:24:39 +00:00
echo -e " Testing config"
echo ""
echo ""
echo "################################"
2018-04-25 12:24:39 +00:00
/usr/sbin/apachectl configtest
if [ $? -eq 1 ]
then
echo "apache Configuration Has failed, Please verify Apache Config"
echo ""
echo ""
echo "################################"
exit 1
2018-04-25 12:24:39 +00:00
fi
echo "################################"
echo ""
echo ""
2018-04-25 12:24:39 +00:00
echo -e "Getting Latest software from The repository"
echo ""
echo ""
echo "################################"
2018-05-30 18:09:02 +00:00
2018-04-25 12:24:39 +00:00
/usr/bin/git clone https://github.com/Aidaho12/haproxy-wi.git /var/www/$HOME_HAPROXY_WI
if [ $? -eq 1 ]
then
echo "Unable to clone The repository Please check connetivity to Github"
exit 1
fi
echo "################################"
echo ""
echo ""
2018-04-25 12:24:39 +00:00
echo -e "Installing required Python Packages"
echo ""
echo ""
echo "################################"
sudo -H pip3.5 install --upgrade pip
2018-09-20 07:32:08 +00:00
sudo pip3.5 install -r /var/www/$HOME_HAPROXY_WI/requirements.txt
2018-04-25 12:24:39 +00:00
if [ $? -eq 1 ]
then
echo "Unable to install Required Packages, Please check Pip error log and Fix the errors and Rerun the script"
exit 1
else
echo "################################"
echo ""
echo ""
echo -e "Installation Succesful"
echo ""
echo ""
echo "################################"
2018-04-25 12:24:39 +00:00
fi
if [[ $MINSTALL = 1 ]];then
echo "################################"
echo ""
echo ""
echo -e "starting databse and applying config"
echo ""
echo ""
echo "################################"
systemctl enable mariadb
systemctl start mariadb
if [ $? -eq 1 ]
then
echo "################################"
echo ""
echo ""
echo "Can't start Mariadb"
echo ""
echo ""
echo "################################"
exit 1
fi
if [ $? -eq 1 ]
then
echo "################################"
echo ""
echo ""
echo "Unable to start Mariadb Service Please check logs"
echo ""
echo ""
echo "################################"
exit 1
else
mysql -u root -e "create database haproxywi";
mysql -u root -e "grant all on haproxywi.* to 'haproxy-wi'@'%' IDENTIFIED BY 'haproxy-wi';"
mysql -u root -e "grant all on haproxywi.* to 'haproxy-wi'@'localhost' IDENTIFIED BY 'haproxy-wi';"
mysql -u root -e "flush privileges;"
2018-04-25 12:24:39 +00:00
echo "################################"
echo ""
echo ""
echo -e "Databse has been created Succesfully and User permissions added"
echo ""
echo ""
echo "################################"
2018-04-25 12:24:39 +00:00
fi
fi
if [[ $DB == 2 ]];then
echo "################################"
echo ""
echo ""
echo -e "Setting Application to use Mysql As a backend"
echo ""
echo ""
echo "################################"
2018-11-06 06:50:36 +00:00
sed -i '0,/enable = 0/s//enable = 1/' /var/www/$HOME_HAPROXY_WI/app/haproxy-wi.cfg
2018-04-25 12:24:39 +00:00
fi
2018-05-30 18:09:02 +00:00
2018-04-25 12:24:39 +00:00
if [[ -n $IP ]];then
2018-11-06 06:50:36 +00:00
sed -i "0,/mysql_host = 127.0.0.1/s//mysql_host = $IP/" /var/www/$HOME_HAPROXY_WI/app/haproxy-wi.cfg
2018-04-25 12:24:39 +00:00
fi
echo "################################"
echo ""
echo ""
2018-04-25 12:24:39 +00:00
echo -e " Starting Services"
echo ""
echo ""
echo "################################"
2018-04-25 12:24:39 +00:00
2018-05-30 18:09:02 +00:00
systemctl enable $HTTPD_NAME; systemctl restart $HTTPD_NAME
2018-04-25 12:24:39 +00:00
if [ $? -eq 1 ]
then
echo "################################"
echo ""
echo ""
echo "Services Has Not been started, Please check error logs"
echo ""
echo ""
echo "################################"
2018-04-25 12:24:39 +00:00
else
echo "################################"
echo ""
echo ""
echo -e "Services have been started, Please Evaluate the tool by adding a host / DNS ectry for /etc/hosts file. \n This can be done by adding an entry like this \n 192.168.1.100 haprox-wi.example.com"
echo ""
echo ""
echo "################################"
2018-04-25 12:24:39 +00:00
fi
2018-10-10 09:57:28 +00:00
sed -i "s|^fullpath = .*|fullpath = /var/www/$HOME_HAPROXY_WI|g" /var/www/$HOME_HAPROXY_WI/app/haproxy-wi.cfg
echo "################################"
echo ""
echo ""
2018-04-25 12:24:39 +00:00
echo -e " Thank You for Evaluating Haproxy-wi"
echo ""
echo ""
echo "################################"
2018-04-25 12:24:39 +00:00
sudo mkdir /var/www/$HOME_HAPROXY_WI/app/certs
sudo mkdir /var/www/$HOME_HAPROXY_WI/keys
2018-08-24 07:29:28 +00:00
sudo mkdir /var/www/$HOME_HAPROXY_WI/configs/
sudo mkdir /var/www/$HOME_HAPROXY_WI/configs/hap_config/
sudo mkdir /var/www/$HOME_HAPROXY_WI/configs/kp_config/
sudo mkdir /var/www/$HOME_HAPROXY_WI/log/
sudo sudo chmod +x /var/www/$HOME_HAPROXY_WI/app/*.py
sudo chmod +x /var/www/$HOME_HAPROXY_WI/app/tools/*.py
2018-10-11 02:49:50 +00:00
chmod +x /var/www/$HOME_HAPROXY_WI/update.sh
2018-10-25 03:50:30 +00:00
sudo ln -s /usr/bin/python3.5 /usr/bin/python3
2018-08-24 07:29:28 +00:00
2018-05-30 18:09:02 +00:00
cd /var/www/$HOME_HAPROXY_WI/app
2018-09-01 10:43:25 +00:00
./create_db.py
2018-08-15 08:17:57 +00:00
if hash apt-get 2>/dev/null; then
sudo chown -R www-data:www-data /var/www/$HOME_HAPROXY_WI/
sudo chown -R www-data:www-data /var/log/apache2/
else
sudo chown -R apache:apache /var/www/$HOME_HAPROXY_WI/
sudo chown -R apache:apache /var/log/httpd/
fi
2018-04-25 12:24:39 +00:00
2018-07-15 19:49:11 +00:00
exit 0