shell脚本实现源码LAMP自动化安装

shell脚本实现源码LAMP自动化安装代码如下,写了好久,在CentOS 6.3实践中用过,分享给大家。

运行此脚本的前提有gcc/gcc-c++的编译环境,此脚本用到一些源码包(apr-1.2.7,apr-util-1.2.7,autoconf-2.59,cmake-2.6.4,curl-7.15.1,freetds-2.2.2,gd-2.0.33,httpd-2.2.31,jpegsrc-v7,libmcrypt-2.5.7,libpng-1.2.10,libxml2-2.6.26,MySQL-5.0.77,openssh-4.3p2,pcre-6.6,php-5.3.29,zlib-1.2.3),需要自行下载,这些包放在脚本同级目录下的Centos.pkg目录下。

#!/bin/sh
#################################
##LAMP AUTOMATIC SOURCE INSTALL##
#################################

##Check the user(root)##
[ $ID -ne 0 ] && echo "The script must root can run ! " && echo  "Please switch user to root ! " && exit 1

##1. Platform
echo "**System Information**"
echo "RedHat-release : $(cat /etc/redhat-release)"
echo "hostname : $HOSTNAME"
echo "operating system:$(uname -o)"
echo "kernel version:$(uname -v)"
echo "hardware platform:$(uname -i)"
echo

##2. Environment Variable
IPADDR=$(ifconfig eth0 | awk -F"[: ]+" 'NR==2 {print $4}')
CENTOS_VER=$(cat /etc/redhat-release |awk -F"[ .]+" '{print $3}')
SYSTEM_BIT=$(getconf LONG_BIT)
INSTALL_PATH="/usr/local"
SOURCEPKG_PATH="$PWD/Centos.pkg"
RPM_PAHT="$PWD/rpm"
RPM=$(ls -r $RPM_PATH)
PACKAGE=$(ls -1 $SOURCEPKG_PATH | awk -F"-" '{print $1}')
[ ! -d extract.pkg ] && mkdir extract.pkg
EXTRACT_PATH="$PWD/extract.pkg"

##3. Package
#3.1 Download Rpm Package
# cd $RPM_PATH
# wget
# wget
# wget
# wget
# wget
# wget
# wget ftp://rpmfind.net/linux/centos/5.11/os/i386/CentOS/ncurses-devel-5.5-24.20060715.i386.rpm
# wget ftp://rpmfind.net/linux/centos/5.11/os/x86_64/CentOS/ncurses-devel-5.5-24.20060715.x86_64.rpm
# echo
#3.2 Download Source Package
# cd $SOURCEPKG_PATH
# wget
# wget
# wget
# wget
# wget
# wget
# wget
# wget
# wget
# wget ftp://ftp.simplesystems.org/pub/png/src/libpng15/libpng-1.5.23.tar.gz
# wget
# wget
# wget
# wget
# wget wget

##4. Base Environmet Optimize
/bin/sh $PWD/optimize.sh

##5. Extract Package
echo "Start Extract Package ,Please wait for several minutes ..."
cd $SOURCEPKG_PATH
for i in `ls -1` ;do
    tar xf $i -C $EXTRACT_PATH;
    [ $(echo $?) -ne 0 ] && exit 1
done
echo "Complete Extract Package !"
echo

##6. Install Source Code
#Apache,Mysql,PHP version
echo "Apache_Version=$(ls $SOURCEPKG_PATH/httpd* |awk -F"[-t]+" '{print $5}')"
echo "Mysql_Version=$(ls $SOURCEPKG_PATH/mysql* |awk -F"[-t]+" '{print $4}')"
echo "Php_Version=$(ls $SOURCEPKG_PATH/mysql* |awk -F"[-t]+" '{print $4}')"

echo "Start Install All Source Code , The process will take a long time , When complete will print:"
echo "Please Wait ... !!!"
echo

#6.1 Install gcc
#GCC_VALUE=$(gcc -v >/dev/null 2>&1)
# for i in $(ls -1 /etc/yum.repos.d);do
#    mv $i $i.bak;
#    [ $(echo $?) -ne 0 ] && exit 1
#done
#wget --directory-prefix=/etc/yum.repos.d "$CENTOS_VER"-Base-163.repo
#if [[ $GCC_VALUE -ne 0 ]] ;then
#    echo "Install gcc ..."
#    #Install gcc
#    yum clean all >/dev/null 2>&1
#    yum makecache>/dev/null 2>&1
#    yum install gcc gcc-c++ >/dev/null 2>&1
#    echo "Gcc Install Complete."
#    done
#fi
#6.2 Install libxml2
echo "Install libxml2 ..."
cd $EXTRACT_PATH/libxml2*
./configure --prefix=$INSTALL_PATH/libxml2 >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Libxml2 Install Completed ."
echo

#6.3 Install libmcrypt
echo "Install libmcrypt ..."
cd $EXTRACT_PATH/libmcrypt*
./configure --with-mcrypt-dir=$INSTALL_PATH/libmcrypt > /dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Libcrypt Install Completed."
echo

#6.4 Install libltdl
echo "Install libltdl ..."
cd $EXTRACT_PATH/libmcrypt*/libltdl*
./configure --enable-ltdl-install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Libltdl Install Completed."
echo

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/6cd23d2e6eda1d3e6161491d4814d058.html