Skip to content
Snippets Groups Projects
01_install 1.67 KiB
Newer Older
#!/bin/bash
m431m's avatar
m431m committed

create_link()
{
    ln -s $1 $2 2> /dev/null
    if [ $? -eq 0 ]; then
        echo "[  OK  ] Link created: ${1}->${2}"
    else
        echo "[FAILED] No such file or directory: ${1}"
        exit 1
    fi
}
m431m's avatar
m431m committed

echo "Starting Django projet"
cd $APP_PATH/
marker_file="marker_file_step_01"
if [ -f $marker_file ]; then
    echo "$marker_file already exists"
else
    echo "$marker_file does not exist"
    django-admin startproject config .

    create_link src/onegeo_suite/ .

    # Handle Django config files
    if [ -f "config/routers.py" ]; then
        rm config/routers.py
m431m's avatar
m431m committed
    cp src/docker/routers.py config/routers.py

    if [ -f "config/settings.py" ]; then
        rm config/settings.py
    fi
m431m's avatar
m431m committed
    cp src/docker/settings.py config/settings.py

    if [ -f "config/triggers.py" ]; then
        rm config/triggers.py
    fi
m431m's avatar
m431m committed
    cp src/docker/triggers.py config/triggers.py

    if [ -f "config/urls.py" ]; then
        rm config/urls.py
    fi
    cp src/docker/urls.py config/urls.py
    cp src/docker/auth.py config/auth.py

    # Wait for the postgres server
m431m's avatar
m431m committed
    echo "Waiting for database"
    i=1
    while true
    do
        if  $(nc -z ${DB_HOST} 5432) ; then
            echo "[${DB_HOST}] The database server is ready."
            break
        fi
        echo "[Retry: $i] The database server is not ready. Next attempt in ${TIME_SLEEP:-1}s"
        sleep ${TIME_SLEEP:-1}
        ((i++))
    done

    # Build database
    python manage.py migrate
    # Build static files
    python manage.py collectstatic --no-input
    # build i18n *.mo files
    python manage.py compilemessages --locale=fr

    echo "Ok" > $marker_file
fi

echo "$(basename $0) complete."