编写安装配置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



本文转自甘兵 51CTO博客,原文链接:http://blog.51cto.com/ganbing/1243667,如需转载请自行联系原作者
相关文章
|
机器学习/深度学习 Java Shell
shell脚本简介+编写
shell脚本简介+编写
99 0
|
7月前
|
存储 监控 Unix
Shell脚本编写教程
Shell脚本编写教程
148 1
|
存储 数据安全/隐私保护 Python
用python写一款FTP自动化的脚本
用python写一款FTP自动化的脚本
243 0
|
网络安全
JMeter入门教程(6) --脚本添加
脚本添加的基本设置
276 0
JMeter入门教程(6) --脚本添加
|
Shell 开发工具 git
easyswoole 更新代码shell
easyswoole 更新代码shell
79 0
|
Shell
编写SHELL脚本--编写简单脚本
1.简单脚本文件hello.sh,内容如下 #!/bin/bash pwd ls -al  执行脚本:bash hello.sh  或者使用root命令:  ./hello.sh   2.接受用户参数   $0代表执行的脚本文件名称   $*代表所有的用户参数   $?代表上个命令执行后的返回...
1705 0
|
Linux 数据安全/隐私保护 Python