#!/bin/bash
URL=https://mirrors.bit.edu.cn/apache//httpd/
FILE=httpd-2.4.46.tar.bz2
PREFIX=`echo $FILE |sed -nr 's@(.*[[:digit:]])\.[[:alpha:]].*@\1@p'`
INSTALL=/apps/httpd24
SUBDIR=`basement /apps/httpd24`
SUFFIX=`echo $FILE |sed -nr 's@.*\.([^.]+$)@\1@p'`
echo -e '\033[1;31m httpd is begin to install \033[0m'
dnf -y install gcc make apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
cd /usr/local/src
wget $URL$FILE
case $SUFFIX in
gz|bz2|xz)
tar xf $FILE
;;
zip)
unzip $FILE
;;
*)
echo '不支持$SUFFIX'
exit 10
esac
cd $PREFIX
./configure --prefix=$INSTALL --sysconfdir=/etc/$SUBDIR --enable-so --enable-ssl
make && make install
echo 'PATH=$INSTALL/bin:$PATH' >/etc/profile.d/$SUBDIR.sh
source /etc/profile.d/$SUBDIR.sh
useradd -r -s /sbin/nologin apache
sed -i -e 's@^User.*@User apache@' -e 's@^Group.*@Group apache@' /etc/$SUBDIR/httpd.conf
sed -ir 's@It works@welcom to magedu@' $INSTALL/htdocs/index.html
apachectl start
echo -e '\033[1;31m httpd is finished \033[0m'