diff --git a/build.sh b/build.sh index a1afef7..63f1265 100644 --- a/build.sh +++ b/build.sh @@ -12,7 +12,7 @@ #apk update #apk add libc-dev ### -echo ">>> Building RustPanel in release mode..." +echo ">>> Building RustPanel in release mode...11" OS=$(uname) case "$OS" in Linux) diff --git a/install/lib.sh b/install/lib.sh new file mode 100644 index 0000000..eca81dc --- /dev/null +++ b/install/lib.sh @@ -0,0 +1,273 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +public_file=/RustPanel/install/public.sh +public_file_Check=$(cat ${public_file} 2>/dev/null) + + +echo ${download_Url} +mkdir -p /RustPanel +run_path="/root" +Is_64bit=`getconf LONG_BIT` + +opensslVersion="1.0.2u" +curlVersion="7.70.0" +freetypeVersion="2.9.1" +pcreVersion="8.42" + +aarch64Check=$(uname -a|grep aarch64) +if [ "${aarch64Check}" ];then + CONFIGURE_BUILD_TYPE="--build=arm-linux" +fi +CONFIGURE_BUILD_TYPE="--build=arm-linux" + +Install_Sendmail() +{ + if [ "${PM}" = "yum" ]; then + yum install postfix mysql-libs -y + if [ "${centos_version}" != '' ];then + systemctl start postfix + systemctl enable postfix + else + service postfix start + chkconfig --level 2345 postfix on + fi + elif [ "${PM}" = "apt-get" ]; then + apt-get install sendmail sendmail-cf -y + fi +} + +Install_Curl() +{ + if [ ! -f "/usr/local/curl/bin/curl" ];then + wget ${download_Url}/src/curl-${curlVersion}.tar.gz + tar -zxf curl-${curlVersion}.tar.gz + cd curl-${curlVersion} + ./configure --prefix=/usr/local/curl --enable-ares --without-nss --with-ssl=/usr/local/openssl --build=arm-linux + make -j${cpuCore} + make install + cd .. + rm -f curl-${curlVersion}.tar.gz + rm -rf curl-${curlVersion} + fi +} + +Install_Openssl() +{ + if [ ! -f "/usr/local/openssl/lib/libssl.so" ];then + cd ${run_path} + wget ${download_Url}/src/openssl-${opensslVersion}.tar.gz + tar -zxf openssl-${opensslVersion}.tar.gz + cd openssl-${opensslVersion} + ./config --openssldir=/usr/local/openssl zlib-dynamic shared + make -j${cpuCore} + make install + echo "/usr/local/openssl/lib" > /etc/ld.so.conf.d/zopenssl.conf + ldconfig + cd .. + rm -f openssl-${opensslVersion}.tar.gz + rm -rf openssl-${opensslVersion} + fi +} +Install_Pcre(){ + Cur_Pcre_Ver=`pcre-config --version|grep '^8.' 2>&1` + if [ "$Cur_Pcre_Ver" == "" ];then + wget -O pcre-${pcreVersion}.tar.gz ${download_Url}/src/pcre-${pcreVersion}.tar.gz -T 5 + tar zxf pcre-${pcreVersion}.tar.gz + rm -f pcre-${pcreVersion}.tar.gz + cd pcre-${pcreVersion} + if [ "$Is_64bit" == "64" ];then + ./configure --prefix=/usr --docdir=/usr/share/doc/pcre-${pcreVersion} --libdir=/usr/lib64 --enable-unicode-properties --enable-pcre16 --enable-pcre32 --enable-pcregrep-libz --enable-pcregrep-libbz2 --enable-pcretest-libreadline --disable-static --enable-utf8 + else + ./configure --prefix=/usr --docdir=/usr/share/doc/pcre-${pcreVersion} --enable-unicode-properties --enable-pcre16 --enable-pcre32 --enable-pcregrep-libz --enable-pcregrep-libbz2 --enable-pcretest-libreadline --disable-static --enable-utf8 + fi + make -j${cpuCore} + make install + cd .. + rm -rf pcre-${pcreVersion} + fi +} +Install_Freetype() +{ + if [ ! -f "/usr/bin/freetype-config" ] && [ ! -f "/usr/local/freetype/bin/freetype-config" ]; then + cd ${run_path} + wget -O freetype-${freetypeVersion}.tar.gz ${download_Url}/src/freetype-${freetypeVersion}.tar.gz -T 5 + tar zxf freetype-${freetypeVersion}.tar.gz + cd freetype-${freetypeVersion} + ./configure --prefix=/usr/local/freetype --enable-freetype-config --build=arm-linux + make -j${cpuCore} + make install + cd ../ + rm -rf freetype-${freetypeVersion} + rm -f freetype-${freetypeVersion}.tar.gz + fi +} +Install_Libiconv() +{ + if [ -d '/usr/local/libiconv' ];then + return + fi + cd ${run_path} + if [ ! -f "libiconv-1.14.tar.gz" ];then + wget -O libiconv-1.14.tar.gz ${download_Url}/src/libiconv-1.14.tar.gz -T 5 + fi + mkdir /patch + wget -O /patch/libiconv-glibc-2.16.patch ${download_Url}/src/patch/libiconv-glibc-2.16.patch -T 5 + tar zxf libiconv-1.14.tar.gz + cd libiconv-1.14 + patch -p0 < /patch/libiconv-glibc-2.16.patch + ./configure --prefix=/usr/local/libiconv --enable-static $CONFIGURE_BUILD_TYPE + make -j${cpuCore} + make install + cd ${run_path} + rm -rf libiconv-1.14 + rm -f libiconv-1.14.tar.gz + echo -e "Install_Libiconv" >> /RustPanel/lib.pl +} +Install_Libmcrypt() +{ + if [ -f '/usr/local/lib/libmcrypt.so' ];then + return; + fi + cd ${run_path} + if [ ! -f "libmcrypt-2.5.8.tar.gz" ];then + wget -O libmcrypt-2.5.8.tar.gz ${download_Url}/src/libmcrypt-2.5.8.tar.gz -T 5 + fi + tar zxf libmcrypt-2.5.8.tar.gz + cd libmcrypt-2.5.8 + + ./configure $CONFIGURE_BUILD_TYPE + make -j${cpuCore} + make install + /sbin/ldconfig + cd libltdl/ + ./configure --enable-ltdl-install + make && make install + ln -sf /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la + ln -sf /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so + ln -sf /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 + ln -sf /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 + ldconfig + cd ${run_path} + rm -rf libmcrypt-2.5.8 + rm -f libmcrypt-2.5.8.tar.gz + echo -e "Install_Libmcrypt" >> /RustPanel/lib.pl +} +Install_Mcrypt() +{ + if [ -f '/usr/bin/mcrypt' ] || [ -f '/usr/local/bin/mcrypt' ];then + return; + fi + cd ${run_path} + if [ ! -f "mcrypt-2.6.8.tar.gz" ];then + wget -O mcrypt-2.6.8.tar.gz ${download_Url}/src/mcrypt-2.6.8.tar.gz -T 5 + fi + tar zxf mcrypt-2.6.8.tar.gz + cd mcrypt-2.6.8 + ./configure $CONFIGURE_BUILD_TYPE + make -j${cpuCore} + make install + cd ${run_path} + rm -rf mcrypt-2.6.8 + rm -f mcrypt-2.6.8.tar.gz + echo -e "Install_Mcrypt" >> /RustPanel/lib.pl +} +Install_Mhash() +{ + if [ -f '/usr/local/lib/libmhash.so' ];then + return; + fi + cd ${run_path} + if [ ! -f "mhash-0.9.9.9.tar.gz" ];then + wget -O mhash-0.9.9.9.tar.gz ${download_Url}/src/mhash-0.9.9.9.tar.gz -T 5 + fi + tar zxf mhash-0.9.9.9.tar.gz + cd mhash-0.9.9.9 + ./configure $CONFIGURE_BUILD_TYPE + make -j${cpuCore} + make install + ln -sf /usr/local/lib/libmhash.a /usr/lib/libmhash.a + ln -sf /usr/local/lib/libmhash.la /usr/lib/libmhash.la + ln -sf /usr/local/lib/libmhash.so /usr/lib/libmhash.so + ln -sf /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 + ln -sf /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 + ldconfig + cd ${run_path} + rm -rf mhash-0.9.9.9* + echo -e "Install_Mhash" >> /RustPanel/lib.pl +} + +Install_Yumlib(){ + sed -i "s#SELINUX=enforcing#SELINUX=disabled#" /etc/selinux/config + rpm -e --nodeps mariadb-libs-* + Centos8Check=$(cat /etc/redhat-release|grep ' 8.'|grep -i centos) + CentosStream8Check=$(cat /etc/redhat-release|grep -i "Centos Stream"|grep 8) + if [ "${Centos8Check}" ] || [ "${CentosStream8Check}" ];then + yum config-manager --set-enabled PowerTools + yum config-manager --set-enabled powertools + fi + mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup + rm -f /var/run/yum.pid + Packs="make cmake gcc gcc-c++ flex bison file libtool libtool-libs autoconf kernel-devel patch wget libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel tar bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal gettext gettext-devel gmp-devel pspell-devel libcap diffutils ca-certificates net-tools libc-client-devel psmisc libXpm-devel c-ares-devel libicu-devel libxslt libxslt-devel zip unzip glibc.i686 libstdc++.so.6 cairo-devel bison-devel libaio-devel perl perl-devel perl-Data-Dumper lsof pcre pcre-devel vixie-cron crontabs expat-devel readline-devel oniguruma-devel libwebp-devel libvpx-devel" + yum install ${Packs} -y + for yumPack in ${Packs}; + do + rpmPack=$(rpm -q ${yumPack}) + packCheck=$(echo $rpmPack|grep not) + if [ "${packCheck}" ]; then + yum install ${yumPack} -y + fi + done + mv /etc/yum.repos.d/epel.repo.backup /etc/yum.repos.d/epel.repo + + ALI_OS=$(cat /etc/redhat-release |grep "Alibaba Cloud Linux release 3") + if [ -z "${ALI_OS}" ];then + yum install epel-release -y + fi + + echo "true" > /etc/bt_lib.lock +} +Install_Aptlib(){ + #apt-get autoremove -y + apt-get -fy install + export DEBIAN_FRONTEND=noninteractive + apt-get install -y build-essential gcc g++ make + + for aptPack in debian-keyring debian-archive-keyring build-essential gcc g++ make cmake autoconf automake re2c wget cron bzip2 libzip-dev libc6-dev bison file rcconf flex vim bison m4 gawk less cpp binutils diffutils unzip tar bzip2 libbz2-dev libncurses5 libncurses5-dev libtool libevent-dev openssl libssl-dev zlibc libsasl2-dev libltdl3-dev libltdl-dev zlib1g zlib1g-dev libbz2-1.0 libbz2-dev libglib2.0-0 libglib2.0-dev libpng3 libjpeg62 libjpeg62-dev libpng12-0 libpng12-dev libkrb5-dev libpq-dev libpq5 gettext libpng12-dev libxml2-dev libcap-dev ca-certificates libc-client2007e-dev psmisc patch git libc-ares-dev libicu-dev e2fsprogs libxslt-dev libc-client-dev xz-utils libgd3 libgd-dev libwebp-dev libvpx-dev; + do apt-get -y install $aptPack --force-yes; done + + ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so.8 /usr/lib/libjpeg.so + ln -s /usr/lib/x86_64-linux-gnu/libjpeg.a /usr/lib/libjpeg.a + ln -s /usr/lib/x86_64-linux-gnu/libpng12.so.0 /usr/lib/libpng.so + ln -s /usr/lib/x86_64-linux-gnu/libpng.a /usr/lib/libpng.a + echo "true" > /etc/bt_lib.lock +} +Install_Lib() +{ + lockFile="/etc/bt_lib.lock" + if [ -f "${lockFile}" ]; then + return + fi + + if [ "${PM}" = "yum" ]; then + Install_Yumlib + elif [ "${PM}" = "apt-get" ]; then + Install_Aptlib + fi + Install_Sendmail + Run_User="www" + groupadd ${Run_User} + useradd -s /sbin/nologin -g ${Run_User} ${Run_User} + +} + +Install_Lib +Install_Openssl +Install_Pcre +Install_Curl +Install_Mhash +Install_Libmcrypt +Install_Mcrypt +Install_Libiconv +Install_Freetype diff --git a/install/nginx.sh b/install/nginx.sh new file mode 100644 index 0000000..2e9df46 --- /dev/null +++ b/install/nginx.sh @@ -0,0 +1,670 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH +LANG=en_US.UTF-8 + +public_file=/RustPanel/install/public.sh +publicFileMd5=$(md5sum ${public_file} 2>/dev/null | awk '{print $1}') + +tengine='3.1.0' +nginx_108='1.8.1' +nginx_112='1.12.2' +nginx_114='1.14.2' +nginx_115='1.15.10' +nginx_116='1.16.1' +nginx_117='1.17.10' +nginx_118='1.18.0' +nginx_119='1.19.8' +nginx_120='1.20.2' +nginx_121='1.21.4' +nginx_122='1.22.1' +nginx_123='1.23.4' +nginx_124='1.24.0' +openresty='1.21.4.3' + +Root_Path=$(cat /var/bt_setupPath.conf) +Setup_Path=$Root_Path/server/nginx +run_path="/root" +Is_64bit=$(getconf LONG_BIT) + +ARM_CHECK=$(uname -a | grep -E 'aarch64|arm|ARM') +if [ "$2" == "1.24" ];then + ARM_CHECK="" +fi +LUAJIT_VER="2.0.4" +LUAJIT_INC_PATH="luajit-2.0" + +if [ "${ARM_CHECK}" ]; then + LUAJIT_VER="2.1.0-beta3" + LUAJIT_INC_PATH="luajit-2.1" +fi + +loongarch64Check=$(uname -a | grep loongarch64) +if [ "${loongarch64Check}" ]; then + wget -O nginx.sh ${download_Url}/install/0/loongarch64/nginx.sh && sh nginx.sh $1 $2 + exit +fi + +#HUAWEI_CLOUD_EULER=$(cat /etc/os-release |grep '"Huawei Cloud EulerOS 1') +#EULER_OS=$(cat /etc/os-release |grep "EulerOS 2.0 ") +#if [ "${HUAWEI_CLOUD_EULER}" ] || [ "${EULER_OS}" ];then +# wget -O nginx.sh ${download_Url}/install/1/nginx.sh && sh nginx.sh $1 $2 +# exit +#fi + +if [ -z "${cpuCore}" ]; then + cpuCore="1" +fi + +System_Lib() { + if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then + Pack="gcc gcc-c++ curl curl-devel libtermcap-devel ncurses-devel libevent-devel readline-devel libuuid-devel" + ${PM} install ${Pack} -y + wget -O fix_install.sh $download_Url/tools/fix_install.sh + nohup bash fix_install.sh > /RustPanel/install/fix.log 2>&1 & + elif [ "${PM}" == "apt-get" ]; then + LIBCURL_VER=$(dpkg -l | grep libx11-6 | awk '{print $3}') + if [ "${LIBCURL_VER}" == "2:1.6.9-2ubuntu1.3" ]; then + apt remove libx11* -y + apt install libx11-6 libx11-dev libx11-data -y + fi + Pack="gcc g++ libgd3 libgd-dev libevent-dev libncurses5-dev libreadline-dev uuid-dev" + ${PM} install ${Pack} -y + fi + +} + +Service_Add() { + if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then + chkconfig --add nginx + chkconfig --level 2345 nginx on + elif [ "${PM}" == "apt-get" ]; then + update-rc.d nginx defaults + fi + if [ "$?" == "127" ];then + wget -O /usr/lib/systemd/system/nginx.service ${download_Url}/init/systemd/nginx.service + systemctl enable nginx.service + fi +} +Service_Del() { + if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then + chkconfig --del nginx + chkconfig --level 2345 nginx off + elif [ "${PM}" == "apt-get" ]; then + update-rc.d nginx remove + fi +} +Set_Time() { + BASH_DATE=$(stat nginx.sh | grep Modify | awk '{print $2}' | tr -d '-') + SYS_DATE=$(date +%Y%m%d) + [ "${SYS_DATE}" -lt "${BASH_DATE}" ] && date -s "$(curl https://www.bt.cn//api/index/get_date)" +} +Install_Jemalloc() { + if [ ! -f '/usr/local/lib/libjemalloc.so' ]; then + wget -O jemalloc-5.0.1.tar.bz2 ${download_Url}/src/jemalloc-5.0.1.tar.bz2 + tar -xvf jemalloc-5.0.1.tar.bz2 + cd jemalloc-5.0.1 + ./configure + make && make install + ldconfig + cd .. + rm -rf jemalloc* + fi +} +Install_LuaJIT2(){ + LUAJIT_INC_PATH="luajit-2.1" + wget -c -O luajit2-2.1-20230410.zip ${download_Url}/src/luajit2-2.1-20230410.zip + unzip -o luajit2-2.1-20230410.zip + cd luajit2-2.1-20230410 + make -j${cpuCore} + make install + cd .. + rm -rf luajit2-2.1-20230410* + ln -sf /usr/local/lib/libluajit-5.1.so.2 /usr/local/lib64/libluajit-5.1.so.2 + LD_SO_CHECK=$(cat /etc/ld.so.conf|grep /usr/local/lib) + if [ -z "${LD_SO_CHECK}" ];then + echo "/usr/local/lib" >>/etc/ld.so.conf + fi + ldconfig +} +Install_LuaJIT() { + if [ "${version}" == "1.23" ] || [ "${version}" == "1.24" ] || [ "${version}" == "tengine" ];then + Install_LuaJIT2 + return + fi + OEPN_LUAJIT=$(cat /usr/local/include/luajit-2.1/luajit.h|grep 2022) + if [ ! -f '/usr/local/lib/libluajit-5.1.so' ] || [ ! -f "/usr/local/include/${LUAJIT_INC_PATH}/luajit.h" ] || [ "${OEPN_LUAJIT}" ]; then + wget -c -O LuaJIT-${LUAJIT_VER}.tar.gz ${download_Url}/install/src/LuaJIT-${LUAJIT_VER}.tar.gz -T 10 + tar xvf LuaJIT-${LUAJIT_VER}.tar.gz + cd LuaJIT-${LUAJIT_VER} + make linux + make install + cd .. + rm -rf LuaJIT-* + export LUAJIT_LIB=/usr/local/lib + export LUAJIT_INC=/usr/local/include/${LUAJIT_INC_PATH}/ + ln -sf /usr/local/lib/libluajit-5.1.so.2 /usr/local/lib64/libluajit-5.1.so.2 + LD_SO_CHECK=$(cat /etc/ld.so.conf|grep /usr/local/lib) + if [ -z "${LD_SO_CHECK}" ];then + echo "/usr/local/lib" >>/etc/ld.so.conf + fi + ldconfig + fi +} +Install_cjson() { + if [ ! -f /usr/local/lib/lua/5.1/cjson.so ]; then + wget -O lua-cjson-2.1.0.tar.gz $download_Url/install/src/lua-cjson-2.1.0.tar.gz -T 20 + tar xvf lua-cjson-2.1.0.tar.gz + rm -f lua-cjson-2.1.0.tar.gz + cd lua-cjson-2.1.0 + make + make install + cd .. + rm -rf lua-cjson-2.1.0 + fi +} +Download_Src() { + mkdir -p ${Setup_Path} + cd ${Setup_Path} + rm -rf ${Setup_Path}/src + if [ "${version}" == "tengine" ] || [ "${version}" == "openresty" ]; then + wget -O ${Setup_Path}/src.tar.gz ${download_Url}/src/${version}-${nginxVersion}.tar.gz -T20 + tar -xvf src.tar.gz + mv ${version}-${nginxVersion} src + else + wget -O ${Setup_Path}/src.tar.gz ${download_Url}/src/nginx-${nginxVersion}.tar.gz -T20 + tar -xvf src.tar.gz + tar -xvf src.tar.gz + mv nginx-${nginxVersion} src + fi + + cd src + + if [ -z "${GMSSL}" ]; then + TLSv13_NGINX=$(echo ${nginxVersion} | tr -d '.' | cut -c 1-3) + if [ "${TLSv13_NGINX}" -ge "115" ] && [ "${TLSv13_NGINX}" != "181" ]; then + opensslVer="1.1.1q" + else + opensslVer="1.0.2u" + fi + # if [ "$version" == "1.23" ];then + # opensslVer="3.0.5" + # fi + wget -O openssl.tar.gz ${download_Url}/src/openssl-${opensslVer}.tar.gz + tar -xvf openssl.tar.gz + mv openssl-${opensslVer} openssl + rm -f openssl.tar.gz + else + wget -O GmSSL-master.zip ${download_Url}/src/GmSSL-master.zip + unzip GmSSL-master.zip + mv GmSSL-master openssl + rm -f GmSSL-master.zip + fi + + pcre_version="8.43" + wget -O pcre-$pcre_version.tar.gz ${download_Url}/src/pcre-$pcre_version.tar.gz + tar zxf pcre-$pcre_version.tar.gz + + wget -O ngx_cache_purge.tar.gz ${download_Url}/src/ngx_cache_purge-2.3.tar.gz + tar -zxvf ngx_cache_purge.tar.gz + mv ngx_cache_purge-2.3 ngx_cache_purge + rm -f ngx_cache_purge.tar.gz + + wget -O nginx-sticky-module.zip ${download_Url}/src/nginx-sticky-module.zip + unzip -o nginx-sticky-module.zip + rm -f nginx-sticky-module.zip + + wget -O nginx-http-concat.zip ${download_Url}/src/nginx-http-concat-1.2.2.zip + unzip -o nginx-http-concat.zip + mv nginx-http-concat-1.2.2 nginx-http-concat + rm -f nginx-http-concat.zip + + #lua_nginx_module + LuaModVer="0.10.13" + if [ "${version}" == "1.23" ] || [ "${version}" == "1.24" ] || [ "${version}" == "tengine" ];then + LuaModVer="0.10.24" + fi + wget -c -O lua-nginx-module-${LuaModVer}.zip ${download_Url}/src/lua-nginx-module-${LuaModVer}.zip + unzip -o lua-nginx-module-${LuaModVer}.zip + mv lua-nginx-module-${LuaModVer} lua_nginx_module + rm -f lua-nginx-module-${LuaModVer}.zip + + #ngx_devel_kit + NgxDevelKitVer="0.3.1" + wget -c -O ngx_devel_kit-${NgxDevelKitVer}.zip ${download_Url}/src/ngx_devel_kit-${NgxDevelKitVer}.zip + unzip -o ngx_devel_kit-${NgxDevelKitVer}.zip + mv ngx_devel_kit-${NgxDevelKitVer} ngx_devel_kit + rm -f ngx_devel_kit-${NgxDevelKitVer}.zip + + #nginx-dav-ext-module + NgxDavVer="3.0.0" + wget -c -O nginx-dav-ext-module-${NgxDavVer}.tar.gz ${download_Url}/src/nginx-dav-ext-module-${NgxDavVer}.tar.gz + tar -xvf nginx-dav-ext-module-${NgxDavVer}.tar.gz + mv nginx-dav-ext-module-${NgxDavVer} nginx-dav-ext-module + rm -f nginx-dav-ext-module-${NgxDavVer}.tar.gz + + wget -c -O ngx_http_substitutions_filter_module-master.zip ${download_Url}/src/ngx_http_substitutions_filter_module-master.zip + unzip -o ngx_http_substitutions_filter_module-master.zip + rm -f ngx_http_substitutions_filter_module-master.zip + + + if [ "${Is_64bit}" = "64" ]; then + if [ "${version}" == "1.15" ] || [ "${version}" == "1.17" ] || [ "${version}" == "tengine" ]; then + NGX_PAGESPEED_VAR="1.13.35.2" + wget -O ngx-pagespeed-${NGX_PAGESPEED_VAR}.tar.gz ${download_Url}/src/ngx-pagespeed-${NGX_PAGESPEED_VAR}.tar.gz + tar -xvf ngx-pagespeed-${NGX_PAGESPEED_VAR}.tar.gz + mv ngx-pagespeed-${NGX_PAGESPEED_VAR} ngx-pagespeed + rm -f ngx-pagespeed-${NGX_PAGESPEED_VAR}.tar.gz + fi + fi +} +Install_Configure() { + Run_User="www" + wwwUser=$(cat /etc/passwd | grep www) + if [ "${wwwUser}" == "" ]; then + groupadd ${Run_User} + useradd -s /sbin/nologin -g ${Run_User} ${Run_User} + fi + + [ -f "/RustPanel/install/nginx_prepare.sh" ] && . /RustPanel/install/nginx_prepare.sh + [ -f "/RustPanel/install/nginx_configure.pl" ] && ADD_EXTENSION=$(cat /RustPanel/install/nginx_configure.pl) + if [ -f "/usr/local/lib/libjemalloc.so" ] && [ -z "${ARM_CHECK}" ]; then + jemallocLD="--with-ld-opt="-ljemalloc"" + fi + + if [ "${version}" == "1.8" ]; then + ENABLE_HTTP2="--with-http_spdy_module" + else + ENABLE_HTTP2="--with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module" + fi + + WebDav_NGINX=$(echo ${nginxVersion} | tr -d '.' | cut -c 1-3) + if [ "${WebDav_NGINX}" -ge "114" ] && [ "${WebDav_NGINX}" != "181" ]; then + ENABLE_WEBDAV="--with-http_dav_module --add-module=${Setup_Path}/src/nginx-dav-ext-module" + fi + + if [ "${version}" == "openresty" ]; then + ENABLE_LUA="--with-luajit" + elif [ -z "${ARM_CHECK}" ] && [ -f "/usr/local/include/${LUAJIT_INC_PATH}/luajit.h" ]; then + ENABLE_LUA="--add-module=${Setup_Path}/src/ngx_devel_kit --add-module=${Setup_Path}/src/lua_nginx_module" + fi + + ENABLE_STICKY="--add-module=${Setup_Path}/src/nginx-sticky-module" + if [ "$version" == "1.23" ] || [ "$version" == "1.24" ] || [ "${version}" == "tengine" ];then + ENABLE_STICKY="" + fi + + name=nginx + i_path=/RustPanel/install/$name + + i_args=$(cat $i_path/config.pl | xargs) + i_make_args="" + for i_name in $i_args; do + init_file=$i_path/$i_name/init.sh + if [ -f $init_file ]; then + bash $init_file + fi + + args_file=$i_path/$i_name/args.pl + if [ -f $args_file ]; then + args_string=$(cat $args_file) + i_make_args="$i_make_args $args_string" + fi + done + + cd ${Setup_Path}/src + + # if [ "${GMSSL}" ];then + # sed -i "s/$OPENSSL\/.openssl\//$OPENSSL\//g" auto/lib/openssl/conf + # fi + + export LUAJIT_LIB=/usr/local/lib + export LUAJIT_INC=/usr/local/include/${LUAJIT_INC_PATH}/ + export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH + + ./configure --user=www --group=www --prefix=${Setup_Path} ${ENABLE_LUA} --add-module=${Setup_Path}/src/ngx_cache_purge ${ENABLE_STICKY} --with-openssl=${Setup_Path}/src/openssl --with-pcre=pcre-${pcre_version} ${ENABLE_HTTP2} --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --add-module=${Setup_Path}/src/ngx_http_substitutions_filter_module-master --with-ld-opt="-Wl,-E" --with-cc-opt="-Wno-error" ${jemallocLD} ${ENABLE_WEBDAV} ${ENABLE_NGX_PAGESPEED} ${ADD_EXTENSION} ${i_make_args} + make -j${cpuCore} +} +Install_Nginx() { + make install + if [ "${version}" == "openresty" ]; then + ln -sf /www/server/nginx/nginx/html /www/server/nginx/html + ln -sf /www/server/nginx/nginx/conf /www/server/nginx/conf + ln -sf /www/server/nginx/nginx/logs /www/server/nginx/logs + ln -sf /www/server/nginx/nginx/sbin /www/server/nginx/sbin + if [ -d "/www/server/btwaf" ]; then + ln -s /www/server/nginx/lualib/resty /www/server/btwaf + fi + fi + + if [ ! -f "${Setup_Path}/sbin/nginx" ]; then + echo '========================================================' + GetSysInfo + echo -e "ERROR: nginx-${nginxVersion} installation failed." + if [ -z "${SYS_VERSION}" ];then + echo -e "============================================" + echo -e "检测到为非常用系统安装,请尝试安装其他Mysql版本看是否正常" + echo -e "如无法正常安装,建议更换至Centos-7或Debian-10+或Ubuntu-20+系统安装宝塔面板" + echo -e "详情请查看系统兼容表:https://docs.qq.com/sheet/DUm54VUtyTVNlc21H?tab=BB08J2" + echo -e "特殊情况可通过以下联系方式寻求安装协助情况" + echo -e "============================================" + fi + Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos') + if [ "${Centos8Check}" ];then + echo -e "Centos8官方已经停止支持" + echo -e "如是新安装系统服务器建议更换至Centos-7/Debian-11/Ubuntu-22系统安装宝塔面板" + fi + echo -e "安装失败,请截图以上报错信息发帖至论坛www.bt.cn/bbs求助" + echo -e "或手机访问以下链接、扫码联系企业微信技术求助" + echo -e "帖子或企业微信注明企业版用户,将获得极速响应技术支持" + echo -e "============================================" + echo -e "联系链接:https://work.weixin.qq.com/kfid/kfc9072f0e29a53bd52" + echo -e "============================================" + rm -rf ${Setup_Path} + exit 1 + fi + + if [ "${version}" == "1.23" ] || [ "${version}" == "1.24" ] || [ "${version}" == "tengine" ];then + wget -c -O lua-resty-core-0.1.26.zip ${download_Url}/src/lua-resty-core-0.1.26.zip + unzip lua-resty-core-0.1.26.zip + cd lua-resty-core-0.1.26 + make install PREFIX=/www/server/nginx + cd .. + rm -rf lua-resty-core-0.1.26* + + wget -c -O lua-resty-lrucache-0.13.zip ${download_Url}/src/lua-resty-lrucache-0.13.zip + unzip lua-resty-lrucache-0.13.zip + cd lua-resty-lrucache-0.13 + make install PREFIX=/www/server/nginx + cd .. + rm -rf lua-resty-core-0.1.26* + + fi + + \cp -rpa ${Setup_Path}/sbin/nginx /www/backup/nginxBak + chmod -x /www/backup/nginxBak + md5sum ${Setup_Path}/sbin/nginx > /RustPanel/data/nginx_md5.pl + ln -sf ${Setup_Path}/sbin/nginx /usr/bin/nginx + rm -f ${Setup_Path}/conf/nginx.conf + + cd ${Setup_Path} + rm -f src.tar.gz +} +Update_Nginx() { + if [ "${nginxVersion}" = "openresty" ]; then + make install + echo -e "done" + nginx -v + echo "${nginxVersion}" >${Setup_Path}/version.pl + rm -f ${Setup_Path}/version_check.pl + exit + fi + if [ ! -f ${Setup_Path}/src/objs/nginx ]; then + echo '========================================================' + GetSysInfo + echo -e "ERROR: nginx-${nginxVersion} installation failed." + echo -e "升级失败,请截图以上报错信息发帖至论坛www.bt.cn/bbs求助" + exit 1 + fi + sleep 1 + /etc/init.d/nginx stop + mv -f ${Setup_Path}/sbin/nginx ${Setup_Path}/sbin/nginxBak + \cp -rfp ${Setup_Path}/src/objs/nginx ${Setup_Path}/sbin/ + sleep 1 + /etc/init.d/nginx start + rm -rf ${Setup_Path}/src + nginx -v + + echo "${nginxVersion}" >${Setup_Path}/version.pl + rm -f ${Setup_Path}/version_check.pl + if [ "${version}" == "tengine" ]; then + echo "2.2.4(${tengine})" >${Setup_Path}/version_check.pl + fi + exit +} +Set_Conf() { + Default_Website_Dir=$Root_Path'/wwwroot/default' + mkdir -p ${Default_Website_Dir} + mkdir -p ${Root_Path}/wwwlogs + mkdir -p ${Setup_Path}/conf/vhost + mkdir -p /usr/local/nginx/logs + mkdir -p ${Setup_Path}/conf/rewrite + + mkdir -p /www/wwwlogs/load_balancing/tcp + mkdir -p /RustPanel/vhost/nginx/tcp + + wget -O ${Setup_Path}/conf/nginx.conf ${download_Url}/conf/nginx1.conf -T20 + wget -O ${Setup_Path}/conf/pathinfo.conf ${download_Url}/conf/pathinfo.conf -T20 + wget -O ${Setup_Path}/conf/enable-php.conf ${download_Url}/conf/enable-php.conf -T20 + wget -O ${Setup_Path}/html/index.html ${download_Url}/error/index.html -T 5 + + chmod 755 /www/server/nginx/ + chmod 755 /www/server/nginx/html/ + chmod 755 /www/wwwroot/ + chmod 644 /www/server/nginx/html/* + + cat >${Root_Path}/server/panel/vhost/nginx/phpfpm_status.conf </www/server/nginx/conf/enable-php-00.conf + for phpV in 52 53 54 55 56 70 71 72 73 74 75 80 81 82; do + cat >${Setup_Path}/conf/enable-php-${phpV}.conf <>${Root_Path}/server/panel/vhost/nginx/phpfpm_status.conf <>${Root_Path}/server/panel/vhost/nginx/phpfpm_status.conf + + cat >${Setup_Path}/conf/proxy.conf <${Setup_Path}/conf/luawaf.conf </dev/null + if [ ! -d "/RustPanel/vhost/wafconf" ]; then + mv $Setup_Path/waf/wafconf /RustPanel/vhost/wafconf + fi + + sed -i "s#include vhost/\*.conf;#include /RustPanel/vhost/nginx/\*.conf;#" ${Setup_Path}/conf/nginx.conf + sed -i "s#/www/wwwroot/default#/www/server/phpmyadmin#" ${Setup_Path}/conf/nginx.conf + sed -i "/pathinfo/d" ${Setup_Path}/conf/enable-php.conf + sed -i "s/#limit_conn_zone.*/limit_conn_zone \$binary_remote_addr zone=perip:10m;\n\tlimit_conn_zone \$server_name zone=perserver:10m;/" ${Setup_Path}/conf/nginx.conf + sed -i "s/mime.types;/mime.types;\n\t\tinclude proxy.conf;\n/" ${Setup_Path}/conf/nginx.conf + #if [ "${nginx_version}" == "1.12.2" ] || [ "${nginx_version}" == "openresty" ] || [ "${nginx_version}" == "1.14.2" ];then + sed -i "s/mime.types;/mime.types;\n\t\t#include luawaf.conf;\n/" ${Setup_Path}/conf/nginx.conf + #fi + + PHPVersion="" + for phpVer in 52 53 54 55 56 70 71 72 73 74 80; do + if [ -d "/www/server/php/${phpVer}/bin" ]; then + PHPVersion=${phpVer} + fi + done + + if [ "${PHPVersion}" ]; then + \cp -r -a ${Setup_Path}/conf/enable-php-${PHPVersion}.conf ${Setup_Path}/conf/enable-php.conf + fi + + AA_PANEL_CHECK=$(cat /RustPanel/config/config.json | grep "English") + if [ "${AA_PANEL_CHECK}" ]; then + #\cp -rf /RustPanel/data/empty.html /www/server/nginx/html/index.html + wget -O /www/server/nginx/html/index.html ${download_Url}/error/index_en_nginx.html -T 5 + chmod 644 /www/server/nginx/html/index.html + wget -O /RustPanel/vhost/nginx/0.default.conf ${download_Url}/conf/nginx/en.0.default.conf + for phpV in 52 53 54 55 56 70 71 72 73 74 75 80 81; do + wget -O ${Setup_Path}/conf/enable-php-${phpV}-wpfastcgi.conf ${download_Url}/install/wordpress_conf/nginx/enable-php-${phpV}-wpfastcgi.conf + done + fi + + if [ "${version}" == "1.23" ] || [ "${version}" == "1.24" ] || [ "${version}" == "tengine" ];then + if [ -d "/www/server/btwaf" ];then + rm -rf /www/server/btwaf/ngx + rm -rf /www/server/btwaf/resty + \cp -rpa /www/server/nginx/lib/lua/* /www/server/btwaf + else + sed -i "/lua_package_path/d" /www/server/nginx/conf/nginx.conf + sed -i '/include proxy\.conf;/a \ lua_package_path "/www/server/nginx/lib/lua/?.lua;;";' /www/server/nginx/conf/nginx.conf + fi + fi + + wget -O /etc/init.d/nginx ${download_Url}/init/nginx.init -T 5 + chmod +x /etc/init.d/nginx +} +Set_Version() { + if [ "${version}" == "tengine" ]; then + echo "-Tengine2.2.3" >${Setup_Path}/version.pl + echo "2.2.4(${tengine})" >${Setup_Path}/version_check.pl + elif [ "${version}" == "openresty" ]; then + echo "openresty" >${Setup_Path}/version.pl + echo "openresty-${openresty}" >${Setup_Path}/version_check.pl + else + echo "${nginxVersion}" >${Setup_Path}/version.pl + fi + + if [ "${GMSSL}" ]; then + echo "1.18国密版" >${Setup_Path}/version_check.pl + fi +} + +Uninstall_Nginx() { + if [ -f "/etc/init.d/nginx" ]; then + Service_Del + /etc/init.d/nginx stop + rm -f /etc/init.d/nginx + fi + [ -f "${Setup_Path}/rpm.pl" ] && yum remove bt-$(cat ${Setup_Path}/rpm.pl) -y + [ -f "${Setup_Path}/deb.pl" ] && apt-get remove bt-$(cat ${Setup_Path}/deb.pl) -y + pkill -9 nginx + rm -rf ${Setup_Path} + rm -rf /www/server/btwaf/ngx + rm -rf /www/server/btwaf/resty +} + +actionType=$1 +version=$2 + +if [ "${actionType}" == "uninstall" ]; then + Service_Del + Uninstall_Nginx +else + case "${version}" in + '1.10') + nginxVersion=${nginx_112} + ;; + '1.12') + nginxVersion=${nginx_112} + ;; + '1.14') + nginxVersion=${nginx_114} + ;; + '1.15') + nginxVersion=${nginx_115} + ;; + '1.16') + nginxVersion=${nginx_116} + ;; + '1.17') + nginxVersion=${nginx_117} + ;; + '1.18') + nginxVersion=${nginx_118} + ;; + '1.18.gmssl') + nginxVersion=${nginx_118} + GMSSL="True" + ;; + '1.19') + nginxVersion=${nginx_119} + ;; + '1.20') + nginxVersion=${nginx_120} + ;; + '1.21') + nginxVersion=${nginx_121} + ;; + '1.22') + nginxVersion=${nginx_122} + ;; + '1.23') + nginxVersion=${nginx_123} + ;; + '1.24') + nginxVersion=${nginx_124} + ;; + '1.8') + nginxVersion=${nginx_108} + ;; + 'openresty') + nginxVersion=${openresty} + ;; + *) + nginxVersion=${tengine} + version="tengine" + ;; + esac + if [ "${actionType}" == "install" ]; then + if [ -f "/www/server/nginx/sbin/nginx" ]; then + Uninstall_Nginx + fi + System_Lib + if [ -z "${ARM_CHECK}" ]; then + Install_Jemalloc + Install_LuaJIT + Install_cjson + fi + Download_Src + Install_Configure + Install_Nginx + Set_Conf + Set_Version + Service_Add + /etc/init.d/nginx start + elif [ "${actionType}" == "update" ]; then + Download_Src + Install_Configure + Update_Nginx + fi +fi + diff --git a/src/test/mod.rs b/src/test/mod.rs index ef452ba..afbe50f 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -3,7 +3,7 @@ * @version: * @Author: Wynters * @Date: 2024-05-07 17:41:48 - * @LastEditTime: 2024-07-11 06:34:23 + * @LastEditTime: 2024-10-26 04:57:18 * @FilePath: \RustPanel\src\test\mod.rs */ @@ -18,95 +18,130 @@ use bollard::{ secret::{HostConfig, RestartPolicy, RestartPolicyNameEnum}, }; use lazy_static::lazy_static; +use tokio::io::{AsyncBufReadExt, BufReader}; +use tokio::process::Command; use std::default::Default; +use std::process::Stdio; use std::sync::Mutex; lazy_static! { pub static ref DOCKER: Mutex = Mutex::new(Docker::connect_with_socket_defaults().unwrap()); } -pub async fn demo(_: &DBPool) { - let docker = DOCKER.lock().unwrap(); +pub async fn demo(_: &DBPool)-> Result<(), Box> { + //Test + // 执行的 shell 命令 + let script_path = "./install/lib.sh"; + + // 创建 Command 对象 + let mut cmd = Command::new("sh"); + cmd.arg(script_path); + + // 配置标准输出为管道模式,以便实时获取输出内容 + cmd.stdout(Stdio::piped()); + + // 执行命令 + let mut child = cmd.spawn()?; + + // 读取标准输出的内容 + if let Some(stdout) = child.stdout.take() { + let reader = BufReader::new(stdout).lines(); + tokio::pin!(reader); + while let Some(line) = reader.next_line().await? { + println!("{}", line); // 输出每一行的内容 + } + } - let _ = docker::install(); + // 等待命令执行完毕,并获取执行状态 + let status = child.wait().await?; + if status.success() { + println!("Shell 脚本执行成功"); + } else { + println!("Shell 脚本执行失败: {:?}", status.code()); + } - docker::image::list().await; + Ok(()) + // let docker = DOCKER.lock().unwrap(); - println!("->{:?}", &docker.version().await.unwrap().version.unwrap()); + // let _ = docker::install(); - let networks = &docker - .list_networks(Some(ListNetworksOptions:: { - ..Default::default() - })) - .await - .unwrap(); + // docker::image::list().await; + // println!("->{:?}", &docker.version().await.unwrap().version.unwrap()); - for network in networks { - println!("-> {:?}", network.id.as_deref().unwrap_or("No ID")); - } + // let networks = &docker + // .list_networks(Some(ListNetworksOptions:: { + // ..Default::default() + // })) + // .await + // .unwrap(); - let alpine_config = Config { - image: Some("alpine:3.19.1"), - tty: Some(true), - attach_stdin: Some(true), - attach_stdout: Some(true), - attach_stderr: Some(true), - open_stdin: Some(true), - host_config: Some(HostConfig { - // auto_remove: Some(true), - restart_policy: Some(RestartPolicy { - name: Some(RestartPolicyNameEnum::ALWAYS), - //maximum_retry_count: Some(10), - ..Default::default() - }), - ..Default::default() - }), - ..Default::default() - }; - - let id = match docker - .create_container( - Some(CreateContainerOptions { - name: "test-container-3.19.1", - ..Default::default() - }), - alpine_config, - ) - .await - { - Ok(res) => res.id, - Err(Error::DockerResponseServerError { - status_code, - message, - }) => { - println!( - "Docker responded with status code {}: {}", - status_code, message - ); - return; - } - Err(e) => { - println!("Other error: {:?}", e); - return; - } - }; - match docker.start_container::(&id, None).await { - Ok(_) => println!("-> {:?}", "Started"), - Err(e) => println!("-> {:?}", e), - } + // for network in networks { + // println!("-> {:?}", network.id.as_deref().unwrap_or("No ID")); + // } - let images = &docker - .list_images(Some(ListImagesOptions:: { - all: true, - ..Default::default() - })) - .await - .unwrap(); + // let alpine_config = Config { + // image: Some("alpine:3.19.1"), + // tty: Some(true), + // attach_stdin: Some(true), + // attach_stdout: Some(true), + // attach_stderr: Some(true), + // open_stdin: Some(true), + // host_config: Some(HostConfig { + // // auto_remove: Some(true), + // restart_policy: Some(RestartPolicy { + // name: Some(RestartPolicyNameEnum::ALWAYS), + // //maximum_retry_count: Some(10), + // ..Default::default() + // }), + // ..Default::default() + // }), + // ..Default::default() + // }; + + // let id = match docker + // .create_container( + // Some(CreateContainerOptions { + // name: "test-container-3.19.1", + // ..Default::default() + // }), + // alpine_config, + // ) + // .await + // { + // Ok(res) => res.id, + // Err(Error::DockerResponseServerError { + // status_code, + // message, + // }) => { + // println!( + // "Docker responded with status code {}: {}", + // status_code, message + // ); + // return; + // } + // Err(e) => { + // println!("Other error: {:?}", e); + // return; + // } + // }; - for image in images { - println!("-> {:?}", image.repo_tags[0]); - } + // match docker.start_container::(&id, None).await { + // Ok(_) => println!("-> {:?}", "Started"), + // Err(e) => println!("-> {:?}", e), + // } + + // let images = &docker + // .list_images(Some(ListImagesOptions:: { + // all: true, + // ..Default::default() + // })) + // .await + // .unwrap(); + + // for image in images { + // println!("-> {:?}", image.repo_tags[0]); + // }