#!/bin/bash
#
DATE=`date +%Y/%m/%d/`
HOST=`hostname -s`
USER=`whoami`
PHPDIR=/usr/local/php
INSTALLDIR=/down/webinstall
NGINXDIR=/usr/local/nginx
MYSQLDIR=/usr/local/mysql
MYSQLDATA=/var/lib/mysql
MYCONFIG=/usr/local/mysql/bin/mysql
SHELLDIR=/shell
WWWDIR=/var/www
RCLOCAL=/etc/rc.d/rc.local
MYSQLSAVED=${MYSQLDIR}
MYSQLDATASAVED=${MYSQLDATA}
PHPSAVED=${PHPDIR}
NGINXSAVED=${NGINXDIR}
if [ ! -f “php-5.3.1.tar.gz” ];then
wget http:/XXXXXXXXXshell/php-5.3.1.tar.gz -P ${INSTALLDIR}
fi
if [ ! -s “mysql-5.0.22.tar.gz” ];then
wget XXXXXXXXXXXXXXX/shell/mysql-5.0.22.tar.gz -P ${INSTALLDIR}
fi
if [ ! -e “nginx-0.7.64.tar.gz” ];then
wget XXXXXXXXXXXXXXXXX/nginx-0.7.64.tar.gz -P ${INSTALLDIR}
fi
while :
do
clear
cat << Display
================================================================================
User:${USER} Hostname:${HOST} Date:${DATE}
——————————————————————————–
1) Easy Application Installer Nginx+PHP+Mysql.
2) MYSQL Distributed Installation.
3) PHP Distributed Installation.
4) NGINX Distributed Installation.
Q) Quit Installation.
H) Help.
=================================================================================
Display
echo -n -e “\t\t\tPlease choose to install >”
read ANS
case “${ANS}” in
1)EASY=”1″
;;
2)MYSQL=”2″
;;
3)PHP=”3″
;;
4)NGINX=”4″
;;
q|Q)
break
;;
h|H)
echo -e “\t\t\t*******Haha,God help you********”
;;
*) echo -e “\t\t\tSorry,unknown user reponse.pless enter [1,2,3,4,Q,H]”
esac
if [ “$EASY” = “1” ];then
EASY=”A”
fi
#*************************MYSQL Partial Installation*****************************
if [ “${MYSQL}” = “2” ] || [ “${EASY}” = “A” ];then
while [ -d “${MYSQLDIR}” ]
do
if [ -z ${AGAIN} ];then
echo “MYSQL Directory already exists”
fi
echo -n “Do you reinstall {y/n}:”
read REIN
case “${REIN}” in
n|N)EASY=”” && MYSQLDIR=
;;
y|Y)rm -rf ${MYSQLDIR}
;;
*)echo “Input error, please try again”
AGAIN=AK47
;;
esac
done
until [ ! -d “${MYSQLDATA}” ]
do
echo -n “Warning: The database already exists whether or deleted!!!!!![y/n]:”
read DATA
case “$DATA” in
y|Y)rm -rf “${MYSQLDATA}”
;;
n|N)MYSQLDATA=
;;
*)echo “Input error, please try again:[y/n]”
;;
esac
done
ls ${INSTALLDIR}| grep -v “tar.gz” |grep “mysql-” |xargs rm -rf
find ${INSTALLDIR} -name mysql*.tar.gz |xargs tar -zxvf && cd mysql-*
chmod 700 ${INSTALLDIR}/mysqlconfig
chmod 700 ${INSTALLDIR}/mysqlconf
killall mysqld > /dev/null 2>&1
if “${INSTALLDIR}”/mysqlconfig;then
make -j5 ; make install
SAVEDIFS=$IFS
IFS=
for SQL in “${INSTALLDIR}/mysqlconf”
do
${SQL}
done
IFS=$SAVEDIFS
fi
cd “${INSTALLDIR}”
if [ -f ${MYCONFIG} ];then
echo
echo -e “\t\t\t**********MYSQL Already Installation Done**********”
echo
sleep 4
fi
if [ “${EASY}” = “A” ] && [ -f “${MYCONFIG}” ];then
EASY=”B”
CHECKMYSQL=”ZZX”
fi
if [ “${MYSQL}” -eq “2” ] && [ -f “${MYCONFIG}” ];then
echo -e -n”\t\t\tContinue Installation PHP[y/n]:”
read PHP2
case ${PHP2} in
y|Y)EASY=”B” && CHECKMYSQL=”Z”
;;
n|N)MYSQL= && continue
;;
esac
fi
MYSQL=
fi
#*************************PHP Partial Installation*******************************
if [ “${PHP}” = “3” ] || [ “${EASY}” = “B” ];then
while [ -d “${PHPDIR}” ]
do
if [ -z “${PHPAGAIN}” ];then
echo “PHP Directory already exists”
fi
echo -n “Do you reinstall {y/n}:”
read REINSTALL
case “${REINSTALL}” in
n|N)PHPDIR=
;;
y|Y)rm -rf ${PHPDIR}
;;
*)echo “Input error, please try again”
PHPAGAIN=AK48
;;
esac
done
ls ${INSTALLDIR} |grep -v “tar.gz”|grep “^php-“|xargs rm -rf
find ${INSTALLDIR} -name php*.tar.gz |xargs tar -zxvf && cd php-*
chmod 700 ${INSTALLDIR}/phpconfig
if ${INSTALLDIR}/phpconfig;then
make -j5 && make install
cd ${INSTALLDIR}
cp -a ${INSTALLDIR}/php.ini ${PHPDIR}/lib/
fi
if [ -f “${PHPDIR}/bin/php-cgi” ];then
echo
echo -e “\t\t\t**********PHP Already Installation Done**********”
echo
fi
if [ “${EASY}” = “B” ] && [ -f “${PHPDIR}”/bin/php-cgi ];then
EASY=”C”
CHECKPHP=”X”
elif [ “${PHP}” -eq “3” ] && [ -f “${PHPDIR}”/bin/php-cgi ];then
echo -e -n “\t\t\tContinue Installation Nginx[y/n]:”
read NGINX3
case “${NGINX3}” in
y|Y)EASY=”C” && CHECKPHP=”X”
;;
n|N)PHP= && continue
;;
esac
fi
PHP=
fi
#*************************NGINX Partial Installation*****************************
if [ “${NGINX}” = “4” -o “${EASY}” = “C” ];then
until [ ! -d “${NGINXDIR}” ]
do
if [ -z “${NGINXGAIN}” ];then
echo “NGINX Directory already exists”
fi
echo -n “Do you reinstall {y/n}:”
read NGINXREINSTALL
case “${NGINXREINSTALL}” in
n|N)NGINXDIR=
;;
y|Y)rm -rf ${NGINXDIR}
;;
*)echo “Input error, please try again”
NGINXGAIN=AK4899
;;
esac
done
ls “${INSTALLDIR}” |grep -v “tar.gz”|grep “nginx-“|xargs rm -rf
ls “${INSTALLDIR}” |grep “tar.gz”|grep “nginx-“|xargs tar -zxvf && cd nginx-*
if “./configure” ;then
make -j5;make install
if [ “$?” = “0” ];then
killall nginx || killall “${NGINXDIR}/sbin/nginx”
killall php-cgi && rm -f ${NGINXDIR}/conf/nginx.conf
mkdir -p ${SHELLDIR} || mkdir ${SHELLDIR}
chmod 700 ${INSTALLDIR}/phpcgi
chmod 700 ${INSTALLDIR}/nginx.sh
mkdir -p ${WWWDIR};cp ${INSTALLDIR}/php.php ${WWWDIR}
cp ${INSTALLDIR}/nginx.conf ${NGINXDIR}/conf
cp -a ${INSTALLDIR}/nginx.sh ${SHELLDIR}
fi
if “${NGINXDIR}”/sbin/nginx || “${SHELLDIR}”/nginx.sh start ;then
cp -a ${INSTALLDIR}/phpcgi ${SHELLDIR} && ${SHELLDIR}/phpcgi
fi
fi
if [ -f “${NGINXDIR}/sbin/nginx” ];then
echo
echo -e “\t\t\t**********NGINX Already Installation Done**********”
echo
echo “${SHELLDIR}/nginx.sh start” >> ${RCLOCAL}
echo “${SHELLDIR}/phpcgi” >> ${RCLOCAL}
if [ “${EASY}” = “C” ] && [ -f “${NGINXDIR}/sbin/nginx” ];then
CHECKNGINX=”Y”
elif [ “$NGINX” -eq “4” ] && [ -f “${NGINXDIR}/sbin/nginx” ];then
CHECKNGINX=”Y”
fi
fi
NGINX=
fi
#***************************Check And Delete File ******************************************
if [ “${CHECKMYSQL}” = “ZZX” ] && [ “${CHECKPHP}” = “X” ] && [ “${CHECKNGINX}” = “Y” ]
then
echo -e “\t\t\t################################################################”
echo -e “\t\t\t#Congratulations, you have all of the installation is complete.#”
echo -e “\t\t\t################################################################”
exit
fi
#***************************Restore Variables*************************************
MYSQLDIR=”${MYSQLSAVED}”
MYSQLDATA=”${MYSQLDATASAVED}”
PHPDIR=”${PHPSAVED}”
NGINXDIR=”${NGINXSAVED}”
EASY=
CHECKMYSQL=
CHECKPHP=
CHECKNGINX=
ls -l ${INSTALLDIR} |grep “^d” |xargs rm -rf
echo -n -e “\t\t\tMainMenu Get Back to contine”
read Menu
done