X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=database_utils%2Fmigrate_vim_db.sh;h=e008478d6c6dee45589f930e1188fec5a8d854b8;hb=115b64af89014d1e60caebbf32dc07dba98e2e86;hp=1d379acbc970629ef77a4939da4faadb4caa2638;hpb=24595390fde6736753946648ee083c178b60759c;p=osm%2Fopenvim.git diff --git a/database_utils/migrate_vim_db.sh b/database_utils/migrate_vim_db.sh index 1d379ac..e008478 100755 --- a/database_utils/migrate_vim_db.sh +++ b/database_utils/migrate_vim_db.sh @@ -43,7 +43,7 @@ function usage(){ echo -e " if openvim_version is not provided it tries to get from openvimd.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 'vimpw' 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" @@ -109,27 +109,41 @@ then fi OPENVIM_VER_NUM=`printf "%d%03d%03d" ${VERSION_1} ${VERSION_2} ${VERSION_3}` -#check and ask for database user password -DBUSER_="-u$DBUSER" -[ -n "$DBPASS" ] && DBPASS_="-p$DBPASS" +#Creating temporary file +TEMPFILE="$(mktemp -q --tmpdir "migratemanodb.XXXXXX")" +trap 'rm -f "$TEMPFILE"' EXIT +chmod 0600 "$TEMPFILE" + +#if password is missing, before prompting for it try without password and with "manopw" DBHOST_="-h$DBHOST" DBPORT_="-P$DBPORT" -while ! echo ";" | mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME >/dev/null 2>&1 +DEF_EXTRA_FILE_PARAM="--defaults-extra-file=$TEMPFILE" +if [ -z "${DBPASS}" ] +then + password_ok="" + echo -e "[client]\nuser='${DBUSER}'\npassword='vimpw'" > "$TEMPFILE" + mysql --defaults-extra-file="$TEMPFILE" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1 && DBPASS="vimpw" + echo -e "[client]\nuser='${DBUSER}'\npassword=''" > "$TEMPFILE" + mysql --defaults-extra-file="$TEMPFILE" $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" read -e -p "mysql database name($DBNAME): " KK [ -n "$KK" ] && DBNAME="$KK" read -e -p "mysql user($DBUSER): " KK - [ -n "$KK" ] && DBUSER="$KK" && DBUSER_="-u$DBUSER" + [ -n "$KK" ] && DBUSER="$KK" read -e -s -p "mysql password: " DBPASS - [ -n "$DBPASS" ] && DBPASS_="-p$DBPASS" - [ -z "$DBPASS" ] && DBPASS_="" + echo -e "[client]\nuser='${DBUSER}'\npassword='${DBPASS}'" > "$TEMPFILE" logintry="yes" echo done -DBCMD="mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME" +DBCMD="mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_ $DBNAME" #echo DBCMD $DBCMD #GET DATABASE VERSION