Exim/mailserver.sh

85 lines
2.6 KiB
Bash
Raw Normal View History

2016-08-08 17:41:39 +00:00
#!/usr/bin/env bash
2016-08-08 18:43:25 +00:00
usage(){
echo "usage: ./mailserver.sh [help] [install]"
echo "help: show this help"
echo "install: install exim/courier mail server"
}
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
[[ $# -lt 1 ]] && usage
[[ $1 == "help" ]] && usage
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
[[ -n $choice ]] && echo $choice > /etc/mailname
2016-08-15 13:38:21 +00:00
[[ -z $choice ]] && install_ask_domain
}
install_tls_dkim() {
mkdir -pv /etc/exim4/tls
openssl req -x509 -newkey rsa -keyout /etc/exim4/tls/mail.key -out /etc/exim4/tls/mail.crt -days 4096 -nodes
mkdir -pv /etc/exim4/dkim
openssl genrsa -out /etc/exim4/dkim/private.key 2048
2016-08-08 22:41:17 +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}"
echo "Press [Enter] key to continue..."
2016-08-15 13:38:21 +00:00
aptitude -y install exim4 courier-imap courier-imap-ssl courier-pop courier-pop-ssl courier-authlib-userdb ssl-cert
chown -fvR daemon: courier/*
cp -fv courier/* /etc/courier/
2016-08-08 22:23:13 +00:00
chown -vR $USER: courier/*
2016-08-15 13:38:21 +00:00
mkdir -pv /etc/exim.domains
mkdir -pv /etc/exim.forward
cp -fv exim4/* /etc/exim4/
chmod -fv 777 /var/run/courier/authdaemon/socket
install_tls_dkim
2016-08-08 18:43:25 +00:00
}
install_spamassassin() {
2016-08-15 13:38:21 +00:00
aptitude -y install exim4-daemon-heavy sa-exim spamassassin
cp -fv spamd/sa-learn /etc/cron.daily/sa-learn
cp -fv spamd/spamassassin /etc/default/spamassassin
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
}
install_restart() {
service courier-authdeamon restart
service courier-imap restart
service courier-pop restart
service courier-imap-ssl restart
service courier-pop-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"
echo "5. Exit"
read -p "Enter choice [1 - 4] " choice
case $choice in
2016-08-15 13:38:21 +00:00
1) clear && install_exim && install_restart ;;
2) clear && install_exim && install_spamassassin && install_restart ;;
3) clear && install_exim && install_clamav && install_restart ;;
4) clear && install_exim && install_spamassassin && install_clamav && install_restart ;;
2016-08-08 18:43:25 +00:00
5) exit ;;
*) clear && echo -e "${RED}Please enter a valid input${STD}" && install_mailserver ;;
esac
}
clear && [[ $1 == "install" ]] && install_mailserver