博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
编写安装配置mail服务脚本
阅读量:7235 次
发布时间:2019-06-29

本文共 3598 字,大约阅读时间需要 11 分钟。

编写安装配置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,如需转载请自行联系原作者
你可能感兴趣的文章
Mac OS X 10.10优胜美地怎样完美接管iphone上的电话和短信
查看>>
dotnet程序优化心得(一)
查看>>
妙趣横生的算法--二叉树
查看>>
发布了Android的App,我要开源几个组件!
查看>>
PHP foreach使用
查看>>
《基于MFC的OpenGL编程》Part 13 Creating 2D and 3D Text
查看>>
HTML5 移动浏览器支持
查看>>
[LeetCode] Next Closest Time 下一个最近时间点
查看>>
【AngularJS】—— 4 表达式
查看>>
[LeetCode] Surrounded Regions
查看>>
【Android布局】在程序中设置android:gravity 和 android:layout_Gravity属性
查看>>
U盘启动笔记本无法安装Win7问题和解决
查看>>
基于SignalR的站点有连接数限制问题及解决方案
查看>>
程序猿当下需要准备涉及的技术方向
查看>>
一起学微软Power BI系列-使用技巧(1)连接Oracle与Mysql数据库
查看>>
2017"百度之星"程序设计大赛 - 复赛1005&&HDU 6148 Valley Numer【数位dp】
查看>>
Linux setjmp longjmp
查看>>
Java自定义注解开发
查看>>
EMF介绍系列(四、枚举类型、自定义类型和Map)
查看>>
淘宝API开发系列--商家的绑定
查看>>