Files
download/pureftpd/install.sh
耗子 758e1c8799
All checks were successful
Generate Checksums / checksums (push) Successful in 46s
feat: 清理提交
2026-01-31 07:03:45 +08:00

124 lines
4.5 KiB
Bash

#!/bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
source <(curl -f -s --connect-timeout 10 --retry 3 https://dl.acepanel.net/public.sh)
if [ $? -ne 0 ]; then
echo "Download public.sh failed, please check the network or try again later."
exit 1
fi
channel=${1}
version=${2}
pureftpd_path="${setup_path}/server/pure-ftpd"
j=$(calculate_j)
# 安装依赖
if [ ${OS} == "rhel" ]; then
dnf makecache -y
dnf groupinstall "Development Tools" -y
dnf install openssl-devel -y
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get update
apt-get install build-essential -y
apt-get install libssl-dev -y
else
error "Unsupported operating system"
fi
if [ "$?" != "0" ]; then
error "Failed to install dependencies"
fi
# 准备安装目录
rm -rf ${pureftpd_path}
mkdir -p ${pureftpd_path}
cd ${pureftpd_path}
dl "${pureftpd_path}" "/pureftpd/pure-ftpd-${version}.tar.gz"
tar -xvf pure-ftpd-${version}.tar.gz
rm -f pure-ftpd-${version}.tar.gz
mv pure-ftpd-${version} src
cd src
chmod +x configure
./configure --prefix=${pureftpd_path} CFLAGS=-O2 --with-puredb --with-quotas --with-cookie --with-virtualhosts --with-diraliases --with-sysquotas --with-ratios --with-altlog --with-paranoidmsg --with-shadow --with-welcomemsg --with-throttling --with-uploadscript --with-language=simplified-chinese --with-rfc2640 --with-ftpwho --with-tls
if [ "$?" != "0" ]; then
rm -rf ${pureftpd_path}
error "Compilation initialization failed"
fi
make "-j${j}"
if [ "$?" != "0" ]; then
rm -rf ${pureftpd_path}
error "Compilation failed"
fi
make install
if [ ! -f "${pureftpd_path}/bin/pure-pw" ]; then
rm -rf ${pureftpd_path}
error "Installation failed"
fi
# 修改 pure-ftpd 配置文件
sed -i "s!# PureDB\s*/etc/pureftpd.pdb!PureDB ${pureftpd_path}/etc/pureftpd.pdb!" ${pureftpd_path}/etc/pure-ftpd.conf
sed -i 's!# ChrootEveryone\s*yes!ChrootEveryone yes!' ${pureftpd_path}/etc/pure-ftpd.conf
sed -i 's!NoAnonymous\s*no!NoAnonymous yes!' ${pureftpd_path}/etc/pure-ftpd.conf
sed -i 's!AnonymousCanCreateDirs\s*yes!AnonymousCanCreateDirs no!' ${pureftpd_path}/etc/pure-ftpd.conf
sed -i 's!AnonymousCantUpload\s*yes!AnonymousCantUpload no!' ${pureftpd_path}/etc/pure-ftpd.conf
sed -i 's!PAMAuthentication\s*yes!PAMAuthentication no!' ${pureftpd_path}/etc/pure-ftpd.conf
sed -i 's!UnixAuthentication\s*yes!UnixAuthentication no!' ${pureftpd_path}/etc/pure-ftpd.conf
sed -i 's!# PassivePortRange\s*30000 50000!PassivePortRange 39000 40000!' ${pureftpd_path}/etc/pure-ftpd.conf
sed -i 's!PassivePortRange\s*30000 50000!PassivePortRange 39000 40000!' ${pureftpd_path}/etc/pure-ftpd.conf
sed -i 's!LimitRecursion\s*10000 8!LimitRecursion 20000 8!' ${pureftpd_path}/etc/pure-ftpd.conf
sed -i 's!# TLS!TLS!' ${pureftpd_path}/etc/pure-ftpd.conf
sed -i "s!# CertFile\s*/etc/ssl/private/pure-ftpd.pem!CertFile ${pureftpd_path}/etc/pure-ftpd.pem!" ${pureftpd_path}/etc/pure-ftpd.conf
sed -i 's!# Bind\s*127.0.0.1,21!Bind 0.0.0.0,21!' ${pureftpd_path}/etc/pure-ftpd.conf
sed -i 's!# Bind\s*0.0.0.0,21!Bind 0.0.0.0,21!' ${pureftpd_path}/etc/pure-ftpd.conf
sed -i "s!# PIDFile\s*/var/run/pure-ftpd.pid!PIDFile ${pureftpd_path}/etc/pure-ftpd.pid!" ${pureftpd_path}/etc/pure-ftpd.conf
touch ${pureftpd_path}/etc/pureftpd.passwd
touch ${pureftpd_path}/etc/pureftpd.pdb
openssl dhparam -out ${pureftpd_path}/etc/pure-ftpd-dhparams.pem 2048
openssl req -x509 -nodes -days 36500 -newkey rsa:2048 -sha256 -keyout ${pureftpd_path}/etc/pure-ftpd.pem -out ${pureftpd_path}/etc/pure-ftpd.pem -subj "/C=CN/ST=Tianjin/L=Tianjin/O=Rat Technology Co., Ltd./OU=AcePanel/CN=Panel"
chmod 600 ${pureftpd_path}/etc/*.pem
# 添加系统服务
ln -sf ${pureftpd_path}/bin/pure-pw /usr/local/bin/pure-pw
cat >/etc/systemd/system/pure-ftpd.service <<EOF
[Unit]
Description=Pure-FTPd FTP server
After=syslog.target network.target
[Service]
Type=forking
PIDFile=${pureftpd_path}/etc/pure-ftpd.pid
ExecStart=${pureftpd_path}/sbin/pure-ftpd ${pureftpd_path}/etc/pure-ftpd.conf
ExecStartPost=/bin/sleep 2
ExecStop=/bin/kill -TERM \$MAINPID
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
chmod 644 /etc/systemd/system/pure-ftpd.service
# 添加防火墙规则
firewall-cmd --zone=public --add-port=21/tcp --permanent
firewall-cmd --zone=public --add-port=39000-40000/tcp --permanent
firewall-cmd --reload
systemctl daemon-reload
systemctl enable --now pure-ftpd
if [ "$?" != "0" ]; then
error "Failed to start"
fi
acepanel app write pureftpd ${channel} ${version}
echo -e $HR
echo "Installation successful"
echo -e $HR