diff --git a/discourse-setup b/discourse-setup index 5adfe1358..7ead5222c 100755 --- a/discourse-setup +++ b/discourse-setup @@ -27,6 +27,10 @@ while [ ${#} -gt 0 ]; do SKIP_CONNECTION_TEST="1" echo "skipping connection test" ;; + --skip-email-setup) + SKIP_EMAIL_SETUP="1" + echo "Skipping email configuration; Discourse ID authentication will be enabled." + ;; esac shift 1 @@ -455,6 +459,8 @@ ask_user_for_config() { then smtp_password="" fi + read_config "DISCOURSE_SKIP_EMAIL_SETUP" + local skip_email_setup=$read_config_result read_config "DISCOURSE_NOTIFICATION_EMAIL" local notification_email=$read_config_result read_config "DISCOURSE_SMTP_DOMAIN" @@ -541,67 +547,77 @@ ask_user_for_config() { done fi - if [ ! -z "$smtp_address" ] + if [ "$SKIP_EMAIL_SETUP" != "1" ] then - read -p "SMTP server address? [$smtp_address]: " new_value - if [ ! -z "$new_value" ] + if [ ! -z "$smtp_address" ] then - smtp_address="$new_value" + read -p "SMTP server address? [$smtp_address]: " new_value + if [ ! -z "$new_value" ] + then + smtp_address="$new_value" + fi fi - fi - if [ ! -z "$smtp_port" ] - then - read -p "SMTP port? [$smtp_port]: " new_value - if [ ! -z "$new_value" ] + if [ ! -z "$smtp_port" ] then - smtp_port="$new_value" + read -p "SMTP port? [$smtp_port]: " new_value + if [ ! -z "$new_value" ] + then + smtp_port="$new_value" + fi fi - fi - ## - ## automatically set correct user name based on common mail providers unless it's been set - ## - if [ "$smtp_user_name" == "user@example.com" ] - then - if [ "$smtp_address" == "smtp.sparkpostmail.com" ] - then - smtp_user_name="SMTP_Injection" - fi - if [ "$smtp_address" == "smtp.sendgrid.net" ] + ## + ## automatically set correct user name based on common mail providers unless it's been set + ## + if [ "$smtp_user_name" == "user@example.com" ] then - smtp_user_name="apikey" + 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 fi - if [ "$smtp_address" == "smtp.mailgun.org" ] + + if [ ! -z "$smtp_user_name" ] then - smtp_user_name="postmaster@$hostname" + read -p "SMTP user name? [$smtp_user_name]: " new_value + if [ ! -z "$new_value" ] + then + smtp_user_name="$new_value" + fi fi - fi - if [ ! -z "$smtp_user_name" ] - then - read -p "SMTP user name? [$smtp_user_name]: " new_value + read -p "SMTP password? [$smtp_password]: " new_value if [ ! -z "$new_value" ] then - smtp_user_name="$new_value" + smtp_password="$new_value" fi - fi - - read -p "SMTP password? [$smtp_password]: " new_value - if [ ! -z "$new_value" ] - then - smtp_password="$new_value" - fi - if [[ "$notification_email" == "noreply@discourse.example.com"* ]] - then - notification_email="noreply@$hostname" - fi + if [[ "$notification_email" == "noreply@discourse.example.com"* ]] + then + notification_email="noreply@$hostname" + fi - read -p "notification email address? [$notification_email]: " new_value - if [ ! -z "$new_value" ] - then - notification_email="$new_value" + read -p "notification email address? [$notification_email]: " new_value + if [ ! -z "$new_value" ] + then + notification_email="$new_value" + fi + else + echo "" + echo "Skipping SMTP configuration (--skip-email-setup enabled)" + if [[ "$notification_email" == "noreply@discourse.example.com"* ]] + then + notification_email="noreply@$hostname" + fi fi # set smtp_domain default value here rather than use Rails default of localhost @@ -644,10 +660,15 @@ ask_user_for_config() { echo -e "\nDoes this look right?\n" 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" + if [ "$SKIP_EMAIL_SETUP" == "1" ] + then + echo "SMTP configuration: skipped (--skip-email-setup)" + else + echo "SMTP address : $smtp_address" + echo "SMTP port : $smtp_port" + echo "SMTP username : $smtp_user_name" + echo "SMTP password : $smtp_password" + fi echo "Notification email: $notification_email" if [ "$letsencrypt_status" == "Enter 'OFF' to disable." ] @@ -691,91 +712,106 @@ ask_user_for_config() { update_ok="n" fi - sed -i -e "s/^ DISCOURSE_SMTP_ADDRESS:.*/ DISCOURSE_SMTP_ADDRESS: $smtp_address/w $changelog" $web_file - if [ -s $changelog ] - then - rm $changelog - else - echo "DISCOURSE_SMTP_ADDRESS change failed." - update_ok="n" - fi - - sed -i -e "s/^ #\?DISCOURSE_SMTP_PORT:.*/ DISCOURSE_SMTP_PORT: $smtp_port/w $changelog" $web_file - if [ -s $changelog ] + if [ "$SKIP_EMAIL_SETUP" != "1" ] then - rm $changelog - else - echo "DISCOURSE_SMTP_PORT change failed." - update_ok="n" - fi + sed -i -e "s/^ DISCOURSE_SMTP_ADDRESS:.*/ DISCOURSE_SMTP_ADDRESS: $smtp_address/w $changelog" $web_file + if [ -s $changelog ] + then + rm $changelog + else + echo "DISCOURSE_SMTP_ADDRESS change failed." + update_ok="n" + fi - sed -i -e "s/^ #\?DISCOURSE_SMTP_USER_NAME:.*/ DISCOURSE_SMTP_USER_NAME: $smtp_user_name/w $changelog" $web_file - if [ -s $changelog ] - then - rm $changelog - else - echo "DISCOURSE_SMTP_USER_NAME change failed." - update_ok="n" - fi + sed -i -e "s/^ #\?DISCOURSE_SMTP_PORT:.*/ DISCOURSE_SMTP_PORT: $smtp_port/w $changelog" $web_file + if [ -s $changelog ] + then + rm $changelog + else + echo "DISCOURSE_SMTP_PORT change failed." + update_ok="n" + fi - sed -i -e "s/^ #\?DISCOURSE_NOTIFICATION_EMAIL:.*/ DISCOURSE_NOTIFICATION_EMAIL: $notification_email/w $changelog" $web_file - if [ -s $changelog ] - then - rm $changelog - else - echo "DISCOURSE_NOTIFICATION_EMAIL change failed." - update_ok="n" - fi + sed -i -e "s/^ #\?DISCOURSE_SMTP_USER_NAME:.*/ DISCOURSE_SMTP_USER_NAME: $smtp_user_name/w $changelog" $web_file + if [ -s $changelog ] + then + rm $changelog + else + echo "DISCOURSE_SMTP_USER_NAME change failed." + update_ok="n" + fi - sed -i -e "s/^ #\?DISCOURSE_SMTP_DOMAIN:.*/ DISCOURSE_SMTP_DOMAIN: $smtp_domain/w $changelog" $web_file - if [ -s $changelog ] - then - rm $changelog - else - echo "DISCOURSE_SMTP_DOMAIN change failed." - update_ok="n" - fi + sed -i -e "s/^ #\?DISCOURSE_SMTP_DOMAIN:.*/ DISCOURSE_SMTP_DOMAIN: $smtp_domain/w $changelog" $web_file + if [ -s $changelog ] + then + rm $changelog + else + echo "DISCOURSE_SMTP_DOMAIN change failed." + update_ok="n" + fi - if [[ "$smtp_password" == *"\""* ]] - then - SLASH="BROKEN" - echo "========================================" - echo "WARNING!!!" - echo "Your password contains a quote (\")" - echo "Your SMTP Password will not be set. You will need to edit app.yml to enter it." - echo "========================================" - update_ok="n" - else - SLASH="|" - if [[ "$smtp_password" == *"$SLASH"* ]] - then SLASH="+" - if [[ "$smtp_password" == *"$SLASH"* ]] - then - SLASH="Q" + if [[ "$smtp_password" == *"\""* ]] + then + SLASH="BROKEN" + echo "========================================" + echo "WARNING!!!" + echo "Your password contains a quote (\")" + echo "Your SMTP Password will not be set. You will need to edit app.yml to enter it." + echo "========================================" + update_ok="n" + else + SLASH="|" + if [[ "$smtp_password" == *"$SLASH"* ]] + then SLASH="+" if [[ "$smtp_password" == *"$SLASH"* ]] then - SLASH="BROKEN" - echo "========================================" - echo "WARNING!!!" - echo "Your password contains all available delimiters (+, |, and Q). " - echo "Your SMTP Password will not be set. You will need to edit app.yml to enter it." - echo "========================================" - update_ok="n" + SLASH="Q" + if [[ "$smtp_password" == *"$SLASH"* ]] + then + SLASH="BROKEN" + echo "========================================" + echo "WARNING!!!" + echo "Your password contains all available delimiters (+, |, and Q). " + echo "Your SMTP Password will not be set. You will need to edit app.yml to enter it." + echo "========================================" + update_ok="n" + fi fi - fi + fi fi - fi - if [[ "$SLASH" != "BROKEN" ]] - then - sed -i -e "s${SLASH}^ #\?DISCOURSE_SMTP_PASSWORD:.*${SLASH} DISCOURSE_SMTP_PASSWORD: \"${smtp_password}\"${SLASH}w $changelog" $web_file + if [[ "$SLASH" != "BROKEN" ]] + then + sed -i -e "s${SLASH}^ #\?DISCOURSE_SMTP_PASSWORD:.*${SLASH} DISCOURSE_SMTP_PASSWORD: \"${smtp_password}\"${SLASH}w $changelog" $web_file + + if [ -s $changelog ] + then + rm $changelog + else + echo "DISCOURSE_SMTP_PASSWORD change failed." + update_ok="n" + fi + fi + else + echo "SMTP environment variables skipped (--skip-email-setup)." + sed -i -e "s/^ #\?DISCOURSE_SKIP_EMAIL_SETUP:.*/ DISCOURSE_SKIP_EMAIL_SETUP: $skip_email_setup/w $changelog" $web_file if [ -s $changelog ] then rm $changelog else - echo "DISCOURSE_SMTP_PASSWORD change failed." + echo "DISCOURSE_SKIP_EMAIL_SETUP change failed." update_ok="n" fi + + fi + + sed -i -e "s/^ #\?DISCOURSE_NOTIFICATION_EMAIL:.*/ DISCOURSE_NOTIFICATION_EMAIL: $notification_email/w $changelog" $web_file + if [ -s $changelog ] + then + rm $changelog + else + echo "DISCOURSE_NOTIFICATION_EMAIL change failed." + update_ok="n" fi if ! [ -z $DEBUG ] @@ -858,8 +894,14 @@ validate_config() { valid_config="y" - for x in DISCOURSE_SMTP_ADDRESS DISCOURSE_SMTP_USER_NAME DISCOURSE_SMTP_PASSWORD \ - DISCOURSE_DEVELOPER_EMAILS DISCOURSE_HOSTNAME + if [ "$SKIP_EMAIL_SETUP" == "1" ] + then + required_fields="DISCOURSE_DEVELOPER_EMAILS DISCOURSE_HOSTNAME" + else + required_fields="DISCOURSE_SMTP_ADDRESS DISCOURSE_SMTP_USER_NAME DISCOURSE_SMTP_PASSWORD DISCOURSE_DEVELOPER_EMAILS DISCOURSE_HOSTNAME" + fi + + for x in $required_fields do read_config $x local result=$read_config_result @@ -893,7 +935,6 @@ validate_config() { fi } - ## ## template file names ## diff --git a/samples/standalone.yml b/samples/standalone.yml index 10286935f..43c2c6404 100644 --- a/samples/standalone.yml +++ b/samples/standalone.yml @@ -70,6 +70,7 @@ env: #DISCOURSE_NOTIFICATION_EMAIL: noreply@discourse.example.com # (address to send notifications from) #DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: peer # (optional, default: peer, valid values: none, peer, client_once, fail_if_no_peer_cert) #DISCOURSE_SMTP_AUTHENTICATION: plain # (default: plain, valid values: plain, login, cram_md5) + #DISCOURSE_SKIP_EMAIL_SETUP: "1" # (optional), uncomment to skip email setup validation ## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate #LETSENCRYPT_ACCOUNT_EMAIL: me@example.com diff --git a/templates/web.template.yml b/templates/web.template.yml index 000abb2e4..fc9dbd71e 100644 --- a/templates/web.template.yml +++ b/templates/web.template.yml @@ -24,7 +24,7 @@ run: - exec: tag: precompile cmd: - - /usr/local/bin/ruby -e 'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end' + - /usr/local/bin/ruby -e 'if (ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com" && ENV["DISCOURSE_SKIP_EMAIL_SETUP"] != "1"); puts "Aborting! Mail is not configured!"; exit 1; end' - /usr/local/bin/ruby -e 'if ENV["DISCOURSE_HOSTNAME"] == "discourse.example.com"; puts "Aborting! Domain is not configured!"; exit 1; end' - /usr/local/bin/ruby -e 'if (ENV["DISCOURSE_CDN_URL"] || "")[0..1] == "//"; puts "Aborting! CDN must have a protocol specified. Once fixed you should rebake your posts now to correct all posts."; exit 1; end' # TODO: move to base image (anacron can not be fired up using rc.d)