From a4d321c56f4a873d2a5b0477e64dc65f14780fd1 Mon Sep 17 00:00:00 2001 From: tierno Date: Mon, 24 Oct 2016 08:47:46 +0000 Subject: [PATCH] enhance on database migration not prompt for pass if no needed Change-Id: Ia8cbebb09ea107c698965be56f79b24dde46de1f Signed-off-by: tierno --- database_utils/migrate_mano_db.sh | 33 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/database_utils/migrate_mano_db.sh b/database_utils/migrate_mano_db.sh index 9484131c..e69d8a5a 100755 --- a/database_utils/migrate_mano_db.sh +++ b/database_utils/migrate_mano_db.sh @@ -43,7 +43,7 @@ function usage(){ echo -e " if openmano_version is not provided it tries to get from openmanod.py using relative path" echo -e " OPTIONS" echo -e " -u USER database user. '$DBUSER' by default. Prompts if DB access fails" - echo -e " -p PASS database password. 'No password' by default. Prompts if DB access fails" + echo -e " -p PASS database password. 'No password' or 'manopw' by default. Prompts if DB access fails" echo -e " -P PORT database port. '$DBPORT' by default" echo -e " -h HOST database host. '$DBHOST' by default" echo -e " -d NAME database name. '$DBNAME' by default. Prompts if DB access fails" @@ -113,20 +113,23 @@ OPENMANO_VER_NUM=`printf "%d%03d%03d" ${VERSION_1} ${VERSION_2} ${VERSION_3}` TEMPFILE="$(mktemp -q --tmpdir "migratemanodb.XXXXXX")" trap 'rm -f "$TEMPFILE"' EXIT chmod 0600 "$TEMPFILE" -cat >"$TEMPFILE" </dev/null 2>&1 +DEF_EXTRA_FILE_PARAM="--defaults-extra-file=$TEMPFILE" +if [ -z "${DBPASS}" ] +then + password_ok="" + echo -e "[client]\nuser='${DBUSER}'\npassword='manopw'" > "$TEMPFILE" + mysql "$DEF_EXTRA_FILE_PARAM" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1 && DBPASS="manopw" + echo -e "[client]\nuser='${DBUSER}'\npassword=''" > "$TEMPFILE" + mysql "$DEF_EXTRA_FILE_PARAM" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1 && DBPASS="" +fi +echo -e "[client]\nuser='${DBUSER}'\npassword='${DBPASS}'" > "$TEMPFILE" + +#check and ask for database user password +while ! mysql "$DEF_EXTRA_FILE_PARAM" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1 do [ -n "$logintry" ] && echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)" [ -z "$logintry" ] && echo -e "\nProvide database name and credentials" @@ -135,11 +138,7 @@ do read -e -p "mysql user($DBUSER): " KK [ -n "$KK" ] && DBUSER="$KK" read -e -s -p "mysql password: " DBPASS - cat >"$TEMPFILE" < "$TEMPFILE" logintry="yes" echo done -- 2.25.1