aboutsummaryrefslogtreecommitdiffstats
path: root/docker/instance_init.sh
blob: f789a972906e6da8436ae038f1bda739e3badd9e (plain)
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
28
29
30
31
#!/bin/bash

MYSQL_IP=`echo $MYSQL_ADDR | cut -d: -f 1`
MYSQL_PORT=`echo $MYSQL_ADDR | cut -d: -f 2`

if [ $MYSQL_AUTH ]; then
    MYSQL_ROOT_USER=`echo $MYSQL_AUTH | cut -d: -f 1`
    MYSQL_ROOT_PASSWORD=`echo $MYSQL_AUTH | cut -d: -f 2`
else
    MYSQL_ROOT_USER="root"
    MYSQL_ROOT_PASSWORD="root"
fi

function create_database {
    cd /service/vfc/nfvo/catalog/resources/bin
    bash initDB.sh $MYSQL_ROOT_USER $MYSQL_ROOT_PASSWORD $MYSQL_PORT $MYSQL_IP

 }

function migrate_database {
    cd /service/vfc/nfvo/catalog
    python manage.py makemigrations database
    python manage.py migrate
}

GET_CATALOG_DB="show databases like 'nfvocatalog';"
CATALOG_DB=`mysql -u$MYSQL_ROOT_USER -p$MYSQL_ROOT_PASSWORD -P$MYSQL_PORT -h$MYSQL_IP -e "GET_CATALOG_DB"`
if [[ "$CATALOG_DB" == "" ]]; then
    create_database
    migrate_database
fi