pureftpd.sh 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_PureFTPd() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. id -g ${run_group} >/dev/null 2>&1
  13. [ $? -ne 0 ] && groupadd ${run_group}
  14. id -u ${run_user} >/dev/null 2>&1
  15. [ $? -ne 0 ] && useradd -g ${run_group} -M -s /sbin/nologin ${run_user}
  16. tar xzf pure-ftpd-${pureftpd_ver}.tar.gz
  17. pushd pure-ftpd-${pureftpd_ver} > /dev/null
  18. [ ! -d "${pureftpd_install_dir}" ] && mkdir -p ${pureftpd_install_dir}
  19. ./configure --prefix=${pureftpd_install_dir} CFLAGS=-O2 --with-puredb --with-quotas --with-cookie --with-virtualhosts --with-virtualchroot --with-diraliases --with-sysquotas --with-ratios --with-altlog --with-paranoidmsg --with-shadow --with-welcomemsg --with-throttling --with-uploadscript --with-language=english --with-tls
  20. make -j ${THREAD} && make install
  21. popd > /dev/null
  22. if [ -e "${pureftpd_install_dir}/sbin/pure-ftpwho" ]; then
  23. /bin/cp ../init.d/pureftpd.service /lib/systemd/system/
  24. sed -i "s@/usr/local/pureftpd@${pureftpd_install_dir}@g" /lib/systemd/system/pureftpd.service
  25. systemctl enable pureftpd
  26. [ ! -e "${pureftpd_install_dir}/etc" ] && mkdir ${pureftpd_install_dir}/etc
  27. /bin/cp ../config/pure-ftpd.conf ${pureftpd_install_dir}/etc
  28. sed -i "s@^PureDB.*@PureDB ${pureftpd_install_dir}/etc/pureftpd.pdb@" ${pureftpd_install_dir}/etc/pure-ftpd.conf
  29. sed -i "s@^LimitRecursion.*@LimitRecursion 65535 8@" ${pureftpd_install_dir}/etc/pure-ftpd.conf
  30. IPADDR=${IPADDR:-127.0.0.1}
  31. [ ! -d /etc/ssl/private ] && mkdir -p /etc/ssl/private
  32. openssl dhparam -out /etc/ssl/private/pure-ftpd-dhparams.pem 2048
  33. openssl req -x509 -days 7300 -sha256 -nodes -subj "/C=CN/ST=Shanghai/L=Shanghai/O=OneinStack/CN=${IPADDR}" -newkey rsa:2048 -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem
  34. chmod 600 /etc/ssl/private/pure-ftpd*.pem
  35. sed -i "s@^# TLS.*@&\nCertFile /etc/ssl/private/pure-ftpd.pem@" ${pureftpd_install_dir}/etc/pure-ftpd.conf
  36. sed -i "s@^# TLS.*@&\nTLSCipherSuite HIGH:MEDIUM:+TLSv1:\!SSLv2:\!SSLv3@" ${pureftpd_install_dir}/etc/pure-ftpd.conf
  37. sed -i "s@^# TLS.*@TLS 1@" ${pureftpd_install_dir}/etc/pure-ftpd.conf
  38. ulimit -s unlimited
  39. systemctl start pureftpd
  40. # Firewall Ftp
  41. if [ "${PM}" == 'yum' ]; then
  42. if [ "`firewall-cmd --state`" == "running" ]; then
  43. firewall-cmd --permanent --zone=public --add-port={21/tcp,20000-30000/tcp}
  44. firewall-cmd --reload
  45. fi
  46. elif [ "${PM}" == 'apt-get' ]; then
  47. if ufw status | grep -wq active; then
  48. ufw allow 21/tcp
  49. ufw allow 20000:30000/tcp
  50. fi
  51. fi
  52. echo "${CSUCCESS}Pure-Ftp installed successfully! ${CEND}"
  53. rm -rf pure-ftpd-${pureftpd_ver}
  54. else
  55. rm -rf ${pureftpd_install_dir}
  56. echo "${CFAILURE}Pure-Ftpd install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  57. kill -9 $$; exit 1;
  58. fi
  59. popd > /dev/null
  60. }