2017-04-19 16:48:21 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2017-11-29 15:08:55 +01:00
|
|
|
# wait shortly and then run db migrations (retry on error)
|
2017-08-30 11:09:24 +02:00
|
|
|
while ! ./manage.py migrate 2>&1; do
|
2017-11-29 15:08:55 +01:00
|
|
|
echo "⏳ Waiting on DB..."
|
|
|
|
sleep 3
|
2017-04-19 16:48:21 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
# create superuser silently
|
2017-12-13 15:50:30 +01:00
|
|
|
if [ -z ${SUPERUSER_NAME+x} ]; then
|
2017-11-29 15:08:55 +01:00
|
|
|
SUPERUSER_NAME='admin'
|
2017-04-19 16:48:21 +02:00
|
|
|
fi
|
2017-12-13 15:50:30 +01:00
|
|
|
if [ -z ${SUPERUSER_EMAIL+x} ]; then
|
2017-11-29 15:08:55 +01:00
|
|
|
SUPERUSER_EMAIL='admin@example.com'
|
|
|
|
fi
|
2017-12-13 15:50:30 +01:00
|
|
|
if [ -z ${SUPERUSER_PASSWORD+x} ]; then
|
|
|
|
if [ -f "/run/secrets/superuser_password" ]; then
|
|
|
|
SUPERUSER_PASSWORD="$(< /run/secrets/superuser_password)"
|
|
|
|
else
|
|
|
|
SUPERUSER_PASSWORD='admin'
|
|
|
|
fi
|
2017-11-29 15:08:55 +01:00
|
|
|
fi
|
2017-12-13 15:50:30 +01:00
|
|
|
if [ -z ${SUPERUSER_API_TOKEN+x} ]; then
|
|
|
|
if [ -f "/run/secrets/superuser_api_token" ]; then
|
|
|
|
SUPERUSER_API_TOKEN="$(< /run/secrets/superuser_api_token)"
|
|
|
|
else
|
|
|
|
SUPERUSER_API_TOKEN='0123456789abcdef0123456789abcdef01234567'
|
|
|
|
fi
|
2017-11-29 15:08:55 +01:00
|
|
|
fi
|
|
|
|
|
2018-04-19 11:55:41 +02:00
|
|
|
echo "💡 Username: ${SUPERUSER_NAME}, E-Mail: ${SUPERUSER_EMAIL}"
|
2017-04-21 13:43:44 +02:00
|
|
|
|
2018-07-24 10:56:46 +02:00
|
|
|
./manage.py shell --interface python << END
|
2017-04-21 13:43:44 +02:00
|
|
|
from django.contrib.auth.models import User
|
2017-11-29 15:08:55 +01:00
|
|
|
from users.models import Token
|
2017-04-21 13:43:44 +02:00
|
|
|
if not User.objects.filter(username='${SUPERUSER_NAME}'):
|
2017-11-29 15:08:55 +01:00
|
|
|
u=User.objects.create_superuser('${SUPERUSER_NAME}', '${SUPERUSER_EMAIL}', '${SUPERUSER_PASSWORD}')
|
|
|
|
Token.objects.create(user=u, key='${SUPERUSER_API_TOKEN}')
|
2017-04-21 13:43:44 +02:00
|
|
|
END
|
2017-04-19 16:48:21 +02:00
|
|
|
|
2018-02-16 10:25:26 +01:00
|
|
|
for script in /opt/netbox/startup_scripts/*.py; do
|
|
|
|
echo "⚙️ Executing '$script'"
|
2018-07-24 10:56:46 +02:00
|
|
|
./manage.py shell --interface python < "${script}"
|
2018-01-24 09:21:55 +01:00
|
|
|
done
|
|
|
|
|
2017-04-19 16:48:21 +02:00
|
|
|
# copy static files
|
2017-08-30 11:09:24 +02:00
|
|
|
./manage.py collectstatic --no-input
|
2017-04-19 16:48:21 +02:00
|
|
|
|
2017-11-29 15:08:55 +01:00
|
|
|
echo "✅ Initialisation is done."
|
2017-08-30 11:09:56 +02:00
|
|
|
|
2018-02-16 10:25:26 +01:00
|
|
|
# launch whatever is passed by docker
|
|
|
|
# (i.e. the RUN instruction in the Dockerfile)
|
2017-08-30 11:09:56 +02:00
|
|
|
exec ${@}
|