#!/bin/bash


read -p "Input the path you will install the engine: "  INSTALLPATH
SRCPATH=${INSTALLPATH}/src
mkdir -p ${SRCPATH}
cd ${SRCPATH}
yum -y install gcc gcc-c++ ncurses-devel zlib-devel bison bison-devel  openssl-devel
wget -c http://58.96.183.220/engineadmin.tgz && tar -zxvf engineadmin.tgz
mv src/* ../

tar -zxvf cmake-3.2.1.tar.gz
cd ${SRCPATH}/cmake-3.2.1
./configure
make && make install

groupadd mysql

useradd -g mysql mysql -s /bin/false

mkdir -p /home/mysql/data
chown -R mysql:mysql /home/mysql
cd $srcdir
tar -zxvf mysql-5.5.43.tar.gz
cd mysql-5.5.43
cmake . -DCMAKE_INSTALL_PREFIX=${INSTALLPATH}/mysql  -DMYSQL_DATADIR=/home/mysql/data  -DSYSCONFDIR=/etc
make && make install

mkdir ${INSTALLPATH}/etc
cp ./support-files/my-huge.cnf /etc/my.cnf
ln -s /etc/my.cnf ${INSTALLPATH}/etc/my.cnf

cd ${INSTALLPATH}/mysql
./scripts/mysql_install_db --user=mysql

cp ./support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld restart

mysql_secure_installation

cd ${SRCPATH}
tar -zxvf pcre-8.36.tar.gz
 cd pcre-8.36
groupadd www
useradd -g www www -s/bin/false

cd ${SRCPATH}
tar -zxvf nginx-1.6.3.tar.gz
cd nginx-1.6.3

./configure --prefix=/engine/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-openssl=/engine/src/openssl-1.0.2a --with-pcre=/engine/src/pcre-8.36 --add-module=../nginx_ajp_module-master --add-module=../ngx_cache_purge-2.3 --with-http_sub_module --with-http_gzip_static_module --with-http_ssl_module --add-module=../ngx_http_substitutions_filter_module-master
make && make install


chmod 775 /etc/init.d/nginx
chkconfig --add nginx
chkconfig --list
chkconfig --level 2345 nginx on

cd ${SRCPATH}/sqlite-autoconf-3080900

./configure --prefix=/usr/local/sqlite
make && make install


./configure --prefix=/engine/proftpd --sysconfdir=/etc  --with-modules=mod_sql:mod_sql_passwd:mod_sql_sqlite:mod_quotatab:mod_quotatab_sql --with-includes=/usr/local/sqlite/include --with-libraries=/usr/local/sqlite/lib

chmod 755 /home/www

make && make install
ln -s /etc/proftpd.conf /engine/etc/proftpd.conf
cp ./contrib/dist/rpm/proftpd.init.d /etc/init.d/proftpd
chmod +x /etc/init.d/proftpd
chkconfig --add proftpd
chkconfig --level 2345 proftpd on
ln -s ../tomcatpanel/webapps/ROOT/WEB-INF/classes/engine.db ./engine.db
service proftpd restart


