您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

100 行
3.3KB

  1. #!/bin/bash
  2. function replace {
  3. #echo $1
  4. sed -i "s/\${LDAP_SERVER_HOST}/${LDAP_SERVER_HOST}/g" $1
  5. sed -i "s/\${LDAP_BIND_DN}/${LDAP_BIND_DN}/g" $1
  6. sed -i "s/\${LDAP_SEARCH_BASE}/${LDAP_SEARCH_BASE}/g" $1
  7. sed -i "s/\${DOMAIN}/${DOMAIN}/g" $1
  8. sed -i "s/\${DOMAINS}/${DOMAINS[*]}/g" $1
  9. sed -i "s/\${LDAP_BIND_PWD}/${LDAP_BIND_PWD}/g" $1
  10. }
  11. for i in `find /tmp/config/postfix -type f -exec ls {} \;`; do
  12. replace $i
  13. done;
  14. for i in `find /tmp/config/dovecot -type f -exec ls {} \;`; do
  15. replace $i
  16. done;
  17. for i in `find /tmp/config/dovecot/conf.d -type f -exec ls {} \;`; do
  18. replace $i
  19. done;
  20. for i in `find /tmp/config/saslauth -type f -exec ls {} \;`; do
  21. replace $i
  22. done;
  23. # Postfix
  24. cp -f /tmp/config/postfix/* /etc/postfix/
  25. mkdir -p /etc/postfix/sasl
  26. cp -f /tmp/config/postfix/sasl/* /etc/postfix/sasl/sasl
  27. for i in ${DOMAINS[@]}; do
  28. echo "$i OK" >> /etc/postfix/virtual_domains;
  29. done;
  30. postmap hash:/etc/postfix/virtual_domains
  31. # TLS certs
  32. cd /tmp
  33. openssl genrsa -des3 -passout pass:${LDAP_BIND_PWD} -out mail.domain.tld.key 4096
  34. chmod 600 mail.domain.tld.key
  35. openssl req -new -key mail.domain.tld.key -out mail.domain.tld.csr \
  36. -passin pass:${LDAP_BIND_PWD} \
  37. -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.${DOMAIN}"
  38. openssl x509 -req -days 365 -in mail.domain.tld.csr -signkey mail.domain.tld.key \
  39. -out mail.domain.tld.crt -passin pass:${LDAP_BIND_PWD}
  40. openssl rsa -in mail.domain.tld.key -out mail.domain.tld.key.nopass \
  41. -passin pass:${LDAP_BIND_PWD}
  42. mv mail.domain.tld.key.nopass mail.domain.tld.key
  43. openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650 \
  44. -passout pass:${LDAP_BIND_PWD} \
  45. -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.${DOMAIN}"
  46. chmod 600 mail.domain.tld.key
  47. chmod 600 cakey.pem
  48. mv mail.domain.tld.key /etc/ssl/private/
  49. mv mail.domain.tld.crt /etc/ssl/certs/
  50. mv cakey.pem /etc/ssl/private/
  51. mv cacert.pem /etc/ssl/certs/
  52. # DH
  53. mkdir -p /etc/postfix/certs
  54. cd /etc/postfix/certs
  55. openssl dhparam -2 -out dh_512.pem 512
  56. openssl dhparam -2 -out dh_1024.pem 1024
  57. chown -R root:root /etc/postfix/certs/
  58. chmod -R 600 /etc/postfix/certs/
  59. # Dovecot
  60. mkdir -p /etc/dovecot/private
  61. openssl req -new -x509 -nodes -out /etc/dovecot/dovecot.pem -keyout /etc/dovecot/private/dovecot.pem -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.${DOMAIN}"
  62. cp -f /tmp/config/dovecot/* /etc/dovecot/
  63. cp -f /tmp/config/dovecot/conf.d/* /etc/dovecot/conf.d/
  64. #Saslauthd
  65. cp -f /tmp/config/saslauth/saslauthd /etc/default/
  66. cp -f /tmp/config/saslauth/saslauthd.conf /etc/
  67. chown root:sasl /etc/saslauthd.conf
  68. chmod 640 /etc/saslauthd.conf
  69. #rm -Rf /tmp/config
  70. # getmail
  71. # https://stackoverflow.com/a/9625233/1937418
  72. for i in `ls ${MAIL_DATA_PATH}/getmail/getmailrc-*`; do
  73. (crontab -l 2>/dev/null; echo "*/5 * * * * sudo -u vmail getmail -r $i --getmaildir ${MAIL_DATA_PATH}/getmail/ >> /dev/null") | crontab - ;
  74. done;
  75. touch ${MAIL_DATA_PATH}/getmail/getmail.log
  76. #chown -R vmail:vmail ${MAIL_DATA_PATH}/getmail
  77. if [ -z "${DATA_CHOWN}" -o "${DATA_CHOWN}" != "0" ]; then
  78. echo "Changing ownership of Data folder. It may take a while..."
  79. chown -R vmail:vmail ${MAIL_DATA_PATH}
  80. fi
  81. service rsyslog start
  82. service postfix start
  83. service dovecot start
  84. service saslauthd start
  85. service cron start
  86. tail -fn 0 /var/log/mail.log
  87. tail -f /dev/null
  88. exit 0