Guest User

Untitled

a guest
May 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4.  
  5. install_dovecot(){
  6.  
  7. echo "function install_dovecot"
  8.  
  9. #install dovecot
  10. sudo apt-get install dovecot-core
  11. sudo apt-get install dovecot-imapd
  12.  
  13.  
  14.  
  15. #open 143 port in UFW
  16. sudo ufw allow "Dovecot IMAP"
  17. #show status
  18. sudo ufw status
  19.  
  20.  
  21.  
  22. #editing dovecot config files
  23. #1. in file /etc/dovecot/conf.d/10-auth.conf set up these rows
  24. #set up
  25. #disable_plaintext_auth = yes
  26. sudo sed -ri.bak 's/^#?\s*disable_plaintext_auth\s*=\s*.+\s*$/disable_plaintext_auth = yes/' /etc/dovecot/conf.d/10-auth.conf
  27. #auth_mechanisms = plain login
  28. sudo sed -ri.bak 's/^#?\s*auth_mechanisms\s*=\s*[a-z\s]+$/auth_mechanisms = plain login/' /etc/dovecot/conf.d/10-auth.conf
  29. #exit
  30. #in file /etc/dovecot/conf.d/10-ssl.conf set up these rows
  31. #ssl = required
  32. sudo sed -ri.bak 's/^\s*#?\s*ssl\s*=\s*.+\s*$/ssl = required/' /etc/dovecot/conf.d/10-ssl.conf
  33. #ssl_cert = </etc/ssl/certs/ssl-cert-snakeoil.pem
  34. #exit
  35. sudo sed -ri.bak 's/^\s*#?\s*ssl_cert\s*=\s*.+\s*$/ssl_cert = <\/etc\/ssl\/certs\/ssl-cert-snakeoil.pem/' /etc/dovecot/conf.d/10-ssl.conf
  36. #exit
  37. #ssl_key = </etc/ssl/private/ssl-cert-snakeoil.key
  38. sudo sed -ri.bak 's/^\s*#?\s*ssl_key\s*=\s*.+\s*$/ssl_key = <\/etc\/ssl\/private\/ssl-cert-snakeoil.key/' /etc/dovecot/conf.d/10-ssl.conf
  39. #exit
  40. #in file /etc/dovecot/conf.d/10-mail.conf
  41. #mail_location = maildir:~/Maildir
  42. sudo sed -ri.bak 's/^mail_location\s*=\s*.+\s*$/mail_location = maildir:~\/Maildir/' /etc/dovecot/conf.d/10-mail.conf
  43. #exit
  44. #namespace inbox {
  45. # ...
  46. # inbox = yes
  47. # ...
  48. #}
  49. #this is set up by default in yes
  50.  
  51.  
  52. #//in file /etc/dovecot/conf.d/10-master.conf
  53. #service auth {
  54. # …
  55. # unix_listener /var/spool/postfix/private/auth {
  56. # mode = 0660
  57. # # Assuming the default Postfix user and group
  58. # user = postfix
  59. # group = postfix
  60. # }
  61. # ...
  62. #}
  63. if [ ! "`grep -P \"^\s*user\s*=\s*postfix\s*$\" /etc/dovecot/conf.d/10-master.conf`" ]; then
  64. text="\n # Postfix smtp-auth\n unix_listener \/var\/spool\/postfix\/private\/auth \{\n mode = 0660\n # Assuming the default Postfix user and group\n user = postfix\n group = postfix\n \}\n"
  65.  
  66. sudo sed -ri.bak "
  67. :a;
  68. N;
  69. \$!ba;
  70. s/# Postfix smtp-auth.*#\}/$text/
  71. " /etc/dovecot/conf.d/10-master.conf
  72. fi
  73. #exit
  74.  
  75.  
  76.  
  77. ###########################################
  78. ## edit postfix files
  79. #################################
  80.  
  81. if [ ! "`grep -P \"#====== Dovecot SASL and Maildir store ======#\" /etc/postfix/main.cf`" ]; then
  82. # add some seting to /etc/postfix/main.cf
  83. echo "
  84. #====== Dovecot SASL and Maildir store ======#
  85. home_mailbox = Maildir/
  86.  
  87. smtpd_sasl_type = dovecot
  88.  
  89. # Can be an absolute path, or relative to \$queue_directory
  90. # Debian/Ubuntu users: Postfix is setup by default to run chrooted, so it is best to leave it as-is below
  91. smtpd_sasl_path = private/auth
  92.  
  93. # On Debian Wheezy path must be relative and queue_directory defined
  94. #queue_directory = /var/spool/postfix
  95.  
  96. # and the common settings to enable SASL:
  97. smtpd_sasl_auth_enable = yes
  98. # With Postfix version before 2.10, use smtpd_recipient_restrictions
  99. #smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
  100. #====== Dovecot and Maildir store ======#
  101. " | sudo tee -a /etc/postfix/main.cf
  102. #exit
  103. fi
  104.  
  105.  
  106. #edit file /etc/postfix/master.cf
  107. #uncomment line # -o smtpd_sasl_auth_enable=yes
  108. sudo sed -ri.bak "
  109. :a;
  110. N;
  111. \$!ba;
  112. s/(# -o smtpd_tls_security_level=encrypt\s*\n*\s*)#( -o smtpd_sasl_auth_enable=yes\s*\n)/\1\2/
  113. " /etc/postfix/master.cf
  114. #exit
  115.  
  116.  
  117.  
  118. #retart dovecot and postfix
  119. sudo systemctl restart postfix.service
  120. sudo systemctl restart dovecot.service
  121.  
  122. echo
  123. echo "dovecot has been successfully installed"
  124.  
  125. } #install_dovecot
Add Comment
Please, Sign In to add comment