Files
taiga/create-superuser.sh.tmpl
2026-03-10 12:57:04 -04:00

57 lines
1.3 KiB
Bash

#!/bin/bash
set -e
file_env() {
var="$1"
fileVar="${var}_FILE"
def="${2:-}"
eval "var_val=\${$var}"
eval "file_val=\${$fileVar}"
if [ -n "$var_val" ] && [ -n "$file_val" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
val="$def"
if [ -n "$var_val" ]; then
val="$var_val"
elif [ -n "$file_val" ]; then
val="$(cat "$file_val")"
fi
export "$var=$val"
unset "$fileVar"
}
file_env "POSTGRES_PASSWORD"
file_env "RABBITMQ_PASS"
file_env "TAIGA_SECRET_KEY"
echo "Waiting for Postgres..."
TIMEOUT=30
i=0
until (echo > /dev/tcp/$POSTGRES_HOST/5432) 2>/dev/null; do
i=$((i+1))
if [ $i -ge $TIMEOUT ]; then
echo "Postgres did not start within $TIMEOUT seconds."
exit 1
fi
sleep 1
done
echo "Waiting for Taiga Back..."
until python -m http.client -c 'GET /api/v1/' -H 'Host: http://taiga-back:8000' >/dev/null; do sleep 3; done
sleep 30 # otherwise there can be some django error
python manage.py shell <<EOF
from django.contrib.auth import get_user_model
User = get_user_model()
if not User.objects.filter(username="${DJANGO_SUPERUSER_USERNAME}").exists():
User.objects.create_superuser('${DJANGO_SUPERUSER_USERNAME}','${DJANGO_SUPERUSER_EMAIL}', '{{ secret "django_password" }}')
EOF
echo "Django superuser created or found"