#!/bash/bash
# FileName:ProFTP_Install.sh
# Author: Shuhui

VER="1.3.4b"
PREFIX="/usr/local/proftpd"


function proftpd_install() {
	yum -y install openssl-devel wget gcc

	# Download
	if [[ ! -e proftpd-${VER} ]]; then
		wget -c http://down.vqiu.cn/package/tarball/ftp/proftpd-${VER}.tar.gz
	fi
	tar axvf proftpd-${VER}.tar.gz
	cd proftpd-${VER}
	./configure \
	--prefix=${PREFIX}-${VER} \
	--with-module=mod_tls
	make;make install

	mkdir -p ${PREFIX}/var/log

	ln -sv ${PREFIX}-${VER} ${PREFIX}

	chown -R nobody.nobody ${PREFIX}
	cd ${PREFIX}/etc
	if [[ -e proftpd.conf ]]; then
		mv proftpd.conf proftpd.conf.default
	fi
	wget http://down.vqiu.cn/conf/Linux_conf/FTP/proftpd.conf

	echo "export PATH=\$PATH:${PREFIX}/sbin:${PREFIX}/bin" > /etc/profile.d/proftpd.sh
	source /etc/profile.d/proftpd.sh
}

function MSG()
{
	sleep 1
	if [[ -e ${PREFIX}/sbin/proftpd ]]
	then
		echo -en "Good Luck，ProFTPd-${OPENSSL_VER} has been installd successfully.\n"
		echo -en 'Now,You Can Create Groups and Users\n-- Create User Grammar --\n'
		echo "${PREFIX}/bin/ftpasswd --group --name=ftpuser --gid=2000 --member=ftpuser --file=${PREFIX}/etc/group"
		echo "${PREFIX}/bin/ftpasswd --passwd  --name=www --gid=2000  --uid=1001  --home=/data/www --file=${PREFIX}/etc/passwd --shell=/sbin/nologin"
	else
		echo -en "Sorry，ProFTPd-${OPENSSL_VER} has been installd failed.\n"
	fi
}

proftpd_install
MSG
