#!/bin/bash
yum install pcre-devel -y
ls_rootpath=$(cd $(dirname $0);pwd)
#wget https://www.lighttpd.net/2020/1/31/1.4.55/
#apt install libpcre3-dev libpcre3
#the private envirmonet can get form the dir dependency 
ls_arch=`uname -m`
if [[ ${ls_arch} =~ "x86" ]];then
   tar xzvf ${ls_rootpath}/automake-1.16.1.tar.gz -C ${ls_rootpath}
   cd ${ls_rootpath}/automake-1.16.1
   ./configure && make && make install
   cd ../
fi
if [[ -d ${ls_rootpath}/lighttpd-1.4.55 ]];then
   rm -rf ${ls_rootpath}/lighttpd-1.4.55
fi
tar xzvf ${ls_rootpath}/lighttpd-1.4.55.tar.gz -C ${ls_rootpath}
cd ${ls_rootpath}/lighttpd-1.4.55
./configure --prefix=/etc/lighttpd
make && make install
cp -r doc/* /etc/lighttpd
mkdir -p /etc/lighttpd/conf.d
mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.confbk
mv /etc/lighttpd/modules.conf /etc/lighttpd/modules.confbk
mv /etc/lighttpd/conf.d/cgi.conf /etc/lighttpd/conf.d/cgi.confbk
cp ${ls_rootpath}/lighttpd.conf /etc/lighttpd/lighttpd.conf
cp ${ls_rootpath}/modules.conf /etc/lighttpd/modules.conf
cp ${ls_rootpath}/cgi.conf /etc/lighttpd/conf.d
#mkdir -p /etc/lighttpd/root/cgi-bin
mkdir -p /etc/lighttpd/root/htdocs/cgi-bin
mkdir -p /etc/lighttpd/vhosts
mkdir -p /etc/lighttpd/conf.d
mkdir /var/log/lighttpd
touch /var/log/lighttpd/error.log
cp -a ${ls_rootpath}/lighttpd-1.4.55/doc/config/conf.d/* /etc/lighttpd/conf.d
#cp -a ${ls_rootpath}/lighttpd-1.4.55/doc/config/vhosts.d/* /etc/lighttpd/vhosts.d
cp -a ${ls_rootpath}/cgi-bin/* /etc/lighttpd/root/htdocs/cgi-bin/
cp ${ls_rootpath}/lighttpd.service /usr/lib/systemd/system/lighttpd.service
cp ${ls_rootpath}/lighttpd-1.4.55/src/lighttpd /etc/lighttpd/
systemctl daemon-reload
systemctl enable lighttpd
systemctl start lighttpd
#./lighttpd -f ../lighttpd.conf

