X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=database_utils%2Finit_mano_db.sh;h=224269bc1c2399b857c481bc97f95806f5ba1730;hb=ed1be4b1591c258748261f21947dc388c28c6fd9;hp=cbb76ef4055c7440296f02e6402e356ed3bc875b;hpb=462e3883d26612875a2978abdb8324109b41e081;p=osm%2FRO.git diff --git a/database_utils/init_mano_db.sh b/database_utils/init_mano_db.sh index cbb76ef4..224269bc 100755 --- a/database_utils/init_mano_db.sh +++ b/database_utils/init_mano_db.sh @@ -26,6 +26,7 @@ DBPASS="" DBHOST="localhost" DBPORT="3306" DBNAME="mano_db" +CREATEDB="" # Detect paths MYSQL=$(which mysql) @@ -43,6 +44,7 @@ function usage(){ echo -e " -h HOST database host. '$DBHOST' by default" echo -e " -d NAME database name. '$DBNAME' by default. Prompts if DB access fails" echo -e " --help shows this help" + echo -e " --createdb forces the deletion and creation of the database" } while getopts ":u:p:P:d:h:-:" o; do @@ -63,9 +65,14 @@ while getopts ":u:p:P:d:h:-:" o; do DBHOST="$OPTARG" ;; -) - [ "${OPTARG}" == "help" ] && usage && exit 0 - echo "Invalid option: --$OPTARG" >&2 && usage >&2 - exit 1 + if [ "${OPTARG}" == "help" ]; then + usage && exit 0 + elif [ "${OPTARG}" == "createdb" ]; then + CREATEDB="yes" + else + echo "Invalid option: --$OPTARG" >&2 && usage >&2 + exit 1 + fi ;; \?) echo "Invalid option: -$OPTARG" >&2 && usage >&2 @@ -89,24 +96,45 @@ DBPASS_="" [ -n "$DBPASS" ] && DBPASS_="-p$DBPASS" DBHOST_="-h$DBHOST" DBPORT_="-P$DBPORT" -while ! echo ";" | mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ >/dev/null 2>&1 + +TEMPFILE="$(mktemp -q --tmpdir "initmanodb.XXXXXX")" +trap 'rm -f "$TEMPFILE"' EXIT +chmod 0600 "$TEMPFILE" +cat >"$TEMPFILE" </dev/null 2>&1 do [ -n "$logintry" ] && echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)" [ -z "$logintry" ] && echo -e "\nProvide database 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_="" + cat >"$TEMPFILE" <