Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set nounset on Bash scripts (fixes #860) #1760

Merged
merged 1 commit into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions tools/azure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ if [[ -z "${DOCCANO_ADMIN_CONTACT_EMAIL}" ]]; then echo "Missing DOCCANO_ADMIN_C
if [[ -z "${DOCCANO_ADMIN_PASSWORD}" ]]; then echo "Missing DOCCANO_ADMIN_PASSWORD environment variable" >&2; exit 1; fi
if ! az account show >/dev/null; then echo "Must be logged into Azure" >&2; exit 2; fi

set -o nounset

az group create \
--location "${DOCCANO_LOCATION}" \
--name "${DOCCANO_RESOURCE_GROUP}"
Expand Down
5 changes: 3 additions & 2 deletions tools/create-admin.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env bash

if [[ "$#" -ne 3 ]]; then echo "Usage: $0 <username> <email> <password>" >&2; exit 1; fi

set -o errexit
set -o nounset

if [[ "$#" -ne 3 ]]; then echo "Usage: $0 <username> <email> <password>" >&2; exit 1; fi

python app/manage.py wait_for_db
python app/manage.py migrate
Expand Down
4 changes: 4 additions & 0 deletions tools/create-package.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset

mkdir -p backend/client

cd frontend
Expand Down
2 changes: 2 additions & 0 deletions tools/dev-celery.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset

cd "/src/backend"

Expand Down
9 changes: 8 additions & 1 deletion tools/dev-django.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/usr/bin/env bash

set -o errexit

if [[ -z "${ADMIN_USERNAME}" ]]; then echo "Missing ADMIN_USERNAME environment variable" >&2; exit 1; fi
if [[ -z "${ADMIN_PASSWORD}" ]]; then echo "Missing ADMIN_PASSWORD environment variable" >&2; exit 1; fi
if [[ -z "${ADMIN_EMAIL}" ]]; then echo "Missing ADMIN_EMAIL environment variable" >&2; exit 1; fi

set -o nounset

app="/src/backend"

echo "Initializing database"
Expand All @@ -18,4 +25,4 @@ if [[ -n "${ADMIN_USERNAME}" ]] && [[ -n "${ADMIN_PASSWORD}" ]] && [[ -n "${ADMI
fi

echo "Starting django"
python -u "${app}/manage.py" runserver 0.0.0.0:8000
python -u "${app}/manage.py" runserver ${HOST:-0.0.0.0}:${PORT:-8000}
1 change: 1 addition & 0 deletions tools/dev-nuxt.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset

root="$(dirname "$0")/.."
app="${root}/frontend"
Expand Down
6 changes: 6 additions & 0 deletions tools/heroku.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

set -o errexit

if [[ -z "${ADMIN_USER_NAME}" ]]; then echo "Missing ADMIN_USER_NAME environment variable" >&2; exit 1; fi
if [[ -z "${ADMIN_PASSWORD}" ]]; then echo "Missing ADMIN_PASSWORD environment variable" >&2; exit 1; fi
if [[ -z "${ADMIN_CONTACT_EMAIL}" ]]; then echo "Missing ADMIN_CONTACT_EMAIL environment variable" >&2; exit 1; fi

set -o nounset

python /doccano/backend/manage.py migrate
if [ -n "$ADMIN_USER_NAME" ]; then
python /doccano/backend/manage.py create_admin --noinput --username="$ADMIN_USER_NAME" --email="$ADMIN_CONTACT_EMAIL" --password="$ADMIN_PASSWORD"
Expand Down
3 changes: 3 additions & 0 deletions tools/install-mssql.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset

# parse arguments
mode="prod"
for opt in "$@"; do
Expand Down
2 changes: 2 additions & 0 deletions tools/prod-celery.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset

cd /backend

Expand Down
8 changes: 7 additions & 1 deletion tools/prod-django.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

set -o errexit

if [[ -z "${ADMIN_USERNAME}" ]]; then echo "Missing ADMIN_USERNAME environment variable" >&2; exit 1; fi
if [[ -z "${ADMIN_PASSWORD}" ]]; then echo "Missing ADMIN_PASSWORD environment variable" >&2; exit 1; fi
if [[ -z "${ADMIN_EMAIL}" ]]; then echo "Missing ADMIN_EMAIL environment variable" >&2; exit 1; fi

set -o nounset

echo "Making staticfiles"
static_dir=staticfiles
if [[ ! -d $static_dir ]] || [[ -z $(ls -A $static_dir) ]]; then
Expand All @@ -25,4 +31,4 @@ if [[ -n "${ADMIN_USERNAME}" ]] && [[ -n "${ADMIN_PASSWORD}" ]] && [[ -n "${ADMI
fi

echo "Starting django"
gunicorn --bind="0.0.0.0:${PORT:-8000}" --workers="${WORKERS:-4}" config.wsgi --timeout 300
gunicorn --bind="${HOST:-0.0.0.0}:${PORT:-8000}" --workers="${WORKERS:-4}" config.wsgi --timeout 300
9 changes: 9 additions & 0 deletions tools/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

set -o errexit

if [[ -z "${ADMIN_USERNAME}" ]]; then echo "Missing ADMIN_USERNAME environment variable" >&2; exit 1; fi
if [[ -z "${ADMIN_PASSWORD}" ]]; then echo "Missing ADMIN_PASSWORD environment variable" >&2; exit 1; fi
if [[ -z "${ADMIN_EMAIL}" ]]; then echo "Missing ADMIN_EMAIL environment variable" >&2; exit 1; fi
if [[ -z "${PORT}" ]]; then echo "Missing PORT environment variable" >&2; exit 1; fi
if [[ -z "${WORKERS}" ]]; then echo "Missing WORKERS environment variable" >&2; exit 1; fi
if [[ -z "${CELERY_WORKERS}" ]]; then echo "Missing CELERY_WORKERS environment variable" >&2; exit 1; fi

set -o nounset

echo "Making staticfiles"
static_dir=staticfiles
mkdir -p client/dist/static
Expand Down