Current File : //root/patchupdate211118.sh
#!/bin/bash
file="/etc/sentora/panel/patch27-201118.log"
EMAIL_LOG=0
if [ -f "$file" ]
then
	echo "Patch 2.7 Already Updated"
	exit
fi
touch /etc/sentora/panel/patch27-201118.log
echo "#######################################################" > /etc/sentora/panel/patch27-201118.log
echo "#   Patch Updation to 2.7 latest Version Start here   #" >> /etc/sentora/panel/patch27-201118.log
echo "#######################################################" >> /etc/sentora/panel/patch27-201118.log
echo "..."
MOD_SEC_FILE="/etc/httpd/conf.d/modsecurity.conf"
if [ -f "/etc/httpd/conf.d/modsecurity.conf" ]
then
	MOD_SEC_FILE="/etc/httpd/conf.d/modsecurity.conf"
elif [ -f "/etc/httpd/conf.d/mod_security.conf" ]
then
	MOD_SEC_FILE="/etc/httpd/conf.d/mod_security.conf"
else
	MOD_SEC_FILE=""
	echo "Unable to find the mod security file " >> /etc/sentora/panel/patch27-201118.log
fi
if [ $MOD_SEC_FILE != "" ]
then
	echo "Changing Mod Security Upload Limit Values"
	sed -i '/SecRequestBodyLimit /c\SecRequestBodyLimit 2097152000' $MOD_SEC_FILE
	sed -i '/SecRequestBodyNoFilesLimit/c\SecRequestBodyNoFilesLimit 20971520' $MOD_SEC_FILE
	sed -i '/SecRequestBodyInMemoryLimit/c\SecRequestBodyInMemoryLimit 20971520' $MOD_SEC_FILE
	HTTPD_RESTART=$(apachectl configtest 2>&1)
	echo $HTTPD_RESTART

	HTTPD_SYNTAX=`echo $HTTPD_RESTART | grep -i "Syntax OK"`
	echo $HTTPD_SYNTAX  >> /etc/sentora/panel/patch27-201118.log
	if [[ $HTTPD_SYNTAX ]]
	then
	    service httpd restart
	else
	    echo "There is having the syntax error in apache config. Please check" >> /etc/sentora/panel/patch27-201118.log
		EMAIL_LOG=1
	fi
	LIGHTTPD_CONFIGTEST=$(lighttpd -t -f /etc/lighttpd/lighttpd.conf 2>&1)
	echo $LIGHTTPD_CONFIGTEST >> /etc/sentora/panel/patch27-201118.log

	LIGHTTPD_RESTART=`echo $LIGHTTPD_CONFIGTEST | grep -i "Syntax OK"` 
	if [[ $LIGHTTPD_RESTART ]]
	then
		service lighttpd restart
	else
		echo "There is having the syntax error in lighttpd config. Please check" >> /etc/sentora/panel/patch27-201118.log
		EMAIL_LOG=1
	fi
fi
chmod +x /usr/bin/setso
HR_VER=`setso --show dbversion`
echo $HR_VER
if [[ $HR_VER = "2.7" ]]
then
	sed -i '/Version : /c\Version : 2.7' /etc/sentora/panel/version.txt
	echo "Need to update the version in panel log. And its updated successfully" >> /etc/sentora/panel/patch27-201118.log
	echo "#######################################################" >> /etc/sentora/panel/patch27-201118.log
	echo "#           Updating latest Panel...                  #" >> /etc/sentora/panel/patch27-201118.log
	echo "#######################################################" >> /etc/sentora/panel/patch27-201118.log
	if ls -l /var/lib/mysql/sentora_core/x_java_version.frm 2> /dev/null > /dev/null
	then
		echo "Java Server" >> /etc/sentora/panel/patch27-201118.log
		cd /etc/sentora/
		wget -O panel.zip http://hostingraja.info/Version2.7/patch/java/panel.zip
		unzip -o panel.zip
	else
		echo "Not Java Server" >> /etc/sentora/panel/patch27-201118.log
		cd /etc/sentora/
		wget -O panel.zip http://hostingraja.info/Version2.7/patch/panel.zip
		unzip -o panel.zip
	fi
	find panel/ -type d -exec chmod 755 {} \;
	find panel/ -type f -exec chmod 644 {} \;
	chmod +x /etc/sentora/panel/bin/setso
	chmod +x /etc/sentora/panel/bin/setzadmin
	chown -R apache:apache panel/
else
	echo "No need to update the version in panel log. skipping this step..." >> /etc/sentora/panel/patch27-201118.log

fi
echo "Adding 2006 port in csf... " >> /etc/sentora/panel/patch27-201118.log
if [ $HR_VER = "2.7" ] || [ $HR_VER = "2.6" ]
then
	cd /root
	wget -O AddTcpPort http://hostingraja.info/patch/AddTcpPort
	mv AddTcpPort /usr/bin/AddTcpPort
	chmod +x /usr/bin/AddTcpPort
	AddTcpPort 2006 2006
fi
echo "#######################################################" >> /etc/sentora/panel/patch27-201118.log
echo "#         Checking and INstalling Composer...         #" >> /etc/sentora/panel/patch27-201118.log
echo "#######################################################" >> /etc/sentora/panel/patch27-201118.log
if [ $HR_VER = "2.6" ]
then
	COMPOSER_PATH="/usr/local/bin/composer"
	PHP70_PATH="/usr/local/php70/bin/php"
	if [ ! -f "$COMPOSER_PATH" ] && [ -f $PHP70_PATH ]
	then
		/usr/local/php70/bin/php  -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
		/usr/local/php70/bin/php  composer-setup.php
		/usr/local/php70/bin/php  -r "unlink('composer-setup.php');"
		mv composer.phar /usr/bin/composer
		yes | cp  /usr/bin/composer /usr/local/bin/composer
	else
		echo "Composer already installed or unable to find the php70 path" >> /etc/sentora/panel/patch27-201118.log
	fi
fi
if [ $EMAIL_LOG = 1 ]
then
	echo /etc/sentora/panel/patch27-201118.log | mail -s "Error in Config File" support@hostingraja.info
else
	echo "Updated Successfully" >> /etc/sentora/panel/patch27-201118.log
fi