From 7c2777f949553efb541d930f460955fff2040369 Mon Sep 17 00:00:00 2001 From: Jeff Atwood Date: Mon, 16 May 2016 03:27:43 -0700 Subject: [PATCH] add SMTP port selection, smarter mailgun handling --- discourse-setup | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/discourse-setup b/discourse-setup index d077ab0..59d1e85 100755 --- a/discourse-setup +++ b/discourse-setup @@ -43,9 +43,9 @@ check_disk_and_memory() { dd if=/dev/zero of=/swapfile bs=1k count=2048k mkswap /swapfile swapon /swapfile - echo "/swapfile swap swap auto 0 0" | sudo tee -a /etc/fstab + echo "/swapfile swap swap auto 0 0" | tee -a /etc/fstab sysctl -w vm.swappiness=10 - echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf + echo vm.swappiness = 10 | tee -a /etc/sysctl.conf total_swap="$(LANG=C free -m | grep ^Swap: | awk '{print $2}')" if [ "$total_swap" -lt 1000 ]; then @@ -163,7 +163,8 @@ ask_user_for_config() { local hostname="discourse.example.com" local developer_emails="me@example.com,you@example.com" local smtp_address="smtp.example.com" - local smtp_user_name="postmaster@discourse.example.com" + local smtp_port="587" + local smtp_user_name="postmaster@discourse.example.com" local smtp_password="" local letsencrypt_account_email="me@example.com" local letsencrypt_status="ENTER to skip" @@ -203,15 +204,30 @@ ask_user_for_config() { fi fi - if [ "$smtp_address" == "smtp.sparkpostmail.com" ] + if [ ! -z $smtp_port ] then - smtp_user_name="SMTP_Injection" + read -p "SMTP port? [$smtp_port]: " new_value + if [ ! -z $new_value ] + then + smtp_port=$new_value + fi fi + ## + ## automatically set correct user name based on common mail providers + ## + if [ "$smtp_address" == "smtp.sparkpostmail.com" ] + then + smtp_user_name="SMTP_Injection" + fi if [ "$smtp_address" == "smtp.sendgrid.net" ] then smtp_user_name="apikey" fi + if [ "$smtp_address" == "smtp.mailgun.org" ] + then + smtp_user_name="postmaster@$hostname" + fi if [ ! -z $smtp_user_name ] then @@ -247,6 +263,7 @@ ask_user_for_config() { echo "Hostname : $hostname" echo "Email : $developer_emails" echo "SMTP address : $smtp_address" + echo "SMTP port : $smtp_port" echo "SMTP username : $smtp_user_name" echo "SMTP password : $smtp_password" @@ -286,6 +303,15 @@ ask_user_for_config() { update_ok="n" fi + sed -i -e "s/^ #DISCOURSE_SMTP_PORT:.*/ DISCOURSE_SMTP_PORT: $smtp_port/w $changelog" $config_file + if [ -s $changelog ] + then + rm $changelog + else + echo "DISCOURSE_SMTP_PORT change failed." + update_ok="n" + fi + sed -i -e "s/^ #DISCOURSE_SMTP_USER_NAME:.*/ DISCOURSE_SMTP_USER_NAME: $smtp_user_name/w $changelog" $config_file if [ -s $changelog ] then -- 2.25.1