编写安装配置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,如需转载请自行联系原作者
相关文章
|
4天前
|
搜索推荐 编译器 Linux
一个可用于企业开发及通用跨平台的Makefile文件
一款适用于企业级开发的通用跨平台Makefile,支持C/C++混合编译、多目标输出(可执行文件、静态/动态库)、Release/Debug版本管理。配置简洁,仅需修改带`MF_CONFIGURE_`前缀的变量,支持脚本化配置与子Makefile管理,具备完善日志、错误提示和跨平台兼容性,附详细文档与示例,便于学习与集成。
292 116
|
19天前
|
域名解析 人工智能
【实操攻略】手把手教学,免费领取.CN域名
即日起至2025年12月31日,购买万小智AI建站或云·企业官网,每单可免费领1个.CN域名首年!跟我了解领取攻略吧~
|
6天前
|
数据采集 人工智能 自然语言处理
Meta SAM3开源:让图像分割,听懂你的话
Meta发布并开源SAM 3,首个支持文本或视觉提示的统一图像视频分割模型,可精准分割“红色条纹伞”等开放词汇概念,覆盖400万独特概念,性能达人类水平75%–80%,推动视觉分割新突破。
421 39
Meta SAM3开源:让图像分割,听懂你的话
|
13天前
|
安全 Java Android开发
深度解析 Android 崩溃捕获原理及从崩溃到归因的闭环实践
崩溃堆栈全是 a.b.c?Native 错误查不到行号?本文详解 Android 崩溃采集全链路原理,教你如何把“天书”变“说明书”。RUM SDK 已支持一键接入。
670 220
|
1天前
|
Windows
dll错误修复 ,可指定下载dll,regsvr32等
dll错误修复 ,可指定下载dll,regsvr32等
132 95
|
11天前
|
人工智能 移动开发 自然语言处理
2025最新HTML静态网页制作工具推荐:10款免费在线生成器小白也能5分钟上手
晓猛团队精选2025年10款真正免费、无需编程的在线HTML建站工具,涵盖AI生成、拖拽编辑、设计稿转代码等多种类型,均支持浏览器直接使用、快速出图与文件导出,特别适合零基础用户快速搭建个人网站、落地页或企业官网。
1668 158
|
存储 人工智能 监控
从代码生成到自主决策:打造一个Coding驱动的“自我编程”Agent
本文介绍了一种基于LLM的“自我编程”Agent系统,通过代码驱动实现复杂逻辑。该Agent以Python为执行引擎,结合Py4j实现Java与Python交互,支持多工具调用、记忆分层与上下文工程,具备感知、认知、表达、自我评估等能力模块,目标是打造可进化的“1.5线”智能助手。
917 61