From 9d8a707d7f70645c81992869d43773fb5b530e1f Mon Sep 17 00:00:00 2001 From: GullumLuvl <7593801+Gullumluvl@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:37:49 +0100 Subject: [PATCH 1/2] Fix a switched variable name (actually parse the default file) --- discourse-setup | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/discourse-setup b/discourse-setup index 209c622f1..894da2656 100755 --- a/discourse-setup +++ b/discourse-setup @@ -344,15 +344,17 @@ check_port() { ## read a variable from the config file ## read_config() { + local config_line config_line=`grep -E "^ #?$1:" $web_file` read_config_result=`echo $config_line | awk -F":" '{print $2}'` read_config_result=`echo $read_config_result | sed "s/^\([\"']\)\(.*\)\1\$/\2/g"` } read_default() { - config_line=`grep -E "^ #?$1:" samples/standalone.yml` - read_default_result=`echo $config_line | awk -F":" '{print $2}'` - read_default_result=`echo $read_config_result | sed "s/^\([\"']\)\(.*\)\1\$/\2/g"` + local default_line + default_line=`grep -E "^ #?$1:" samples/standalone.yml` + read_default_result=`echo $default_line | awk -F":" '{print $2}'` + read_default_result=`echo $read_default_result | sed "s/^\([\"']\)\(.*\)\1\$/\2/g"` } assert_maxmind_envs() { @@ -866,17 +868,11 @@ validate_config() { if [ ! -z "$result" ] then - if [[ "$config_line" = *"$default"* ]] + if [[ "$result" = "$default" ]] then echo "$x left at incorrect default of $default" valid_config="n" fi - config_val=`echo $config_line | awk '{print $2}'` - if [ -z $config_val ] - then - echo "$x was not configured" - valid_config="n" - fi else echo "$x not present" valid_config="n" From 2ad8204dcafd8d0ac33922d885b1aa6344e0b21a Mon Sep 17 00:00:00 2001 From: GullumLuvl <7593801+Gullumluvl@users.noreply.github.com> Date: Fri, 1 Nov 2024 21:27:51 +0100 Subject: [PATCH 2/2] Add a "SMTP protocol" user entry to the setup, automatically prefilled with TLS for port 465, STARTTLS otherwise. --- discourse-setup | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/discourse-setup b/discourse-setup index 894da2656..9360a7502 100755 --- a/discourse-setup +++ b/discourse-setup @@ -447,6 +447,10 @@ ask_user_for_config() { local developer_emails=$read_config_result read_config "DISCOURSE_SMTP_PASSWORD" local smtp_password=$read_config_result + read_config "DISCOURSE_SMTP_ENABLE_START_TLS" + local smtp_enable_start_tls=$read_config_result + read_config "DISCOURSE_SMTP_FORCE_TLS" + local smtp_force_tls=$read_config_result read_config "DISCOURSE_SMTP_PORT" local smtp_port=$read_config_result read_config "DISCOURSE_SMTP_USER_NAME" @@ -559,6 +563,46 @@ ask_user_for_config() { fi fi + ## + ## automatically suggest TLS if port 465, otherwise keep STARTTLS + ## + if [ ! -z "$smtp_enable_start_tls" ] + then + if [ "$smtp_port" == 465 ] + then + smtp_protocol="TLS" + else + smtp_protocol="STARTTLS" + fi + local smtp_protocol_valid="n" + until [ "$smtp_protocol_valid" == "y" ] + do + read -p "SMTP protocol? [$smtp_protocol]: " new_value + if [ ! -z "$new_value" ] + then + if [ "$new_value" == 'TLS' ] || [ "$new_value" == 'STARTTLS' ] + then + smtp_protocol="$new_value" + smtp_protocol_valid="y" + else + echo + echo "[Error] Invalid SMTP protocol (TLS or STARTTLS)" + echo + fi + else + smtp_protocol_valid="y" + fi + done + if [ "$smtp_protocol" == "STARTTLS" ] + then + smtp_enable_start_tls='true' + smtp_force_tls='false' + else + smtp_enable_start_tls='false' + smtp_force_tls='true' + fi + fi + ## ## automatically set correct user name based on common mail providers unless it's been set ## @@ -646,6 +690,7 @@ ask_user_for_config() { echo "Email : $developer_emails" echo "SMTP address : $smtp_address" echo "SMTP port : $smtp_port" + echo "SMTP protocol : $smtp_protocol" echo "SMTP username : $smtp_user_name" echo "SMTP password : $smtp_password" echo "Notification email: $notification_email" @@ -709,6 +754,28 @@ ask_user_for_config() { update_ok="n" fi + sed -i -e "s/^ #\?DISCOURSE_SMTP_ENABLE_START_TLS:.*/ DISCOURSE_SMTP_ENABLE_START_TLS: $smtp_enable_start_tls/w $changelog" $web_file + if [ -s $changelog ] + then + rm $changelog + else + echo "DISCOURSE_SMTP_ENABLE_START_TLS change failed." + update_ok="n" + fi + + sed -i -e "s/^ #\?DISCOURSE_SMTP_FORCE_TLS:.*/ DISCOURSE_SMTP_FORCE_TLS: $smtp_force_tls/w $changelog" $web_file + if [ -s $changelog ] + then + rm $changelog + else + sed -i "/^.*DISCOURSE_SMTP_ENABLE_START_TLS:.*/a \ \ DISCOURSE_SMTP_FORCE_TLS: $smtp_force_tls" $web_file + if ! grep -q '^ DISCOURSE_SMTP_FORCE_TLS:' "$web_file" + then + echo "DISCOURSE_SMTP_FORCE_TLS change failed." + update_ok="n" + fi + fi + sed -i -e "s/^ #\?DISCOURSE_SMTP_USER_NAME:.*/ DISCOURSE_SMTP_USER_NAME: $smtp_user_name/w $changelog" $web_file if [ -s $changelog ] then