pure-ftpd 写一个自动安装脚本shell

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pure-ftpd 写一个自动安装脚本shell相关的知识,希望对你有一定的参考价值。

运行脚本后 输入 yes 就会自动安装

#!/bin/bash
port=`netstat -lnp|grep :21|wc -l`
check_ok()
{
        if [ $? -eq 0 ];then
        echo "check ok"
else
echo "check error " && exit 
        fi
}
read -p "AUto install ftp input ‘yes‘ install on:     "  yes
if [  yes == "$yes" -a $port == 0 ];then
#获取当前ip地址,默认第一个ip地址
ip=`ifconfig|awk -F [:a-Z" "]+ ‘NR==2 {print $2}‘`
lftp="yum install -y lftp"
user=ftptest
pure1=pure-ftpd-1.0.42.tar.bz2
pure=pure-ftpd-1.0.42
URL="http://download.pureftpd.org/pub/pure-ftpd/releases/$pure1 --no-check-certificate"
src=/tmp/ftp
#随机获取5个数字密码
passwd=$((RANDOM))
echo  -e "\033[33m ------------------------------------------------------\033[0m"
echo  -e "\033[33m -                                                    -\033[0m"
echo  -e "\033[33m -                                                    -\033[0m"
echo  -e "\033[33m -                                                    -\033[0m"
echo  -e "\033[33m -                      Auto install FTP              -\033[0m"
echo  -e "\033[33m -                                                    -\033[0m"
echo  -e "\033[33m -                                                    -\033[0m"
echo  -e "\033[33m -                                                    -\033[0m"
echo  -e "\033[33m ------------------------------------------------------\033[0m"
sleep 2
cd /usr/local/src/
rm -rf $pure && rm -rf $pure1
wget $URL
check_ok
tar -jxvf $pure1  && cd $pure
#进行初始化
./configure --prefix=/usr/local/pureftpd --without-inetd --with-altlog --with-puredb --with-throttling --with-peruserlimits  --with-tlsa
check_ok 
make && make install
mkdir -p /usr/local/pureftpd/etc/ && cd configuration-file/
cp pure-ftpd.conf /usr/local/pureftpd/etc/pure-ftpd.conf
cp pure-config.pl  /usr/local/pureftpd/sbin/
chmod 755 /usr/local/pureftpd/sbin/pure-config.pl
check_ok
#清空配置文件 写入新的配置
> /usr/local/pureftpd/etc/pure-ftpd.conf
echo "hrootEveryone              yes
BrokenClientsCompatibility  no
MaxClientsNumber            50
Daemonize                   yes
MaxClientsPerIP             8
VerboseLog                  no
DisplayDotFiles             yes
AnonymousOnly               no
NoAnonymous                 no
SyslogFacility              ftp
DontResolve                 yes
MaxIdleTime                 15
PureDB                      /usr/local/pureftpd/etc/pureftpd.pdb 
#这是一个用户名和密码库
LimitRecursion              3136 8
AnonymousCanCreateDirs      no
MaxLoad                     4
AntiWarez                   yes
Umask                       133:022
MinUID                      100      
#你不能映射uid 小于100 最小100的  限制100
AllowUserFXP                no
AllowAnonymousFXP           no
ProhibitDotFilesWrite       no
ProhibitDotFilesRead        no
AutoRename                  no
AnonymousCantUpload         no
PIDFile                     /usr/local/pureftpd/var/run/pure-ftpd.pid
MaxDiskUsage               99
CustomerProof              yes"  > /usr/local/pureftpd/etc/pure-ftpd.conf
check_ok
mkdir $src
useradd $user -s /sbin/nologin -M
chown -R $user $src
/usr/local/pureftpd/bin/pure-pw useradd ftpuser -u$user -d $src <<EOF
$passwd
$passwd
EOF
check_ok
/usr/local/pureftpd/bin/pure-pw mkdb 
/usr/local/pureftpd/sbin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf 
check_ok
rm -rf /usr/local/src/$pure1
rm -rf /usr/local/src/$pure
$lftp
echo  -e "\033[33m ------------------------------------------------------\033[0m"
echo  -e "\033[33m -                                                    -\033[0m"
echo  -e "\033[33m -                                                    -\033[0m"
echo  -e "\033[33m -                                                    -\033[0m"
echo  -e "\033[5;33m -          Auto install FTP        Yes               -\033[0m"
echo  -e "\033[33m -                                                    -\033[0m"
echo  -e "\033[33m -                                                    -\033[0m"
echo  -e "\033[33m -                                                    -\033[0m"
echo  -e "\033[33m ------------------------------------------------------\033[0m"
sleep 2
echo -e "user:ftpuser passwd:$passwd\nUse: lftp [email protected]$ip\ndir: $src\nAccount and pas
swd to the root dir ftp.txt"
#把账号和密码存入到主目录下,也就是root目录
echo "user:ftpuser2\npasswd:$passwd" > ~/ftp.txt
else
echo "cancel install,check port 21\n exit" &&exit
fi


1. 删除ftp用户命令
[[email protected] configuration-file]#/usr/local/pureftpd/bin/pure-pw userdel ftpuser1  
2. 修改ftp用户密码
[[email protected] ~]# /usr/local/pureftpd/bin/pure-pw passwd ftpuser
[[email protected] ~]# /usr/local/pureftpd/bin/pure-pw mkdb   //执行上面的修改密码后 需要更新一下密码库


安装完后会把账号和密码输入到屏幕上,存到主目录下ftp.txt文件

以上是关于pure-ftpd 写一个自动安装脚本shell的主要内容,如果未能解决你的问题,请参考以下文章

shell写自动安装脚本自动读取license和自动输入回车

Shell 脚本自动安装cobbler(改进+填坑)

shell脚本 自动安装问题

自动安装zabbix客户端shell脚本

Shell脚本自动部署(编译)LAMP平台

开机自动运行 shell脚本 怎么写