Exim/mailserver.sh

79 lines
2.5 KiB
Bash
Raw Normal View History

2016-08-08 17:41:39 +00:00
#!/usr/bin/env bash
2016-08-08 22:41:17 +00:00
RED="\e[91m"
GRE="\e[92m"
YEL="\e[93m"
STD="\e[0m"
2016-08-08 18:43:25 +00:00
2016-08-08 22:23:13 +00:00
[[ $EUID -ne 0 ]] && echo -e "${RED}This script must be run as root.${STD}" && exit 1
2016-08-08 18:43:25 +00:00
2016-08-15 13:38:21 +00:00
install_ask_domain() {
2016-08-08 22:41:17 +00:00
echo -e "${GRE}Please enter the mail server's main domain${STD}"
read choice
2016-10-18 12:45:07 +00:00
[[ -n "$choice" ]] && echo "$choice" > /etc/mailname
[[ -z "$choice" ]] && install_ask_domain
2016-08-15 13:38:21 +00:00
}
2016-08-08 18:43:25 +00:00
install_exim() {
2016-08-15 13:38:21 +00:00
install_ask_domain
2016-08-08 22:23:13 +00:00
echo -e "${YEL}Two boxes will appear. Hit [Enter] each time to continue.${STD}"
2016-08-15 15:18:38 +00:00
read -p "Press [Enter] key to continue..."
2016-09-28 21:23:54 +00:00
aptitude -y install exim4 courier-imap courier-imap-ssl courier-authlib-userdb ssl-cert sudo openssl
2016-10-05 20:42:29 +00:00
mkdir -pv /etc/exim4/domains
mkdir -pv /etc/exim4/forward
2016-08-15 17:55:19 +00:00
cp -fv exim4/exim4.conf /etc/exim4/exim4.conf
2016-10-18 12:45:07 +00:00
sed -i "s/ETC_MAILNAME =/ETC_MAILNAME = $(cat /etc/mailname)/" /etc/exim4/exim4.conf
chmod -fv 777 /var/run/courier/authdaemon
2016-08-15 13:38:21 +00:00
chmod -fv 777 /var/run/courier/authdaemon/socket
2016-08-15 15:18:38 +00:00
/usr/share/doc/exim4-base/examples/exim-gencert
openssl genrsa -out /etc/exim4/dkim.key 2048
openssl dhparam -out /etc/courier/dhparams.pem 2048
2016-08-15 15:18:38 +00:00
install_restart
2016-08-08 18:43:25 +00:00
}
install_spamassassin() {
2016-09-28 21:23:54 +00:00
aptitude -y install exim4-daemon-heavy sa-exim spamassassin pyzor razor
sudo -u debian-spamd pyzor discover
razor-admin -home=/etc/razor -discover
2016-08-15 13:38:21 +00:00
cp -fv spamd/sa-learn /etc/cron.daily/sa-learn
cp -fv spamd/spamassassin /etc/default/spamassassin
2016-10-07 17:38:49 +00:00
[[ -n $(which systemctl) ]] && systemctl enable spamassassin
2016-08-15 16:13:50 +00:00
service spamassassin restart
2016-08-15 15:18:38 +00:00
install_restart
2016-08-08 18:43:25 +00:00
}
install_clamav() {
2016-08-15 13:38:21 +00:00
aptitude -y install exim4-daemon-heavy clamav clamav-daemon
2016-08-15 16:13:50 +00:00
adduser clamav Debian-exim
2016-10-07 17:38:49 +00:00
[[ -n $(which systemctl) ]] && systemctl enable clamav-daemon
2016-08-15 16:13:50 +00:00
service clamav-daemon restart
2016-08-15 15:18:38 +00:00
install_restart
2016-08-15 13:38:21 +00:00
}
install_restart() {
service courier-authdeamon restart
service courier-imap restart
service courier-imap-ssl restart
service exim4 restart
2016-08-08 18:43:25 +00:00
}
install_mailserver() {
echo "Do you want to install extra software ?"
echo "1. None"
echo "2. SpamAssassin (antispam)"
echo "3. ClamAV (antivirus)"
echo "4. Both SpamAssassin and ClamAV"
2016-10-07 09:17:24 +00:00
echo "5. Exit"
read -p "Enter choice [1 - 5] " choice
2016-10-18 12:45:07 +00:00
case "$choice" in
2016-08-15 15:18:38 +00:00
1) install_exim ;;
2) install_exim && install_spamassassin ;;
3) install_exim && install_clamav ;;
4) install_exim && install_spamassassin && install_clamav ;;
2016-10-07 09:17:24 +00:00
5) exit ;;
2016-08-08 18:43:25 +00:00
*) clear && echo -e "${RED}Please enter a valid input${STD}" && install_mailserver ;;
esac
}
2016-10-07 11:26:28 +00:00
clear && install_mailserver