#!/bin/sh
#
# metadata_begin
# recipe: FTP
# tags: unix
# revision: 1
# description_ru:
# description_en:
# metadata_end
#

if [[ -f /etc/redhat-release ]]; then
    # CentOS
    yum install -y vsftpd
    systemctl enable vsftpd
    systemctl start vsftpd
elif [[ -f /etc/lsb-release ]]; then
    # Ubuntu
    apt-get update
    apt-get install -y vsftpd
    systemctl enable vsftpd
    systemctl start vsftpd
else
    echo "Не удалось определить дистрибутив."
    exit 1
fi

# Настройка vsftpd
cat > /etc/vsftpd.conf << EOF
# Основные настройки
listen=NO
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES

# Аутентификация
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

# Пассивный режим
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=40100
pasv_address=<Your_Server_IP_Address>

# Шифрование
ssl_enable=NO
EOF

# Перезапуск vsftpd
if [[ -f /etc/redhat-release ]]; then
    # CentOS
    systemctl restart vsftpd
elif [[ -f /etc/lsb-release ]]; then
    # Ubuntu
    systemctl restart vsftpd
fi
