FIX: discourse-setup MAXMIND works correctly

Ouch. This was worse than I thought.

Things fixed:

- consistent formatting (mostly that after `then` was indented by 4, not 2)
- fail if `DISCOURSE_MAXMIND_LICENSE_KEY` is not added to $web_file
- detect if `web_only.yml` exists 
- stop `web_only` if it exists rather than non-existing `app` (but why is it stopping it anyway?)
- don't try to `assert_maxmind_license_key` before `app.yml` exists
This commit is contained in:
Jay Pfaffman 2021-01-27 10:30:15 -08:00 committed by Rafael dos Santos Silva
parent 32c7b98716
commit 3063a97a2c
1 changed files with 128 additions and 116 deletions

View File

@ -185,7 +185,6 @@ check_disk_and_memory() {
fi
fi
free_disk="$(df /var | tail -n 1 | awk '{print $4}')"
if [ "$free_disk" -lt 5000 ]; then
echo "WARNING: Discourse requires at least 5GB free disk space. This system"
@ -317,11 +316,24 @@ read_default() {
}
assert_maxmind_license_key() {
if ! grep DISCOURSE_MAXMIND_LICENSE_KEY $web_file
if ! grep DISCOURSE_MAXMIND_LICENSE_KEY $web_file >/dev/null 2>&1
then
echo "Adding MAXMIND placeholder to $web_file"
sed -i '/^.*LETSENCRYPT_ACCOUNT_EMAIL.*/a \ \ #DISCOURSE_MAXMIND_LICENSE_KEY: 1234567890123456' $web_file
fi
if ! grep DISCOURSE_MAXMIND_LICENSE_KEY $web_file >/dev/null 2>&1
then
cat <<EOF
Adding DISCOURSE_MAXMIND_LICENSE_KEY to $web_file has failed! This
indicates either that your $web_file is very old or otherwise not
what the script expects or that there is a bug in this script. The
best solution for a novice is to delete $web_file and start over.
An expert might prefer to edit $web_file by hand.
EOF
read -p "Press return to continue or control-c to quit..."
fi
}
##
@ -711,7 +723,7 @@ validate_config() {
## template file names
##
if [ "$1" == "2container" ]
if [ "$1" == "2container" ] || [ -f containers/web_only.yml ]
then
app_name=web_only
data_name=data
@ -727,7 +739,7 @@ else
web_file=containers/$app_name.yml
data_file=containers/$app_name.yml
fi
changelog=/tmp/changelog
changelog=/tmp/changelog
##
## Check requirements before creating a copy of a config file we won't edit
@ -735,7 +747,6 @@ fi
check_root
check_and_install_docker
check_disk_and_memory
assert_maxmind_license_key
if [ -a "$web_file" ]
then
@ -750,7 +761,8 @@ then
cp $web_file containers/$BACKUP
echo "Stopping existing container in 5 seconds or Control-C to cancel."
sleep 5
./launcher stop app
assert_maxmind_license_key
./launcher stop $app_name
echo
else
check_ports