From cc5b00a49e32c703db0aa0811372d656d3ab776c Mon Sep 17 00:00:00 2001 From: Jay Pfaffman Date: Thu, 11 Feb 2021 11:19:41 -0800 Subject: [PATCH] feature: discourse-setup email config improvements --- discourse-setup | 182 ++++++++++++++++++++++++++++++++----- samples/standalone.yml | 1 + samples/web_only.yml | 2 + tests/README.md | 28 ++++++ tests/run-all-tests | 11 +++ tests/standalone | 88 ++++++++++++++++++ tests/two-container | 87 ++++++++++++++++++ tests/update-old-templates | 94 +++++++++++++++++++ 8 files changed, 468 insertions(+), 25 deletions(-) create mode 100644 tests/README.md create mode 100755 tests/run-all-tests create mode 100755 tests/standalone create mode 100755 tests/two-container create mode 100755 tests/update-old-templates diff --git a/discourse-setup b/discourse-setup index 75094e2..fec8370 100755 --- a/discourse-setup +++ b/discourse-setup @@ -2,6 +2,34 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $DIR +if [ "$1" == "2container" ] +then + TWO_CONTAINER="1" + echo "2container argument is deprecated. Use --two-container" + shift 1 +fi + +while [ ${#} -gt 0 ]; do + case "${1}" in + --debug) + DEBUG="1" + SKIP_REBUILD="1" + ;; + --skip-rebuild) + SKIP_REBUILD="1" + ;; + --two-container) + TWO_CONTAINER="1" + ;; + --skip-connection-test) + SKIP_CONNECTION_TEST="1" + echo "skipping connection test" + ;; + esac + + shift 1 +done + ## ## Make sure only root can run our script ## @@ -45,8 +73,14 @@ connect_to_port () { check_IP_match() { HOST="$1" echo - echo Checking your domain name . . . - connect_to_port $HOST 443; ec=$? + if [ "$SKIP_CONNECTION_TEST" == 1 ] + then + echo "Setting EC to 2" + ec=2 + else + echo Checking your domain name . . . + connect_to_port $HOST 443; ec=$? + fi case $ec in 0) echo "Connection to $HOST succeeded." @@ -80,7 +114,7 @@ check_IP_match() { exit 1 ;; 2) - echo "Continuing without port check." + echo "Skipping port check." ;; esac } @@ -278,7 +312,7 @@ check_ports() { ## check_port() { - local valid=$(netstat -tln | awk '{print $4}' | grep ":${1}\$") + local valid=$(lsof -i:${1} | grep "LISTEN") if [ -n "$valid" ]; then echo "Port ${1} appears to already be in use." @@ -336,6 +370,50 @@ EOF fi } +assert_smtp_domain() { + if ! grep DISCOURSE_SMTP_DOMAIN $web_file >/dev/null 2>&1 + then + echo "Adding SMTP_DOMAIN placeholder to $web_file" + sed -i '/^.*DISCOURSE_SMTP_PASSWORD.*/a \ \ #DISCOURSE_SMTP_DOMAIN: discourse.example.com # (required by some providers)' $web_file + fi + if ! grep DISCOURSE_SMTP_DOMAIN $web_file >/dev/null 2>&1 + then + cat </dev/null 2>&1 + then + echo "Adding DISCOURSE_NOTIFICATION_EMAIL placeholder to $web_file" + sed -i '/^.*DISCOURSE_SMTP_PASSWORD.*/a \ \ #DISCOURSE_NOTIFICATION_EMAIL: nobody@discourse.example.com # (address to send notifications from)' $web_file + fi + if ! grep DISCOURSE_NOTIFICATION_EMAIL $web_file >/dev/null 2>&1 + then + cat <containers/app.yml > $YML + +hostname='new.myhost.com' +developer='new@mail.myhost.com' +smtp_address='new.myhostn.com' +smtp_port='2525' +smtp_user='newuser' +smtp_pass='new-smtp-pw' +notification='somuser@otherhost.com' +smtp_domain=otherhost.com # NOTE: script uses notification hostnme +letsencrypt='le-new@myhost.com' +maxmind='maxthisone' +$DIR/../discourse-setup --skip-connection-test --skip-rebuild < $YML +hostname='new.myhost.com' +developer='new-admin@mail.myhost.com' +smtp_address='new.myhostn.com' +smtp_port='2525' +smtp_user='newuser' +smtp_pass='new-smtp-pw' +notification='somuser@otherhost.com' +smtp_domain=otherhost.com # NOTE: script uses notification hostnme +letsencrypt='le-new@myhost.com' +maxmind='maxthisone' +$DIR/../discourse-setup --skip-connection-test --skip-rebuild <