Use -v to check if variables are set in bash.

I _think_ this was added to bash in 4.1.2 or something. It is a better check
than -z which checks if the value of the variable is null or not.
This commit is contained in:
Abhilash Raj
2017-04-08 19:53:57 -07:00
parent 701825c2a3
commit 1cfee02611
2 changed files with 11 additions and 12 deletions

View File

@@ -33,7 +33,7 @@ function wait_for_postgres () {
#
# TODO: Check the database type and detect if it is up based on that. For now,
# assume that postgres is being used if DATABASE_URL is defined.
if [[ ! -v "$DATABASES_URL" ]]; then
if [[ ! -v DATABASES_URL ]]; then
echo "DATABASE_URL is not defined. Using sqlite database..."
export DATABASE_URL=sqlite:///mailman.db
export DATABASE_TYPE='sqlite'
@@ -41,22 +41,22 @@ if [[ ! -v "$DATABASES_URL" ]]; then
fi
if [[ "DATABASE_TYPE" = 'postgres' ]]
if [[ "$DATABASE_TYPE" = 'postgres' ]]
then
wait_for_postgres
fi
# Check if $MM_HOSTNAME is set, if not, set it to a default value.
# TODO: Factor this out to a function.
if [[ -z "$MM_HOSTNAME" ]]; then
if [[ ! -v MM_HOSTNAME ]]; then
export MM_HOSTNAME=mailman-core
fi
if [[ -z "$SMTP_HOST" ]]; then
if [[ ! -v SMTP_HOST ]]; then
export SMTP_HOST='172.19.199.1'
fi
if [[ -z "$SMTP_PORT" ]]; then
if [[ ! -v SMTP_PORT ]]; then
export SMTP_PORT=25
fi
@@ -98,15 +98,15 @@ then
fi
if [[ -z "$HYPERKITTY_API_KEY" ]]; then
if [[ ! -v HYPERKITTY_API_KEY ]]; then
echo "HYPERKITTY_API_KEY not defined, please set this environment variable..."
echo "exiting..."
exit 1
fi
if [[ -z "$HYPERKITTY_URL" ]]; then
if [[ -v HYPERKITTY_URL ]]; then
echo "HYPERKITTY_URL not set, using the default value of http://mailman-web:8000/hyperkitty"
HYPERKITTY_URL="http://mailman-web:8000/hyperkitty/"
export HYPERKITTY_URL="http://mailman-web:8000/hyperkitty/"
fi
# Generate a basic mailman-hyperkitty.cfg.

View File

@@ -61,7 +61,6 @@ if [[ ! $(pwd) == '/opt/mailman-web' ]]; then
fi
# Check if the logs directory is setup.
if [[ ! -e /opt/mailman-web-data/logs/mailmanweb.log ]]; then
echo "Creating log file for mailman web"
mkdir -p /opt/mailman-web-data/logs/
@@ -78,7 +77,7 @@ if [[ -e /opt/mailman-web-data/settings_local.py ]]; then
echo "Copying settings_local.py ..."
cp /opt/mailman-web-data/settings_local.py /opt/mailman-web/settings_local.py
else
echo "settings_local.py not found, it is highly recommended that you provide one/"
echo "settings_local.py not found, it is highly recommended that you provide one"
echo "Using default configuration to run."
fi
@@ -93,7 +92,7 @@ python manage.py migrate
# It can be changed by $UWSGI_LOG_URL environment variable, which if not set points
# to /opt/mailman-web/logs/uwsgi.log
# It can also point to a logging daemon accessible at a URL.
if [[ -z "$UWSGI_LOG_URL" ]]; then
if [[ ! -v UWSGI_LOG_URL ]]; then
echo "No UWSGI_LOG_URL defined, logging uwsgi to /opt/mailman-web-data/logs/uwsgi.log ..."
export UWSGI_LOG_URL='/opt/mailman-web-data/logs/uwsgi.log'
if [[ ! -e "$UWSGI_LOG_URL" ]]; then
@@ -101,7 +100,7 @@ if [[ -z "$UWSGI_LOG_URL" ]]; then
fi
fi
if [[ -z "$UWSGI_WSGI_FILE" ]]; then
if [[ ! -v UWSGI_WSGI_FILE ]]; then
export UWSGI_WSGI_FILE="wsgi.py"
export UWSGI_HTTP=:8000
export UWSGI_WORKERS=2