Guest User

Untitled

a guest
Feb 7th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. HOST=$(hostname)
  4.  
  5. function install_postfix() {
  6. echo | sudo debconf-set-selections <<__EOF
  7. postfix postfix/root_address string
  8. postfix postfix/rfc1035_violation boolean false
  9. postfix postfix/mydomain_warning boolean
  10. postfix postfix/mynetworks string 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
  11. postfix postfix/mailname string $HOST
  12. postfix postfix/tlsmgr_upgrade_warning boolean
  13. postfix postfix/recipient_delim string +
  14. postfix postfix/main_mailer_type select Internet with smarthost
  15. postfix postfix/destinations string $HOST, localhost.localdomain, localhost
  16. postfix postfix/retry_upgrade_warning boolean
  17. # Install postfix despite an unsupported kernel?
  18. postfix postfix/kernel_version_warning boolean
  19. postfix postfix/not_configured error
  20. postfix postfix/sqlite_warning boolean
  21. postfix postfix/mailbox_limit string 0
  22. postfix postfix/relayhost string [smtp.gmail.com]:587
  23. postfix postfix/procmail boolean false
  24. postfix postfix/bad_recipient_delimiter error
  25. postfix postfix/protocols select all
  26. postfix postfix/chattr boolean false
  27. __EOF
  28.  
  29. echo "Postfix should be configured as Internet site with smarthost"
  30. sudo apt-get install -q -y postfix
  31. }
  32.  
  33. if ! dpkg -s postfix >/dev/null;
  34. then
  35. install_postfix
  36. else
  37. echo "Postfix is already installed."
  38. echo "You may consider removing it before running the script."
  39. echo "You may do so with the following command:"
  40. echo "sudo apt-get purge postfix"
  41. echo
  42. fi
  43.  
  44. if zenity --version >/dev/null; then
  45. GMAIL_USER=$(zenity --entry --title="Gmail username" --text="Enter your gmail username:")
  46. GMAIL_PASS=$(zenity --entry --title="Gmail password" --text="Enter your gmail password:" --hide-text)
  47. else
  48. read -p "Gmail username: " GMAIL_USER
  49. read -sp "Gmail password: " GMAIL_PASS
  50. fi
  51.  
  52. echo # an empty line
  53.  
  54. if [ -z "$GMAIL_USER" ]; then echo "No gmail username given. Exiting."; exit -1; fi
  55. if [ -z "$GMAIL_PASS" ]; then echo "No gmail password given. Exiting."; exit -1; fi
  56.  
  57. if ! [ -f /etc/postfix/main.cf.original ]; then
  58. sudo cp /etc/postfix/main.cf /etc/postfix/main.cf.original
  59. fi
  60.  
  61. sudo tee /etc/postfix/main.cf >/dev/null <<__EOF
  62. relayhost = [smtp.gmail.com]:587
  63. smtp_use_tls = yes
  64. smtp_sasl_auth_enable = yes
  65. smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
  66. smtp_sasl_security_options = noanonymous
  67. smtp_tls_loglevel = 1
  68. smtp_tls_per_site = hash:/etc/postfix/tls_per_site
  69. smtp_tls_CAfile = /etc/ssl/certs/Equifax_Secure_CA.pem
  70. smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache
  71. __EOF
  72.  
  73. echo "[smtp.gmail.com]:587 $GMAIL_USER:$GMAIL_PASS" | sudo tee /etc/postfix/sasl_passwd >/dev/null
  74. sudo chmod 400 /etc/postfix/sasl_passwd
  75. sudo postmap /etc/postfix/sasl_passwd
  76. echo "smtp.gmail.com MUST" | sudo tee /etc/postfix/tls_per_site >/dev/null
  77. sudo chmod 400 /etc/postfix/tls_per_site
  78. sudo postmap /etc/postfix/tls_per_site
  79.  
  80. sudo service postfix restart
  81. echo "Configuration done"
  82.  
  83. mail -s "Email relaying configured at ${HOST}" $GMAIL_USER@gmail.com <<__EOF
  84. The postfix service has been configured at host '${HOST}'.
  85. Thank you for using this postfix configuration script.
  86. __EOF
  87.  
  88. echo "I have sent you a mail to $GMAIL_USER@gmail.com"
  89. echo "This will confirm that the configuration is good."
  90. echo "Please check your inbox at gmail."
Add Comment
Please, Sign In to add comment