From eb7eef02e80559f6a7c8adf53266c559b3117407 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Fri, 2 Mar 2018 15:13:34 -0800 Subject: [PATCH] install: Suppress initialize-database instructions when redundant. To do it, add a blob of getopt boilerplate at the top of the script; and also fix a couple of nits of shell style while here. --- scripts/lib/install | 3 +- scripts/setup/initialize-database | 49 +++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/scripts/lib/install b/scripts/lib/install index 4c5d5b8a0e..a9d3ec1d58 100755 --- a/scripts/lib/install +++ b/scripts/lib/install @@ -294,7 +294,6 @@ EOF exit 0 fi -# TODO suppress instructions on success -sudo -u zulip /home/zulip/deployments/current/scripts/setup/initialize-database +sudo -u zulip /home/zulip/deployments/current/scripts/setup/initialize-database --quiet sudo -u zulip /home/zulip/deployments/current/manage.py generate_realm_creation_link diff --git a/scripts/setup/initialize-database b/scripts/setup/initialize-database index a0f92eb541..762d2cf00f 100755 --- a/scripts/setup/initialize-database +++ b/scripts/setup/initialize-database @@ -1,8 +1,31 @@ #!/usr/bin/env bash -set -xe +set -e + +usage() { + echo "usage: initialize-database [--quiet]" >&2 + exit 1 +} + +args="$(getopt -o '' --long help,quiet -- "$@")" +eval "set -- $args" +while true; do + case "$1" in + --help) usage;; + --quiet) QUIET=1; shift;; + --) shift; break;; + *) usage;; + esac +done + +if [ "$#" -gt 0 ]; then + usage +fi + +set -x # Change to root directory of the checkout that we're running from -cd "$(dirname "$0")/../.." +THIS_DIR="$(dirname "$(readlink -f "$0")")" +cd "$THIS_DIR/../.." ./manage.py checkconfig @@ -17,7 +40,6 @@ if ! ./manage.py initialize_voyager_db; then echo " * supervisorctl stop all # to stop all services that might be accessing the database" echo " * scripts/setup/postgres-init-db # run as root to drop and re-create the database" echo -e "\033[0m" - set -x exit 1 fi @@ -32,13 +54,14 @@ if [ -e "/var/run/supervisor.sock" ]; then fi set +x -echo "Congratulations! You have successfully configured your Zulip database." -echo "If you haven't already, you should configure email in /etc/zulip/settings.py." -echo -echo "Next, run as the zulip user (use 'su zulip' if needed):" -echo -echo " /home/zulip/deployments/current/manage.py generate_realm_creation_link" -echo -echo "This generates a secure, single-use link that you you can use to setup " -echo "a Zulip organization from the convenience of your web browser." -set -x +if [ -z "$QUIET" ]; then + echo "Congratulations! You have successfully configured your Zulip database." + echo "If you haven't already, you should configure email in /etc/zulip/settings.py." + echo + echo "Next, run as the zulip user (use 'su zulip' if needed):" + echo + echo " /home/zulip/deployments/current/manage.py generate_realm_creation_link" + echo + echo "This generates a secure, single-use link that you you can use to setup " + echo "a Zulip organization from the convenience of your web browser." +fi