Advertisement
Guest User

Untitled

a guest
Mar 10th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 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 mailutils
  34. then
  35. sudo apt-get install mailutils
  36. fi
  37.  
  38. if ! dpkg -s postfix >/dev/null;
  39. then
  40. install_postfix
  41. else
  42. echo "Postfix is already installed."
  43. echo "You may consider removing it before running the script."
  44. echo "You may do so with the following command:"
  45. echo "sudo apt-get purge postfix"
  46. echo
  47. fi
  48.  
  49. if zenity --version >/dev/null; then
  50. GMAIL_ADRESS=$(zenity --entry --title="Gmail e-mail-adress" --text="Enter your gmail e-mail-adress:")
  51. GMAIL_PASS=$(zenity --entry --title="Gmail password" --text="Enter your gmail password:" --hide-text)
  52. else
  53. read -p "Gmail username: " GMAIL_ADRESS
  54. read -sp "Gmail password: " GMAIL_PASS
  55. fi
  56.  
  57. echo # an empty line
  58.  
  59. if [ -z "$GMAIL_ADRESS" ]; then echo "No gmail e-mail-adress given. Exiting."; exit -1; fi
  60. if [ -z "$GMAIL_PASS" ]; then echo "No gmail password given. Exiting."; exit -1; fi
  61.  
  62. if ! [ -f /etc/postfix/main.cf.original ]; then
  63. sudo cp /etc/postfix/main.cf /etc/postfix/main.cf.original
  64. fi
  65.  
  66. sudo tee /etc/postfix/main.cf >/dev/null <<__EOF
  67. relayhost = [smtp.gmail.com]:587
  68. smtp_use_tls = yes
  69. smtp_sasl_auth_enable = yes
  70. smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
  71. smtp_sasl_security_options = noanonymous
  72. smtp_tls_loglevel = 1
  73. smtp_tls_per_site = hash:/etc/postfix/tls_per_site
  74. smtp_tls_CAfile = /etc/ssl/certs/Equifax_Secure_CA.pem
  75. smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache
  76. __EOF
  77.  
  78. echo "[smtp.gmail.com]:587 $GMAIL_ADRESS:$GMAIL_PASS" | sudo tee /etc/postfix/sasl_passwd >/dev/null
  79. sudo chmod 400 /etc/postfix/sasl_passwd
  80. sudo postmap /etc/postfix/sasl_passwd
  81. echo "smtp.gmail.com MUST" | sudo tee /etc/postfix/tls_per_site >/dev/null
  82. sudo chmod 400 /etc/postfix/tls_per_site
  83. sudo postmap /etc/postfix/tls_per_site
  84.  
  85. sudo service postfix restart
  86. echo "Configuration done"
  87.  
  88. mail -s "Email relaying configured at ${HOST}" $GMAIL_ADRESS <<__EOF
  89. The postfix service has been configured at host '${HOST}'.
  90. Thank you for using this postfix configuration script.
  91. __EOF
  92.  
  93. echo "I have sent you a mail to $GMAIL_ADRESS"
  94. echo "This will confirm that the configuration is good."
  95. echo "Please check your inbox at gmail."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement