#!/bin/bash
source_file="/dcc_data/nginx-1.10.1.tar.gz"
source_dir="/dcc_data/"
origin_file="/dcc_data/nginx-1.10.1"
log_path="$HOME/mylog/install.log"
if [ ! -d "$HOME/mylog" ];then
mkdir $HOME/mylog
fi
tar -zxf $source_file -C $source_dir
if [ ! $? -eq 0 ];then
echo "tar error"
exit 6
fi
cd $origin_file
rpm -q gcc zlib-devel pcre-devel &>> /dev/null
if [ ! $? -eq 0 ];then
#test yum whether can use?
test01=`yum repolist | grep 'repolist: '|sed -n 's/repolist: //p'`
if [ "$test01" == "0" ];then
echo "error_code:1;the yum.repo can't be used" >> $log_path
echo "Error:yum can not be used"
exit 1
fi
#install gcc
yum -y install gcc >> /dev/null 2>> $log_path
if [ $? -eq 1 ];then
echo "Error:can't install gcc,check log in details"
exit 2
fi
#install zlib-devel
yum -y install zlib-devel >> /dev/null 2>> $log_path
if [ $? -eq 1 ];then
echo "Error:can't install zlib-devel,check log in details"
exit 3
fi
#install pcre-devel
yum -y install pcre-devel >> /dev/null 2>> $log_path
if [ $? -eq 1 ];then
echo "Error:can't install pcre-devel,check log in details"
exit 4
fi
fi
#configure
./configure >> /dev/null 2>> $log_path
if [ ! $? -eq 0 ];then
echo "Error:configure failed,check log in details"
exit 5
fi
#make
make >> /dev/null 2>> $log_path && make install >> /dev/null 2>> $log_path
if [ ! $? -eq 0 ];then
echo "Error:configure failed,check log in details"
exit 5
else
echo "install nginx success"
fi
#check httpd status
systemctl status httpd | grep running >> /dev/null && systemctl stop httpd
#start nginx
start_file="/usr/local/nginx/sbin/nginx"
PID="/usr/local/nginx/logs/nginx.pid"
$start_file
sleep 10
if [ -f $PID ];then
echo "start nginx success"
else
echo "start nginx failed"
fi