4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openmano
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
37 echo -e "Usage: $0 OPTIONS"
38 echo -e " Inits openmano database; deletes previous one and loads from ${DBNAME}_structure.sql"
40 echo -e " -u USER database user. '$DBUSER' by default. Prompts if DB access fails"
41 echo -e " -p PASS database password. 'No password' by default. Prompts if DB access fails"
42 echo -e " -P PORT database port. '$DBPORT' by default"
43 echo -e " -h HOST database host. '$DBHOST' by default"
44 # echo -e " -d NAME database name. '$DBNAME' by default. Prompts if DB access fails"
45 echo -e " --help shows this help"
48 while getopts ":u:p:P:h:-:" o
; do
66 [ "${OPTARG}" == "help" ] && usage
&& exit 0
67 echo "Invalid option: --$OPTARG" >&2 && usage
>&2
71 echo "Invalid option: -$OPTARG" >&2 && usage
>&2
75 echo "Option -$OPTARG requires an argument." >&2 && usage
>&2
86 #check and ask for database user password
89 [ -n "$DBPASS" ] && DBPASS_
="-p$DBPASS"
92 while ! echo ";" | mysql
$DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ >/dev
/null
2>&1
94 [ -n "$logintry" ] && echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)"
95 [ -z "$logintry" ] && echo -e "\nProvide database credentials"
96 # read -e -p "mysql database name($DBNAME): " KK
97 # [ -n "$KK" ] && DBNAME="$KK"
98 read -e -p "mysql user($DBUSER): " KK
99 [ -n "$KK" ] && DBUSER
="$KK" && DBUSER_
="-u$DBUSER"
100 read -e -s -p "mysql password: " DBPASS
101 [ -n "$DBPASS" ] && DBPASS_
="-p$DBPASS"
102 [ -z "$DBPASS" ] && DBPASS_
=""
107 #${DIRNAME}/quick_delete_db.sh $MUSER $MPASS $MDB $HOST $PORT
108 echo " loading ${DIRNAME}/${DBNAME}_structure.sql"
109 mysql
$DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ < ${DIRNAME}/${DBNAME}_structure.sql
111 echo " migrage database version"
112 ${DIRNAME}/migrate_mano_db.sh
$DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ -d$DBNAME