From: mirabal Date: Thu, 20 Apr 2017 13:18:39 +0000 (+0200) Subject: Add --uninstall to install-db-server.sh X-Git-Tag: v2.0.0~20 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=ee19576ffab403bf0218974ed96c98dc0375b507;p=osm%2Fopenvim.git Add --uninstall to install-db-server.sh - Parameter --uninstall delete existing DB but keeps the user Change-Id: I374d56776211f0a9fcdd33d166cb4e7dc15de363 Signed-off-by: mirabal --- diff --git a/database_utils/install-db-server.sh b/database_utils/install-db-server.sh index e393395..4d816a5 100755 --- a/database_utils/install-db-server.sh +++ b/database_utils/install-db-server.sh @@ -13,6 +13,7 @@ function usage(){ echo -e " -h --help: show this help" echo -e " --forcedb: reinstall vim_db DB, deleting previous database if exists and creating a new one" echo -e " --no-install-packages: use this option to skip updating and installing the requires packages. This avoid wasting time if you are sure requires packages are present e.g. because of a previous installation" + echo -e " --unistall: Delete DB, by default vim_db" } @@ -59,6 +60,16 @@ function _init_db(){ su $SUDO_USER -c "${DIRNAME}/init_vim_db.sh -u $DB_USER -p $DB_PASS -d ${DB_NAME}" || ! echo "Failed while initializing database" || exit 1 } +function _uninstall_db(){ +echo ' + ################################################################# + ##### DELETE DATABASE ##### + #################################################################' + DBDELETEPARAM="" + [[ -n $QUIET_MODE ]] && DBDELETEPARAM="-f" + mysqladmin --defaults-extra-file=$TEMPFILE -s drop ${DB_NAME} $DBDELETEPARAM || ! echo "Could not delete ${DB_NAME} database" || exit 1 + +} function db_exists() { RESULT=`mysqlshow --defaults-extra-file="$2" | grep -v Wildcard | grep -o $1` if [ "$RESULT" == "$1" ]; then @@ -77,6 +88,7 @@ DBPASSWD_PARAM="" QUIET_MODE="" FORCEDB="" NO_PACKAGES="" +UNINSTALL="" while getopts ":U:P:d:u:p:hiq-:" o; do case "${o}" in U) @@ -107,6 +119,7 @@ while getopts ":U:P:d:u:p:hiq-:" o; do [ "${OPTARG}" == "forcedb" ] && FORCEDB="y" && continue [ "${OPTARG}" == "quiet" ] && export QUIET_MODE=yes && export DEBIAN_FRONTEND=noninteractive && continue [ "${OPTARG}" == "no-install-packages" ] && export NO_PACKAGES=yes && continue + [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2 exit 1 ;; @@ -158,9 +171,17 @@ then done fi +if [[ ! -z "$UNINSTALL" ]] +then + _uninstall_db + exit +fi + + if [[ -z "$NO_PACKAGES" ]] then _create_db _init_db fi +