#!/bin/bash
#############
#Date 2022/11/22
#mail it-arch
#############
echo "##########################################"
echo "Auto Install EduSoho                    ##"
echo "Press Ctrl + C to cancel                ##"
echo "Any key to continue                     ##"
echo "##########################################"
read -n 1
/etc/init.d/iptables status >/dev/null 2>&1
if [ $? -eq 0 ]
then
iptables -I INPUT -p tcp --dport 80 -j ACCEPT && 
iptables -I INPUT -p tcp --dport 443 -j ACCEPT &&
#iptables -I INPUT -p tcp --dport 3306 -j ACCEPT && 
iptables-save >/dev/null 2>&1
else
	echo -e "\033[32m iptables is stopd\033[0m"
fi
sed -i "s/SELINUX=enforcing/SELINUX=disabled/"  /etc/selinux/config
setenforce 0
rpm -ivh ftp://ftp.pbone.net/mirror/pkgs.repoforge.org/mod_xsendfile/mod_xsendfile-0.9-1.el6.rf.x86_64.rpm
ntpdate -s time1.aliyun.com 
#######################################################
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm 
yum remove php* -y
yum install php55w  php55w-bcmath php55w-cli php55w-common  php55w-devel php55w-fpm    php55w-gd php55w-imap  php55w-ldap php55w-mbstring  php55w-mysql   php55w-odbc   php55w-pdo   php55w-pCHANGE_ME  php55w-pCHANGE_ME  php55w-xml php55w-xmlrpc php55w-opcache php55w-intl php55w-pCHANGE_ME -y
echo -e "\033[32m Linux 源更新完毕！ \033[0m"
echo -e "\033[32m PHP 安装... \033[0m"
#######################################################
yum install -y *bcmath* --skip-broken 
sed -i "s/;date.timezone =/date.timezone = Asia\/Shanghai/g" /etc/php.ini 
sed -i "s#`grep post_max_size /etc/php.ini`#post_max_size = 1024M#g" /etc/php.ini 
sed -i "s#`grep memory_limit /etc/php.ini`#memory_limit = 1024M#g" /etc/php.ini 
sed -i "s#`grep upload_max_filesize /etc/php.ini`#upload_max_filesize = 1024M#g" /etc/php.ini 
###################################################
echo -e "\033[32m MySQL 安装... \033[0m"
yum -y install gcc gcc-c++ autoconf httpd libxml* mysql mysql-server  httpd-manual mod_ssl mod_perl mod_auth_mysql mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-devel 
###################################################
service httpd start 
service mysqld start 
service php-fpm start 
chkconfig httpd on 
chkconfig mysqld on 
chkconfig php-fpm on 
##############################################
echo -e "\033[32m 创建zabbix账户 \033[0m"
groupadd edusoho -g 201
useradd -g edusoho -u 201 -m -s /sbin/nologin edusoho
###################################################
echo -e "\033[32m 创建数据库，导入数据 \033[0m"
mysql -uroot -e "create database edusoho character set utf8;" 
mysql -uroot -e "grant all privileges on edusoho.* to zabbix@localhost identified by 'edusoho';"
mysql -uroot -e "flush privileges;"
mysqladmin -uroot password "edusoho"
################################################
echo -e "\033[32m 建立站点数据 \033[0m"
if [ -d /var/www/html ];then
    cd /var/www/html
else
    mkdir -p /var/www/html && cd /var/www/html
fi
wget http://download.edusoho.com/edusoho-7.2.9.tar.gz
tar zxvf edusoho-7.2.9.tar.gz
rm edusoho-7.2.9.tar.gz -Rf
chown apache edusoho/ -Rf
cat>>/etc/httpd/conf/httpd.conf <<EOF
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/html/edusoho/web
    <Directory /var/www/html/edusoho/web>
        # enable the .htaccess rewrites
        AllowOverride All
        Order allow,deny
        Allow from All
    </Directory>
    ErrorLog /var/log/httpd/edusoho_error.log
    CustomLog /var/log/httpd/edusoho_access.log combined
</VirtualHost>
EOF
echo -e "\033[32m 启动服务 \033[0m"
/etc/init.d/httpd restart
#################################################
echo -e "\033[32m edusoho is Install Success,MySQL user:root  Passwd:CHANGE_ME \033[0m"
echo -e "\033[32m edusoho is Install Success,user:Admin  Passwd:CHANGE_ME \033[0m"
