#!/bin/bash #install dns mail dovecot

read -p "domain name :" domain_name read -p "hostname:" host_name read -p "host ip:" host_ip read -p "Network card path:" eth_path read -p "postfix package path:" ppp read -p "dovecot package path:" dpp

for i in {$eth_path,$dpp,$ppp};do if [ -e $i ];then echo -e "\033[32m $i is at \033[0m" else echo -e "\033[31m $i not at ! \033[0m" exit 1 fi done

if [ -e /dev/sr0 ] ;then echo "make yum repo and mount CD" echo "[a] name=a baseurl=file:///mnt enabled=1 gpgcheck=0 " > /etc/yum.repos.d/a.repo mount /dev/sr0 /mnt else echo "CD not at! exit" exit 1 fi

iptables -F

cat > /etc/sysconfig/network <<EOF NETWORKING=yes HOSTNAME=$host_name EOF

hostname $host_name

for i in {cyrus-sasl-gssapi,cyrus-sasl-devel,cyrus-sasl-plain,cyrus-sasl-lib,cyrus-sasl,make,gcc,gcc-c++,openssl-devel,telnet,pam-devel,bind,bind-chroot};do if rpm -qa | grep $i >> /dev/null ;then echo -e "\033[32m $i installed \033[0m" else yum install -y $i fi done

cat > /etc/named.conf <<EOF options { listen-on port 53 { $host_ip; }; listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt";

};

logging { channel default_debug { file "data/named.run"; severity dynamic; }; };

zone "$domain_name" IN { type master; file "$domain_name.zone"; };

include "/etc/named.rfc1912.zones"; include "/etc/named.root.key"; EOF

echo "$TTL 86400 @ IN SOA $domain_name. adim.$domain_name ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum IN NS mail.$domain_name. IN MX 10 mail.$domain_name. mail IN A $host_ip" > /var/named/$domain_name.zone

#chown named:named: /var/named/

cat $eth_path | grep "DNS1" if [ $? -eq 0 ] ;then sed -i 's/^DNS1.*//g' $eth_path echo "DNS1=$host_ip" >> $eth_path else echo "DNS1=$host_ip" >> $eth_path fi

service network restart

service named restart service network restart sleep 5 echo -e "\033[31m 解析本主机 \033[0m" nslookup $host_name

#################################

echo -e "\033[32m ----install mail ----\033[0m" sleep 3 echo -e "\033[31m stop old mail \033[0m" /etc/init.d/postfix stop chkconfig --level 35 postfix off gpasswd -a postfix postfix gpaaswd -a postfix postdrop

tar xf $ppp -C /usr/src/ cd /usr/src/postfix* make makefiles 'CCARGS=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I /usr/include/sasl/' 'AUXLIBS=-L/usr/lib64/sasl2 -lsasl2'

make && make install

if [ -e /etc/postfix/main.cf ] ;then rm -rf /etc/postfix/main.cf cat > /etc/postfix/main.cf <<EOF alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases command_directory = /usr/sbin daemon_directory = /usr/libexec/postfix data_directory = /var/lib/postfix debug_peer_level = 2 debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5 home_mailbox = Maildir/ html_directory = no inet_interfaces = $host_ip inet_protocols = all mail_owner = postfix mailq_path = /usr/bin/mailq manpage_directory = /usr/local/man meta_directory = /etc/postfix mydestination = $myhostname, $mydomain, mydomain = $domain_name myhostname = $host_name myorigin = $mydomain newaliases_path = /usr/bin/newaliases queue_directory = /var/spool/postfix readme_directory = no sample_directory = /etc/postfix sendmail_path = /usr/sbin/sendmail setgid_group = postdrop shlib_directory = no unknown_local_recipient_reject_code = 550 EOF else cat > /etc/postfix/main.cf <<EOF alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases command_directory = /usr/sbin daemon_directory = /usr/libexec/postfix data_directory = /var/lib/postfix debug_peer_level = 2 debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5 home_mailbox = Maildir/ html_directory = no inet_interfaces = $host_ip inet_protocols = all mail_owner = postfix mailq_path = /usr/bin/mailq manpage_directory = /usr/local/man meta_directory = /etc/postfix mydestination = $myhostname, $mydomain, mydomain = $domain_name myhostname = $host_name myorigin = $mydomain newaliases_path = /usr/bin/newaliases queue_directory = /var/spool/postfix readme_directory = no sample_directory = /etc/postfix sendmail_path = /usr/sbin/sendmail setgid_group = postdrop shlib_directory = no unknown_local_recipient_reject_code = 550 EOF echo -e "\033[31m the main.cf file not at make it \033[0m" fi

service postfix start

echo -e "\033[31m install complete start postfix \033[0m"

####################################################################

echo -e "\033[32m ----install mail ----\033[0m"

echo -e "\033[31m add user \033[0m" sleep 3 useradd -M -s /sbin/nologin dovecot useradd -M -s /sbin/nologin dovenull

tar xf $dpp -C /usr/src/

cd /usr/src/dovecot*

./configure --sysconfdir=/etc/ --with-pam

make && make install

cp doc/dovecot-initd.sh /etc/init.d/dovecot

chmod +x /etc/init.d/dovecot

chkconfig --add dovecot

cp -r /usr/local/share/doc/dovecot/example-config/* /etc/dovecot/

cat > /etc/pam.d/dovecot <<EOF #%PAM-1.0

auth required pam_nologin.so auth include system-auth account include system-auth session include system-auth EOF

mv /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.bak cat > /etc/dovecot/dovecot.conf <<EOF dict { #quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext #expire = sqlite:/etc/dovecot/dovecot-dict-sql.conf.ext } !include conf.d/10-auth.conf ssl = no disable_plaintext_auth = no mail_location = maildir:~/Maildir !include_try local.conf EOF

service dovecot restart