编写安装配置mail服务脚本

编写安装配置mail服务脚本

【要求】:

自动完成安装postfix(根据提示输入主机名、域名并确定安装路径)、dovecot、squirrelmail,基本配置

【提示】:

此脚本是在lamp环境安装完成的前提下继续的操作(apache安装路径为/usr/local/apache/,可通过修改脚本起始位置httpd_dir变量值以替换成其他路径)


#!/bin/bash

httpd_dir="/usr/local/apache"

ls /etc/postfix &> /dev/null

if [ $? -ne 0 ]; then

yum -y install db*-devel cyrus-sasl-*

service sendmail stop &> /dev/null

chkconfig --level 35 sendmail off


grep postfix /etc/passwd &> /dev/null

if [ $? -ne 0 ];then

groupadd -g 1200 postdrop

groupadd -g 1000 postfix

useradd -M -u 1000 -g postfix -G postdrop -s /sbin/nologin postfix

fi


postfixball=`ls /usr/src/postfix*.gz`

tar zxf $postfixball -C /usr/src

dir=`ls -l /usr/src | grep ^d | grep postfix | awk '{print $7}'`

cd /usr/src/$dir

make makefiles 'CCARGS=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl' 'AUXLIBS=-L/usr/lib/sasl2 -lsasl2' && make && make install

cd /etc/postfix

postconf -n > tmp.file

mv /etc/postfix/main.cf /etc/postfix/main.cf.bak

mv tmp.file /etc/postfix/main.cf

ip=`ifconfig eth0 | grep "inet addr:" | awk '{print $2}' | awk -F: '{print $2}'`

read -p "myhostname of fqdn:" myhostname

read -p "mydomain of mail:" mydomain

echo "inet_interfaces=$ip,127.0.0.1

myhostname=$myhostname

mydomain=$mydomain

myorigin=$mydomain

mydestination=$mydomain,$myhostname

home_mailbox=Maildir/">> /etc/postfix/main.cf

postfix start

fi


ls /etc/dovecot &> /dev/null

if [ $? -ne 0 ]; then

yum -y install pam-devel

grep dovecot /etc/passwd &> /dev/null

if [ $? -ne 0 ]; then

useradd -M -s /sbin/nologin dovecot

useradd -M -s /sbin/nologin dovenull

fi

dovecotball=`ls /usr/src/dovecot*.gz`

tar zxf $dovecotball -C /usr/src/

dir=`ls -l /usr/src/ | grep ^d | grep dovecot |awk '{print $7}'`

cd /usr/src/$dir

./configure --sysconfdir=/etc && make && make install

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

chmod +x /etc/init.d/dovecot

chkconfig --add dovecot

chkconfig dovecot on

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


echo "#%PAM-1.0

auth required pam_nologin.so

auth include system-auth

account include system-auth

session include system-auth"> /etc/pam.d/dovecot


sed -i 's_include conf.d/\*.conf_include conf.d/10-auth.conf_' /etc/dovecot/dovecot.conf


echo "ssl=no

disable_plaintext_auth=no

mail_location=maildir:~/Maildir" >> /etc/dovecot/dovecot.conf

service dovecot start

fi


if [ ! -f /usr/lib/sasl2/smtpd.conf ]; then

echo "pwcheck_method: saslauthd" >/usr/lib/sasl2/smtpd.conf

service saslauthd start &> /dev/null

chkconfig --level 35 saslauthd on

echo "smtpd_sasl_auth_enable=yes

smtpd_sasl_security_options=noanonymous

mynetworks=127.0.0.1

smtpd_recipient_restrictions=

permit_mynetworks,

permit_sasl_authenticated,

reject_unauth_destination">> /etc/postfix/main.cf

postfix reload

fi

if [ ! -d $httpd_dir/htdocs/webmail ]; then

squirrelball=`ls /usr/src/squirrel*.gz`

tar zxf $squirrelball -C /usr/src

dir=`ls -l /usr/src | grep ^d |grep squirrel | awk '{print $7}'`

mv /usr/src/$dir $httpd_dir/htdocs/webmail

webmaildir=$httpd_dir/htdocs/webmail

tar zxf /usr/src/zh_CN*.gz -C $webmaildir

cd $httpd_dir/htdocs/webmail

mkdir -p data attach

chown -R daemon:daemon data attach


cp config/config_default.php config/config.php


sed -i '/^$data_dir =/ d' config/config.php

sed -i '/^$attachment_dir =/ d' config/config.php

sed -i '/^ $squirrelmail_default_language=/ d' config/config.php

sed -i '/^$default_charset =/ d' config/config.php

echo "\$data_dir = '$webmaildir/data';

\$attachment_dir = '$webmaildir/attach';

\$squirrelmail_default_language = 'zh_CN';

\$default_charset = 'zh_CN.UTF-8';">> config/config.php

fi


你可能感兴趣的:(shell脚本,编写安装配置mail服务脚本)