#!/bin/sh

set -eu

exists="$("${UV}" run --no-dev manage.py shell -c \
    'from django.contrib.auth import get_user_model; print(get_user_model().objects.filter(is_superuser=True).exists())' \
    2>/dev/null | tail -n 1)"

if [ "${exists}" = "True" ]; then
    echo "An administrator account already exists."
    exit 0
fi

DJANGO_SUPERUSER_USERNAME=rekono \
DJANGO_SUPERUSER_EMAIL=rekono@rekono.dev \
DJANGO_SUPERUSER_PASSWORD=rekono \
    "${UV}" run --no-dev manage.py createsuperuser --no-input
