Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
281 changes: 161 additions & 120 deletions discourse-setup
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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." ]
Expand Down Expand Up @@ -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 ]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -893,7 +935,6 @@ validate_config() {
fi
}


##
## template file names
##
Expand Down
1 change: 1 addition & 0 deletions samples/standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion templates/web.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down