Skip to content

Commit

Permalink
Fix shellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik committed Jan 11, 2024
1 parent 4bbc70f commit 3bbe6f3
Show file tree
Hide file tree
Showing 22 changed files with 158 additions and 148 deletions.
13 changes: 7 additions & 6 deletions dc-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
bash ./docker/docker-compose-check.sh
if [[ $? -eq 1 ]]; then exit 1; fi

# Building images for all configurations
# The docker build doesn't supply any environment variables to the Dockerfile, so we can use any profile.

if [ $# -eq 0 ]
then
echo "Building docker compose"
# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env build
else
echo "Building docker compose with additional parameter $1 ..."
# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env build "$1"
fi

# Building images for all configurations
# The docker build doesn't supply any environment variables to the Dockerfile, so we can use any profile.

# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env build $1
13 changes: 7 additions & 6 deletions dc-down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
bash ./docker/docker-compose-check.sh
if [[ $? -eq 1 ]]; then exit 1; fi

# Stopping containers for all configurations
# The environment must be provided but it doesn't make a difference which one

if [ $# -eq 0 ]
then
echo "Stopping docker compose and removing containers"
# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env down
else
echo "Stopping docker compose and removing containers with additional parameter $1 ..."
# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env down "$1"
fi

# Stopping containers for all configurations
# The environment must be provided but it doesn't make a difference which one

# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env down $1
13 changes: 7 additions & 6 deletions dc-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
bash ./docker/docker-compose-check.sh
if [[ $? -eq 1 ]]; then exit 1; fi

# Stopping containers for all configurations
# The environment must be provided but it doesn't make a difference which one

if [ $# -eq 0 ]
then
echo "Stopping docker compose"
# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env stop
else
echo "Stopping docker compose with additional parameter $1 ..."
# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env stop "$1"
fi

# Stopping containers for all configurations
# The environment must be provided but it doesn't make a difference which one

# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env stop $1
10 changes: 5 additions & 5 deletions dc-unittest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ while [[ $# -gt 0 ]]; do
usage
exit 0
;;
-*|--*)
-*)
echo "Unknown option $1"
usage
exit 1
Expand All @@ -53,9 +53,9 @@ while [[ $# -gt 0 ]]; do
esac
done

if [ -z $PROFILE ]
if [ -z "$PROFILE" ]
then
if [ -z $DD_PROFILE ]
if [ -z "$DD_PROFILE" ]
then
echo "No profile supplied."
usage
Expand All @@ -65,7 +65,7 @@ then
fi
fi

if [ -z $TEST_CASE ]
if [ -z "$TEST_CASE" ]
then
echo "No test case supplied."
usage
Expand All @@ -75,4 +75,4 @@ fi
echo "Running docker compose unit tests with profile $PROFILE and test case $TEST_CASE ..."

# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile $PROFILE --env-file ./docker/environments/$PROFILE.env exec uwsgi bash -c "python manage.py test $TEST_CASE -v2 --keepdb"
docker compose --profile "$PROFILE" --env-file "./docker/environments/$PROFILE.env" exec uwsgi bash -c "python manage.py test $TEST_CASE -v2 --keepdb"
4 changes: 2 additions & 2 deletions dc-up-d.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [[ $? -eq 1 ]]; then exit 1; fi

if [ $# -eq 0 ]
then
if [ -z $DD_PROFILE ]
if [ -z "$DD_PROFILE" ]
then
echo "No profile supplied, running default: postgres-redis"
PROFILE="postgres-redis"
Expand All @@ -29,4 +29,4 @@ fi
echo "Starting docker compose with profile $PROFILE in the background ..."

# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile $PROFILE --env-file ./docker/environments/$PROFILE.env up --no-deps -d
docker compose --profile "$PROFILE" --env-file "./docker/environments/$PROFILE.env" up --no-deps -d
4 changes: 2 additions & 2 deletions dc-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ bash ./docker/docker-compose-check.sh
if [[ $? -eq 1 ]]; then exit 1; fi

if [ $# -eq 0 ]; then
if [ -z $DD_PROFILE ]
if [ -z "$DD_PROFILE" ]
then
echo "No profile supplied, running default: postgres-redis"
PROFILE="postgres-redis"
Expand All @@ -28,4 +28,4 @@ fi
echo "Starting docker compose with profile $PROFILE in the foreground ..."

# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile $PROFILE --env-file ./docker/environments/$PROFILE.env up --no-deps
docker compose --profile "$PROFILE" --env-file "./docker/environments/$PROFILE.env" up --no-deps
6 changes: 3 additions & 3 deletions docker/docker-compose-check.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

main=`docker compose version --short | cut -d '.' -f 1`
minor=`docker compose version --short | cut -d '.' -f 2`
current=`docker compose version --short`
main=$(docker compose version --short | cut -d '.' -f 1)
minor=$(docker compose version --short | cut -d '.' -f 2)
current=$(docker compose version --short)

echo 'Checking docker compose version'
if [[ $main -lt 2 ]]; then
Expand Down
2 changes: 1 addition & 1 deletion docker/dojo-data.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#Exports and loads sample data for dojo

if [ $# > 1 ]
if [ $# -gt 1 ]
then
if [[ "$1" = "load" ]]
then
Expand Down
4 changes: 2 additions & 2 deletions docker/entrypoint-celery-beat.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

Check warning on line 1 in docker/entrypoint-celery-beat.sh

View check run for this annotation

DryRunSecurity / Configured Sensitive Files Check

Sensitive File Edit

This file edit was detected to be sensitive according to the DryRun Security Configuration for this repository. Any edit to this file by an Author not in the allowedAuthors list will be considered sensitive.
umask 0002

id
Expand All @@ -7,7 +7,7 @@ id
FILES=$(ls /app/docker/extra_settings/* 2>/dev/null)
NUM_FILES=$(echo "$FILES" | wc -w)
if [ "$NUM_FILES" -gt 0 ]; then
COMMA_LIST=$(echo $FILES | tr -s '[:blank:]' ', ')
COMMA_LIST=$(echo "$FILES" | tr -s '[:blank:]' ', ')
echo "============================================================"
echo " Overriding DefectDojo's local_settings.py with multiple"
echo " Files: $COMMA_LIST"
Expand Down
14 changes: 8 additions & 6 deletions docker/entrypoint-celery-worker.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

Check warning on line 1 in docker/entrypoint-celery-worker.sh

View check run for this annotation

DryRunSecurity / Configured Sensitive Files Check

Sensitive File Edit

This file edit was detected to be sensitive according to the DryRun Security Configuration for this repository. Any edit to this file by an Author not in the allowedAuthors list will be considered sensitive.
umask 0002

id
Expand All @@ -7,7 +7,7 @@ id
FILES=$(ls /app/docker/extra_settings/* 2>/dev/null)
NUM_FILES=$(echo "$FILES" | wc -w)
if [ "$NUM_FILES" -gt 0 ]; then
COMMA_LIST=$(echo $FILES | tr -s '[:blank:]' ', ')
COMMA_LIST=$(echo "$FILES" | tr -s '[:blank:]' ', ')
echo "============================================================"
echo " Overriding DefectDojo's local_settings.py with multiple"
echo " Files: $COMMA_LIST"
Expand All @@ -25,8 +25,10 @@ done
echo

if [ "${DD_CELERY_WORKER_POOL_TYPE}" = "prefork" ]; then
EXTRA_PARAMS="--autoscale=${DD_CELERY_WORKER_AUTOSCALE_MAX},${DD_CELERY_WORKER_AUTOSCALE_MIN}
--prefetch-multiplier=${DD_CELERY_WORKER_PREFETCH_MULTIPLIER}"
EXTRA_PARAMS=("--autoscale=${DD_CELERY_WORKER_AUTOSCALE_MAX},${DD_CELERY_WORKER_AUTOSCALE_MIN}"
"--prefetch-multiplier=${DD_CELERY_WORKER_PREFETCH_MULTIPLIER}")
else
EXTRA_PARAMS=()
fi

# do the check with Django stack
Expand All @@ -36,5 +38,5 @@ exec celery --app=dojo \
worker \
--loglevel="${DD_CELERY_LOG_LEVEL}" \
--pool="${DD_CELERY_WORKER_POOL_TYPE}" \
--concurrency=${DD_CELERY_WORKER_CONCURRENCY:-1} \
${EXTRA_PARAMS}
--concurrency="${DD_CELERY_WORKER_CONCURRENCY:-1}" \
"${EXTRA_PARAMS[@]}"
19 changes: 10 additions & 9 deletions docker/entrypoint-initializer.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

Check warning on line 1 in docker/entrypoint-initializer.sh

View check run for this annotation

DryRunSecurity / Configured Sensitive Files Check

Sensitive File Edit

This file edit was detected to be sensitive according to the DryRun Security Configuration for this repository. Any edit to this file by an Author not in the allowedAuthors list will be considered sensitive.

initialize_data()
{
Expand Down Expand Up @@ -40,7 +40,7 @@ fi
FILES=$(ls /app/docker/extra_settings/* 2>/dev/null)
NUM_FILES=$(echo "$FILES" | wc -w)
if [ "$NUM_FILES" -gt 0 ]; then
COMMA_LIST=$(echo $FILES | tr -s '[:blank:]' ', ')
COMMA_LIST=$(echo "$FILES" | tr -s '[:blank:]' ', ')
echo "============================================================"
echo " Overriding DefectDojo's local_settings.py with multiple"
echo " Files: $COMMA_LIST"
Expand All @@ -67,7 +67,7 @@ done
echo

echo "Checking ENABLE_AUDITLOG"
cat <<EOD | python manage.py shell
cat <<EOD | if ! python manage.py shell
from django.db import connections, DEFAULT_DB_ALIAS
from django.db.utils import ProgrammingError
from dojo.settings import settings
Expand Down Expand Up @@ -99,7 +99,6 @@ if 'enable_auditlog' in raw_row: # db is not migrated yet
else:
print("Database has been already migrated. Nothing to check.")
EOD
if [ $? -ne 0 ]
then
echo "You have set 'enable_auditlog' to False in the past. It is not possible to manage auditlog in System settings anymore. If you would like to keep auditlog disabled, you need to set environmental variable DD_ENABLE_AUDITLOG to False for all Django containers (uwsgi, celeryworker & initializer)."
echo "Or there is some other error in checking script. Check logs of this container."
Expand All @@ -114,7 +113,7 @@ python3 manage.py migrate
echo "Admin user: ${DD_ADMIN_USER}"
ADMIN_EXISTS=$(echo "SELECT * from auth_user;" | python manage.py dbshell | grep "${DD_ADMIN_USER}")
# Abort if the admin user already exists, instead of giving a new fake password that won't work
if [ ! -z "$ADMIN_EXISTS" ]
if [ -n "$ADMIN_EXISTS" ]
then
echo "Admin password: Initialization detected that the admin user ${DD_ADMIN_USER} already exists in your database."
echo "If you don't remember the ${DD_ADMIN_USER} password, you can create a new superuser with:"
Expand All @@ -126,14 +125,16 @@ fi

if [ -z "${DD_ADMIN_PASSWORD}" ]
then
export DD_ADMIN_PASSWORD="$(cat /dev/urandom | LC_ALL=C tr -dc a-zA-Z0-9 | \
DD_ADMIN_PASSWORD="$(LC_ALL=C tr -dc a-zA-Z0-9 < /dev/urandom | \
head -c 22)"
export DD_ADMIN_PASSWORD
echo "Admin password: ${DD_ADMIN_PASSWORD}"
fi

if [ -z "${DD_JIRA_WEBHOOK_SECRET}" ]
then
export DD_JIRA_WEBHOOK_SECRET="$(uuidgen)"
DD_JIRA_WEBHOOK_SECRET="$(uuidgen)"
export DD_JIRA_WEBHOOK_SECRET
echo "JIRA Webhook Secret: ${DD_JIRA_WEBHOOK_SECRET}"
fi

Expand Down Expand Up @@ -161,9 +162,9 @@ EOD

echo "Importing extra fixtures"
# If there is extra fixtures, load them
for i in $(ls dojo/fixtures/extra_*.json | sort -n 2>/dev/null) ; do
for i in $(find dojo/fixtures/extra_*.json | sort -n 2>/dev/null) ; do
echo "Loading $i"
python3 manage.py loaddata ${i%.*}
python3 manage.py loaddata "${i%.*}"
done

echo "Installing watson search index"
Expand Down
Loading

0 comments on commit 3bbe6f3

Please sign in to comment.