#!/bin/bash
export LANG=zh_CN.UTF-8
source /etc/profile
filepath='/tools/fail2ban'
fail2bantar='fail2ban-0.11.2.tar.gz'
install_fail2ban_path='/etc/fail2ban'
jail_conf='/etc/fail2ban/jail.conf'
mail_whois_lines_conf='/etc/fail2ban/action.d/mail-whois-lines.conf'
install_fail2ban() {
if [ -d $filepath ];then
cd $filepath
if [ -f $fail2bantar ];then
echo "存在fail2ban压缩文件,继续解压......"
tar zxvf fail2ban-0.11.2.tar.gz
if [ $? -eq 0 ];then
cd $filepath/fail2ban-0.11.2
echo "开始安装......"
python setup.py install
sleep 30
echo "安装完成!"
else
echo "解压缩失败,无法继续,退出!"
exit
fi
else
echo "不存在fail2ban-0.11.2.tar.gz压缩文件,退出!"
exit
fi
else
echo "不存在/tools/fail2ban目录,无法继续,退出!"
exit
fi
}
config_fail2ban() {
if [ $? -eq 0 ];then
if [ -d $install_fail2ban_path ];then
cd $install_fail2ban_path
if [ -f $jail_conf -a -f ${mail_whois_lines_conf} ];then
echo "对jail.conf和mail-whois-lines.conf文件进行重命名操作......"
mv jail.conf jail.conf.bak
mv ${mail_whois_lines_conf} ${mail_whois_lines_conf}.bak
echo "重命名完成!"
echo "拷贝jail.conf和mail-whois-lines.conf文件......"
cp -a $filepath/jail.conf .
cp -a $filepath/mail-whois-lines.conf $install_fail2ban_path/action.d/
echo "拷贝完成!"
echo "fail2ban配置完成!"
else
echo "没有jail.conf和mail-whois-lines.conf文件,不用重命名直接进行拷贝!"
echo "开始拷贝......"
cp -a $filepath/jail.conf .
cp -a $filepath/mail-whois-lines.conf $install_fail2ban_path/action.d/
echo "直接拷贝完成!"
echo "fail2ban配置完成!"
fi
else
echo "没有发现安装完的目录,安装失败,退出!"
exit
fi
else
echo "fail2ban安装没有完成,无法进行配置,退出!"
exit
fi
}
install_fail2ban
config_fail2ban
echo "fail2ban安装和配置全部完成,开始配置启动脚本......"
cp $filepath/fail2ban-0.11.2/files/redhat-initd /etc/init.d/fail2ban
chmod a+x /etc/init.d/fail2ban
echo "启动脚本配置完成!"
echo "正式启动fail2ban应用......"
service fail2ban start
echo "fail2ban启动完成!"