-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·27 lines (23 loc) · 1.15 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash -e
# check if it's the first time the docker is launched (db file is empty)
if [ "$(cat /usr/src/app/datas/secretkey.txt)" == "empty" ];then
python3 manage.py generate_secret_key --replace
cp -rf secretkey.txt datas/secretkey.txt && rm -f secretkey.txt
#check if command done its job
if [ -z ${ADMIN_LOGIN+x} ] || [ -z ${ADMIN_EMAIL+x} ] || [ -z ${ADMIN_PASSWORD+x} ];then
echo "ERROR You must give ADMIN_LOGIN, ADMIN_EMAIL and ADMIN_PASSWORD environnment variables"
exit 1
else
python3 manage.py shell -c "from django.contrib.auth.models import User; User.objects.create_superuser('$ADMIN_LOGIN', '$ADMIN_EMAIL', '$ADMIN_PASSWORD')"
python3 manage.py drf_create_token "$ADMIN_LOGIN"
fi
fi
# check if mandatory env variables is given
if [ -z ${HOSTNAME+x} ];then
echo "for security reason give HOSTNAME environment variable"
else
TRUE_IP=`hostname -I | awk '{$1=$1};1'` # Adding in case of docker
sed -i "s/ALLOWED_HOSTS = \['.*'\]/ALLOWED_HOSTS = \[$HOSTNAME,'$TRUE_IP','127.0.0.1'\]/" wishitch/settings.py
fi
python3 manage.py collectstatic --noinput
python3 manage.py runserver 0.0.0.0:8000