Enhance install-openvim script to add same options as in RO 72/1772/1
authortierno <alfonso.tiernosepulveda@telefonica.com>
Fri, 5 May 2017 13:51:47 +0000 (15:51 +0200)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Fri, 5 May 2017 13:51:47 +0000 (15:51 +0200)
Change-Id: Ib50749c25be41f7387d3a5bed686e9b720e0a72a
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
scripts/initopenvim.sh
scripts/install-openvim.sh

index 2fb3439..1bd152a 100755 (executable)
@@ -58,7 +58,8 @@ function is_valid_uuid(){
 
 
 #process options
 
 
 #process options
-source ${DIRNAME}/get-options.sh "force:f delete:d delete-all port:p= admin-port:P= screen-name= help:h dbname= insert-bashrc" $* || $_exit 1
+source ${DIRNAME}/get-options.sh \
+    "force:f delete:d delete-all port:p= admin-port:P= screen-name= help:h dbname= insert-bashrc" $* || $_exit 1
 
 #check correct arguments
 action_list=""
 
 #check correct arguments
 action_list=""
index 5f0867f..7fba365 100755 (executable)
 # contact with: nfvlabs@tid.es
 ##
 
 # contact with: nfvlabs@tid.es
 ##
 
-#ONLY TESTED for Ubuntu 14.10 14.04 16.04, CentOS7 and RHEL7
+#ONLY TESTED in Ubuntu 16.04   partially tested in Ubuntu 14.10 14.04 16.04, CentOS7 and RHEL7
 #Get needed packages, source code and configure to run openvim
 #Ask for database user and password if not provided
 
 #Get needed packages, source code and configure to run openvim
 #Ask for database user and password if not provided
 
-
-
 function usage(){
     echo -e "usage: sudo $0 [OPTIONS]"
     echo -e "Install last stable source code in ./openvim and the needed packages"
 function usage(){
     echo -e "usage: sudo $0 [OPTIONS]"
     echo -e "Install last stable source code in ./openvim and the needed packages"
@@ -34,18 +32,20 @@ function usage(){
     echo -e "  OPTIONS"
     echo -e "     -u USER:    database admin user. 'root' by default. Prompts if needed"
     echo -e "     -p PASS:    database admin password to be used or installed. Prompts if needed"
     echo -e "  OPTIONS"
     echo -e "     -u USER:    database admin user. 'root' by default. Prompts if needed"
     echo -e "     -p PASS:    database admin password to be used or installed. Prompts if needed"
-    echo -e "     -q --quiet: install in an unattended mode"
+    echo -e "     -q --quiet: install in unattended mode"
     echo -e "     -h --help:  show this help"
     echo -e "     --develop:  install last version for developers, and do not configure as a service"
     echo -e "     -h --help:  show this help"
     echo -e "     --develop:  install last version for developers, and do not configure as a service"
-    echo -e "     --force:    makes idenpotent, delete previous installations folders if needed"
+    echo -e "     --forcedb:  reinstall vim_db DB, deleting previous database if exists and creating a new one"
+    echo -e "     --updatedb: do not reinstall vim_db DB if it exists, just update database"
+    echo -e "     --force:    makes idenpotent, delete previous installations folders if needed. It assumes --updatedb if --forcedb option is not provided"
     echo -e "     --noclone:  assumes that openvim was cloned previously and that this script is run from the local repo"
     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 "     --noclone:  assumes that openvim was cloned previously and that this script is run from the local repo"
     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 "     --no-db: do not insall mysql server"
+    echo -e "     --no-db: do not install mysql server"
 }
 
 function install_packages(){
     [ -x /usr/bin/apt-get ] && apt-get install -y $*
 }
 
 function install_packages(){
     [ -x /usr/bin/apt-get ] && apt-get install -y $*
-    [ -x /usr/bin/yum ]     && yum install -y $*   
+    [ -x /usr/bin/yum ]     && yum install     -y $*   
     
     #check properly installed
     for PACKAGE in $*
     
     #check properly installed
     for PACKAGE in $*
@@ -55,20 +55,24 @@ function install_packages(){
         [ -x /usr/bin/yum ]     && yum list installed $PACKAGE &>> /dev/null && PACKAGE_INSTALLED="yes" 
         if [ "$PACKAGE_INSTALLED" = "no" ]
         then
         [ -x /usr/bin/yum ]     && yum list installed $PACKAGE &>> /dev/null && PACKAGE_INSTALLED="yes" 
         if [ "$PACKAGE_INSTALLED" = "no" ]
         then
-            echo "failed to install package '$PACKAGE'. Revise network connectivity and try again"
-            exit -1
+            echo "failed to install package '$PACKAGE'. Revise network connectivity and try again" >&2
+            exit 1
        fi
     done
 }
 
        fi
     done
 }
 
-function db_exists() {
-    RESULT=`mysqlshow --defaults-extra-file="$2" | grep -v Wildcard | grep -w $1`
-    if [ "$RESULT" == "$1" ]; then
-        echo " DB $1 exists"
-        return 0
-    fi
-    echo " DB $1 does not exist"
-    return 1
+function ask_user(){
+    # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
+    # Params: $1 text to ask;   $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
+    # Return: true(0) if user type 'yes'; false (1) if user type 'no'
+    read -e -p "$1" USER_CONFIRMATION
+    while true ; do
+        [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
+        [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
+        [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
+        [ "${USER_CONFIRMATION,,}" == "no" ]  || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
+        read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
+    done
 }
 
 
 }
 
 
@@ -78,6 +82,8 @@ DBPASSWD=""
 DBPASSWD_PARAM=""
 QUIET_MODE=""
 DEVELOP=""
 DBPASSWD_PARAM=""
 QUIET_MODE=""
 DEVELOP=""
+DB_FORCE_UPDATE=""
+UPDATEDB=""
 FORCE=""
 NOCLONE=""
 NO_PACKAGES=""
 FORCE=""
 NOCLONE=""
 NO_PACKAGES=""
@@ -102,7 +108,9 @@ while getopts ":u:p:hiq-:" o; do
         -)
             [ "${OPTARG}" == "help" ] && usage && exit 0
             [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
         -)
             [ "${OPTARG}" == "help" ] && usage && exit 0
             [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
-            [ "${OPTARG}" == "force" ]   && FORCE="y" && continue
+            [ "${OPTARG}" == "forcedb" ] && DB_FORCE_UPDATE="${DB_FORCE_UPDATE}--forcedb" && continue
+            [ "${OPTARG}" == "updatedb" ] && DB_FORCE_UPDATE="${DB_FORCE_UPDATE}--updatedb" && continue
+            [ "${OPTARG}" == "force" ]   &&  FORCE="y" && continue
             [ "${OPTARG}" == "noclone" ] && NOCLONE="y" && continue
             [ "${OPTARG}" == "quiet" ] && export QUIET_MODE=yes && export DEBIAN_FRONTEND=noninteractive && continue
             [ "${OPTARG}" == "no-install-packages" ] && export NO_PACKAGES=yes && continue
             [ "${OPTARG}" == "noclone" ] && NOCLONE="y" && continue
             [ "${OPTARG}" == "quiet" ] && export QUIET_MODE=yes && export DEBIAN_FRONTEND=noninteractive && continue
             [ "${OPTARG}" == "no-install-packages" ] && export NO_PACKAGES=yes && continue
@@ -120,32 +128,39 @@ while getopts ":u:p:hiq-:" o; do
             ;;
         *)
             usage >&2
             ;;
         *)
             usage >&2
-            exit -1
+            exit 1
             ;;
     esac
 done
 
             ;;
     esac
 done
 
+if [ "$DB_FORCE_UPDATE" == "--forcedb--updatedb" ] || [ "$DB_FORCE_UPDATE" == "--updatedb--forcedb" ] ; then
+    echo "Error: options --forcedb and --updatedb are mutually exclusive" >&2
+    exit 1
+elif [ -n "$FORCE" ] && [ -z "$DB_FORCE_UPDATE" ] ; then
+    DB_FORCE_UPDATE="--updatedb"
+fi
+
 #check root privileges and non a root user behind
 #check root privileges and non a root user behind
-[ "$USER" != "root" ] && echo "Needed root privileges" >&2 && exit -1
+[ "$USER" != "root" ] && echo "Needed root privileges" >&2 && exit 1
 if [[ -z "$SUDO_USER" ]] || [[ "$SUDO_USER" = "root" ]]
 then
 if [[ -z "$SUDO_USER" ]] || [[ "$SUDO_USER" = "root" ]]
 then
-    [[ -z $QUIET_MODE ]] && read -e -p "Install in the root user (y/N)?" KK
-    [[ -z $QUIET_MODE ]] && [[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && echo "Cancelled" && exit 1
+    [[ -z $QUIET_MODE ]] && ! ask_user "Install in the root user (y/N)? " n  && echo "Cancelled" && exit 1
     export SUDO_USER=root
 fi
 
     export SUDO_USER=root
 fi
 
-#Discover Linux distribution
-#try redhat type
+# Discover Linux distribution
+# try redhat type
 [ -f /etc/redhat-release ] && _DISTRO=$(cat /etc/redhat-release 2>/dev/null | cut  -d" " -f1) 
 [ -f /etc/redhat-release ] && _DISTRO=$(cat /etc/redhat-release 2>/dev/null | cut  -d" " -f1) 
-#if not assuming ubuntu type
+# if not assuming ubuntu type
 [ -f /etc/redhat-release ] || _DISTRO=$(lsb_release -is  2>/dev/null)            
 if [ "$_DISTRO" == "Ubuntu" ]
 then
     _RELEASE=$(lsb_release -rs)
     if [[ ${_RELEASE%%.*} != 14 ]] && [[ ${_RELEASE%%.*} != 16 ]]
     then
 [ -f /etc/redhat-release ] || _DISTRO=$(lsb_release -is  2>/dev/null)            
 if [ "$_DISTRO" == "Ubuntu" ]
 then
     _RELEASE=$(lsb_release -rs)
     if [[ ${_RELEASE%%.*} != 14 ]] && [[ ${_RELEASE%%.*} != 16 ]]
     then
-        [[ -z $QUIET_MODE ]] && read -e -p "WARNING! Not tested Ubuntu version. Continue assuming a trusty (14.XX)'? (y/N)" KK
-        [[ -z $QUIET_MODE ]] && [[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && echo "Cancelled" && exit 1
+        [[ -z $QUIET_MODE ]] &&
+            ! ask_user "WARNING! Not tested Ubuntu version. Continue assuming a trusty (14.XX)' (y/N)? " n &&
+            echo "Cancelled" && exit 1
         _RELEASE = 14
     fi
 elif [ "$_DISTRO" == "CentOS" ]
         _RELEASE = 14
     fi
 elif [ "$_DISTRO" == "CentOS" ]
@@ -153,175 +168,107 @@ then
     _RELEASE="7" 
     if ! cat /etc/redhat-release | grep -q "7."
     then
     _RELEASE="7" 
     if ! cat /etc/redhat-release | grep -q "7."
     then
-        read -e -p "WARNING! Not tested CentOS version. Continue assuming a '_RELEASE' type? (y/N)" KK
-        [ "$KK" != "y" -a  "$KK" != "yes" ] && echo "Cancelled" && exit 0
+        [[ -z $QUIET_MODE ]] &&
+            ! ask_user "WARNING! Not tested CentOS version. Continue assuming a '$_RELEASE' type (y/N)? " n &&
+            echo "Cancelled" && exit 1
     fi
 elif [ "$_DISTRO" == "Red" ]
 then
     _RELEASE="7" 
     if ! cat /etc/redhat-release | grep -q "7."
     then
     fi
 elif [ "$_DISTRO" == "Red" ]
 then
     _RELEASE="7" 
     if ! cat /etc/redhat-release | grep -q "7."
     then
-        read -e -p "WARNING! Not tested Red Hat OS version. Continue assuming a '_RELEASE' type? (y/N)" KK
-        [ "$KK" != "y" -a  "$KK" != "yes" ] && echo "Cancelled" && exit 0
+        [[ -z $QUIET_MODE ]] &&
+            ! ask_user "WARNING! Not tested Red Hat OS version. Continue assuming a '$_RELEASE' type (y/N)? " n &&
+            echo "Cancelled" && exit 1
     fi
 else  #[ "$_DISTRO" != "Ubuntu" -a "$_DISTRO" != "CentOS" -a "$_DISTRO" != "Red" ] 
     _DISTRO_DISCOVER=$_DISTRO
     [ -x /usr/bin/apt-get ] && _DISTRO="Ubuntu" && _RELEASE="14"
     [ -x /usr/bin/yum ]     && _DISTRO="CentOS" && _RELEASE="7"
     fi
 else  #[ "$_DISTRO" != "Ubuntu" -a "$_DISTRO" != "CentOS" -a "$_DISTRO" != "Red" ] 
     _DISTRO_DISCOVER=$_DISTRO
     [ -x /usr/bin/apt-get ] && _DISTRO="Ubuntu" && _RELEASE="14"
     [ -x /usr/bin/yum ]     && _DISTRO="CentOS" && _RELEASE="7"
-    read -e -p "WARNING! Not tested Linux distribution '$_DISTRO_DISCOVER '. Continue assuming a '$_DISTRO $_RELEASE' type? (y/N)" KK
-    [ "$KK" != "y" -a  "$KK" != "yes" ] && echo "Cancelled" && exit 0
+    [[ -z $QUIET_MODE ]] &&
+        ! ask_user "WARNING! Not tested Linux distribution '$_DISTRO_DISCOVER '. Continue assuming a '$_DISTRO $_RELEASE' type (y/N)? " n &&
+        echo "Cancelled" && exit 1
 fi
 
 #check if installed as a service
 INSTALL_AS_A_SERVICE=""
 [[ "$_DISTRO" == "Ubuntu" ]] &&  [[ ${_RELEASE%%.*} == 16 ]] && [[ -z $DEVELOP ]] && INSTALL_AS_A_SERVICE="y"
 
 fi
 
 #check if installed as a service
 INSTALL_AS_A_SERVICE=""
 [[ "$_DISTRO" == "Ubuntu" ]] &&  [[ ${_RELEASE%%.*} == 16 ]] && [[ -z $DEVELOP ]] && INSTALL_AS_A_SERVICE="y"
 
-#Next operations require knowing BASEFOLDER
+# Next operations require knowing BASEFOLDER
 if [[ -z "$NOCLONE" ]]; then
     if [[ -n "$INSTALL_AS_A_SERVICE" ]] ; then
 if [[ -z "$NOCLONE" ]]; then
     if [[ -n "$INSTALL_AS_A_SERVICE" ]] ; then
-        OPENVIM_BASEFOLDER=__openvim__${RANDOM}
+        BASEFOLDER=__openvim__${RANDOM}
     else
     else
-        OPENVIM_BASEFOLDER="${PWD}/openvim"
+        BASEFOLDER="${PWD}/openvim"
     fi
     fi
-    [[ -n "$FORCE" ]] && rm -rf $OPENVIM_BASEFOLDER #make idempotent
+    [[ -n "$FORCE" ]] && rm -rf $BASEFOLDER #make idempotent
 else
     HERE=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
 else
     HERE=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
-    OPENVIM_BASEFOLDER=$(dirname $HERE)
-fi
-
-
-if [[ -z "$NO_PACKAGES" ]]
-then
-echo '
-#################################################################
-#####               UPDATE REPOSITORIES                     #####
-#################################################################'
-[ "$_DISTRO" == "Ubuntu" ] && apt-get update -y
-
-[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && yum check-update -y
-[ "$_DISTRO" == "CentOS" ] && sudo yum install -y epel-release
-[ "$_DISTRO" == "Red" ] && wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm \
-  && sudo rpm -ivh epel-release-7-5.noarch.rpm && sudo yum install -y epel-release && rm -f epel-release-7-5.noarch.rpm
-[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && sudo yum repolist
+    BASEFOLDER=$(dirname $HERE)
 fi
 
 if [[ -z "$NO_PACKAGES" ]]
 then
 fi
 
 if [[ -z "$NO_PACKAGES" ]]
 then
-echo '
-#################################################################
-#####               INSTALL REQUIRED PACKAGES               #####
-#################################################################'
-[ "$_DISTRO" == "Ubuntu" ] && install_packages "git screen wget mysql-server"
-[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "git screen wget mariadb mariadb-server"
-
-if [[ "$_DISTRO" == "Ubuntu" ]]
-then
-    #start services. By default CentOS does not start services
-    service mysql start >> /dev/null
-    # try to set admin password, ignore if fails
-    [[ -n $DBPASSWD ]] && mysqladmin -u $DBUSER -s password $DBPASSWD
-fi
-
-if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ]
-then
-    #start services. By default CentOS does not start services
-    service mariadb start
-    service httpd   start
-    systemctl enable mariadb
-    systemctl enable httpd
-    read -e -p "Do you want to configure mariadb (recomended if not done before) (Y/n)" KK
-    [ "$KK" != "n" -a  "$KK" != "no" ] && mysql_secure_installation
-
-    read -e -p "Do you want to set firewall to grant web access port 80,443  (Y/n)" KK
-    [ "$KK" != "n" -a  "$KK" != "no" ] && 
-        firewall-cmd --permanent --zone=public --add-service=http &&
-        firewall-cmd --permanent --zone=public --add-service=https &&
-        firewall-cmd --reload
-fi
-fi  #[[ -z "$NO_PACKAGES" ]]
-
-#check and ask for database user password. Must be done after database installation
-if [[ -n $QUIET_MODE ]]
-then
-    echo -e "\nCheking database connection and ask for credentials"
-    while ! mysqladmin -s -u$DBUSER $DBPASSWD_PARAM status >/dev/null
-    do
-        [ -n "$logintry" ] &&  echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)"
-        [ -z "$logintry" ] &&  echo -e "\nProvide database credentials"
-        read -e -p "database user? ($DBUSER) " DBUSER_
-        [ -n "$DBUSER_" ] && DBUSER=$DBUSER_
-        read -e -s -p "database password? (Enter for not using password) " DBPASSWD_
-        [ -n "$DBPASSWD_" ] && DBPASSWD="$DBPASSWD_" && DBPASSWD_PARAM="-p$DBPASSWD_"
-        [ -z "$DBPASSWD_" ] && DBPASSWD=""           && DBPASSWD_PARAM=""
-        logintry="yes"
-    done
-fi
-
-if [[ -z "$NO_PACKAGES" ]]
-then
-
-echo '
-#################################################################
-#####               INSTALL PYTHON PACKAGES                 #####
-#################################################################'
-[ "$_DISTRO" == "Ubuntu" ] && install_packages "python-yaml python-libvirt python-bottle python-mysqldb python-jsonschema python-paramiko python-argcomplete python-requests"
-[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "PyYAML libvirt-python MySQL-python python-jsonschema python-paramiko python-argcomplete python-requests"
-
-#The only way to install python-bottle on Centos7 is with easy_install or pip
-[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && easy_install -U bottle
-
-fi  #[[ -z "$NO_PACKAGES" ]]
+    echo -e "\n"\
+        "#################################################################\n"\
+        "#####        UPDATE REPOSITORIES                            #####\n"\
+        "#################################################################"
+    [ "$_DISTRO" == "Ubuntu" ] && apt-get update -y
+
+    [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && yum check-update -y
+    [ "$_DISTRO" == "CentOS" ] && sudo yum install -y epel-release
+    [ "$_DISTRO" == "Red" ] && wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm \
+        && sudo rpm -ivh epel-release-7-5.noarch.rpm && sudo yum install -y epel-release && rm -f epel-release-7-5.noarch.rpm
+    [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && sudo yum repolist
+
+    echo -e "\n"\
+        "#################################################################\n"\
+        "#####        INSTALL REQUIRED PACKAGES                      #####\n"\
+        "#################################################################"
+    [ "$_DISTRO" == "Ubuntu" ] && install_packages "git make screen wget mysql-client"
+    [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "git make screen wget mariadb-client"
+
+    echo -e "\n"\
+        "#################################################################\n"\
+        "#####        INSTALL PYTHON PACKAGES                        #####\n"\
+        "#################################################################"
+    [ "$_DISTRO" == "Ubuntu" ] && install_packages "python-yaml python-libvirt python-bottle python-mysqldb python-jsonschema python-paramiko python-argcomplete python-requests"
+    [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "PyYAML libvirt-python MySQL-python python-jsonschema python-paramiko python-argcomplete python-requests"
+    # The only way to install python-bottle on Centos7 is with easy_install or pip
+    [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && easy_install -U bottle
+
+fi  # [[ -z "$NO_PACKAGES" ]]
 
 if [[ -z $NOCLONE ]]; then
 
 if [[ -z $NOCLONE ]]; then
-    echo '
-#################################################################
-#####                 DOWNLOAD SOURCE                       #####
-#################################################################'
-    if [[ -d "${OPENVIM_BASEFOLDER}" ]]
-    then
-        if [[ -n "$FORCE" ]]
-        then
-            echo "deleting '${OPENVIM_BASEFOLDER}' folder"
-            rm -rf "$OPENVIM_BASEFOLDER" #make idempotent
-        elif [[ -z "$QUIET_MODE" ]]
-        then
-            read -e -p "${OPENVIM_BASEFOLDER} folder exist, overwrite? (y/N)" KK
-            if [[ "$KK" == "y" ]] || [[ "$KK" == "yes" ]]
-                then rm -rf "$OPENVIM_BASEFOLDER"
-            else
-                echo "canceled"
-                exit 1
-            fi
+    echo -e "\n"\
+        "#################################################################\n"\
+        "#####        DOWNLOAD SOURCE                                #####\n"\
+        "#################################################################"
+    if [[ -d "${BASEFOLDER}" ]] ; then
+        if [[ -n "$FORCE" ]] ; then
+            echo "deleting '${BASEFOLDER}' folder"
+            rm -rf "$BASEFOLDER" #make idempotent
+        elif [[ -z "$QUIET_MODE" ]] ; then
+            ! ask_user "folder '${BASEFOLDER}' exists, overwrite (y/N)? " n && echo "Cancelled!" && exit 1
+            rm -rf "$BASEFOLDER"
         else
         else
-            echo "'${OPENVIM_BASEFOLDER}' folder exist" >&2 && exit 1
+            echo "'${BASEFOLDER}' folder exists. Use "--force" to overwrite" >&2 && exit 1
         fi
     fi
         fi
     fi
-
-
-    su $SUDO_USER -c "git clone ${GIT_URL} ${OPENVIM_BASEFOLDER}"
-    su $SUDO_USER -c "cp ${OPENVIM_BASEFOLDER}/.gitignore-common ${OPENVIM_BASEFOLDER}/.gitignore"
-    [[ -z $DEVELOP ]] && su $SUDO_USER -c "git -C  ${OPENVIM_BASEFOLDER} checkout v2.0"
+    su $SUDO_USER -c "git clone ${GIT_URL} ${BASEFOLDER}"
+    su $SUDO_USER -c "cp ${BASEFOLDER}/.gitignore-common ${BASEFOLDER}/.gitignore"
+    [[ -z $DEVELOP ]] && su $SUDO_USER -c "git -C ${BASEFOLDER} checkout v2.0"
 fi
 
 fi
 
-DB_QUIET=''
-if [ -z "$NO_DB" ]; then
-    if [ -n "$QUIET_MODE" ]; then
-        DB_QUIET='-q'
-    fi
-
-    echo "!!!! install-db-server.sh: ${OPENVIM_BASEFOLDER}/database_utils/install-db-server.sh -U $DBUSER $DBPASSWD_PARAM $DB_QUIET"
-    ${OPENVIM_BASEFOLDER}/database_utils/install-db-server.sh -U $DBUSER $DBPASSWD_PARAM  $DB_QUIET  || exit 1
-fi
 
 
 if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ]
 then
 
 
 if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ]
 then
-    echo '
-#################################################################
-#####        CONFIGURE firewalld                            #####
-#################################################################'
-    read -e -p "Configure firewalld for openvimd port 9080? (Y/n)" KK
-    if [ "$KK" != "n" -a  "$KK" != "no" ]
+    echo -e "\n"\
+        "#################################################################\n"\
+        "#####        CONFIGURE firewalld                            #####\n"\
+        "#################################################################"
+    if [[ -z $QUIET_MODE ]] || ask_user "Configure firewalld for openvimd port 9080 (Y/n)? " y
     then
         #Creates a service file for openvim
         echo '<?xml version="1.0" encoding="utf-8"?>
     then
         #Creates a service file for openvim
         echo '<?xml version="1.0" encoding="utf-8"?>
@@ -344,14 +291,14 @@ then
     fi
 fi
 
     fi
 fi
 
-echo '
-#################################################################
-#####        CONFIGURE openvim CLIENT                       #####
-#################################################################'
+echo -e "\n"\
+    "#################################################################n"\
+    "#####        CONFIGURE OPENVIM CLIENT                       #####n"\
+    "#################################################################"
 #creates a link at ~/bin if not configured as a service
 if [[ -z "$INSTALL_AS_A_SERVICE" ]]
 then
 #creates a link at ~/bin if not configured as a service
 if [[ -z "$INSTALL_AS_A_SERVICE" ]]
 then
-    su $SUDO_USER -c 'mkdir -p ~/bin'
+    su $SUDO_USER -c 'mkdir -p ${HOME}/bin'
     su $SUDO_USER -c 'rm -f ${HOME}/bin/openvim'
     su $SUDO_USER -c 'rm -f ${HOME}/bin/openflow'
     su $SUDO_USER -c 'rm -f ${HOME}/bin/service-openvim'
     su $SUDO_USER -c 'rm -f ${HOME}/bin/openvim'
     su $SUDO_USER -c 'rm -f ${HOME}/bin/openflow'
     su $SUDO_USER -c 'rm -f ${HOME}/bin/service-openvim'
@@ -359,20 +306,20 @@ then
     su $SUDO_USER -c 'rm -f ${HOME}/bin/service-floodlight'
     su $SUDO_USER -c 'rm -f ${HOME}/bin/service-opendaylight'
     su $SUDO_USER -c 'rm -f ${HOME}/bin/get_dhcp_lease.sh'
     su $SUDO_USER -c 'rm -f ${HOME}/bin/service-floodlight'
     su $SUDO_USER -c 'rm -f ${HOME}/bin/service-opendaylight'
     su $SUDO_USER -c 'rm -f ${HOME}/bin/get_dhcp_lease.sh'
-    su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/openvim'   "'${HOME}/bin/openvim'
-    su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/openflow'  "'${HOME}/bin/openflow'
-    su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/service-openvim'  "'${HOME}/bin/service-openvim'
-    su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/initopenvim'  "'${HOME}/bin/initopenvim'
-    su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/service-floodlight'  "'${HOME}/bin/service-floodlight'
-    su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/service-opendaylight'  "'${HOME}/bin/service-opendaylight'
-    su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/get_dhcp_lease.sh'  "'${HOME}/bin/get_dhcp_lease.sh'
+    su $SUDO_USER -c "ln -s '${BASEFOLDER}/openvim'   "'${HOME}/bin/openvim'
+    su $SUDO_USER -c "ln -s '${BASEFOLDER}/openflow'  "'${HOME}/bin/openflow'
+    su $SUDO_USER -c "ln -s '${BASEFOLDER}/scripts/service-openvim'  "'${HOME}/bin/service-openvim'
+    su $SUDO_USER -c "ln -s '${BASEFOLDER}/scripts/initopenvim'  "'${HOME}/bin/initopenvim'
+    su $SUDO_USER -c "ln -s '${BASEFOLDER}/scripts/service-floodlight'  "'${HOME}/bin/service-floodlight'
+    su $SUDO_USER -c "ln -s '${BASEFOLDER}/scripts/service-opendaylight'  "'${HOME}/bin/service-opendaylight'
+    su $SUDO_USER -c "ln -s '${BASEFOLDER}/scripts/get_dhcp_lease.sh'  "'${HOME}/bin/get_dhcp_lease.sh'
     
     #insert /home/<user>/bin in the PATH
     
     #insert /home/<user>/bin in the PATH
-    #skiped because normally this is done authomatically when ~/bin exist
-    #if ! su $SUDO_USER -c 'echo $PATH' | grep -q "/home/${SUDO_USER}/bin"
+    #skiped because normally this is done authomatically when ~/bin exists
+    #if ! su $SUDO_USER -c 'echo $PATH' | grep -q "${HOME}/bin"
     #then
     #    echo "    inserting /home/$SUDO_USER/bin in the PATH at .bashrc"
     #then
     #    echo "    inserting /home/$SUDO_USER/bin in the PATH at .bashrc"
-    #    su $SUDO_USER -c 'echo "PATH=\$PATH:/home/\${USER}/bin" >> ~/.bashrc'
+    #    su $SUDO_USER -c 'echo "PATH=\$PATH:\${HOME}/bin" >> ~/.bashrc'
     #fi
     
     if [[ $SUDO_USER == root ]]
     #fi
     
     if [[ $SUDO_USER == root ]]
@@ -385,40 +332,44 @@ then
 fi
 
 #configure arg-autocomplete for this user
 fi
 
 #configure arg-autocomplete for this user
-#in case of minmal instalation this package is not installed by default
+#in case of minimal instalation this package is not installed by default
 [[ "$_DISTRO" == "CentOS" || "$_DISTRO" == "Red" ]] && yum install -y bash-completion
 #su $SUDO_USER -c 'mkdir -p ~/.bash_completion.d'
 su $SUDO_USER -c 'activate-global-python-argcomplete --user'
 [[ "$_DISTRO" == "CentOS" || "$_DISTRO" == "Red" ]] && yum install -y bash-completion
 #su $SUDO_USER -c 'mkdir -p ~/.bash_completion.d'
 su $SUDO_USER -c 'activate-global-python-argcomplete --user'
-if ! grep -q bash_completion.d/python-argcomplete.sh ${HOME}/.bashrc
+if ! su  $SUDO_USER -c 'grep -q bash_completion.d/python-argcomplete.sh ${HOME}/.bashrc'
 then
     echo "    inserting .bash_completion.d/python-argcomplete.sh execution at .bashrc"
     su $SUDO_USER -c 'echo ". ${HOME}/.bash_completion.d/python-argcomplete.sh" >> ~/.bashrc'
 fi
 
 then
     echo "    inserting .bash_completion.d/python-argcomplete.sh execution at .bashrc"
     su $SUDO_USER -c 'echo ". ${HOME}/.bash_completion.d/python-argcomplete.sh" >> ~/.bashrc'
 fi
 
+if [ -z "$NO_DB" ]; then
+    echo -e "\n"\
+        "#################################################################"\n"\
+        "#####               INSTALL DATABASE SERVER                 #####"\n"\
+        "#################################################################"
 
 
+    if [ -n "$QUIET_MODE" ]; then
+        DB_QUIET='-q'
+    fi
+    ${BASEFOLDER}/database_utils/install-db-server.sh -U $DBUSER ${DBPASSWD_PARAM/p/P} $DB_QUIET $DB_FORCE_UPDATE || exit 1
+fi   # [ -z "$NO_DB" ]
 
 if [[ -n "$INSTALL_AS_A_SERVICE"  ]]
 then
 
 if [[ -n "$INSTALL_AS_A_SERVICE"  ]]
 then
-echo '
-#################################################################
-#####             CONFIGURE OPENVIM SERVICE                 #####
-#################################################################'
-
-    DELETE_PARAM="" && [[ -z "$NOCLONE" ]] && DELETE_PARAM="-d"
-    ${OPENVIM_BASEFOLDER}/scripts/install-openvim-service.sh -f ${OPENVIM_BASEFOLDER} ${DELETE_PARAM}
-#    alias service-openvim="service openvim"
-#    echo 'alias service-openvim="service openvim"' >> ${HOME}/.bashrc
-
-    echo
+    echo -e "\n"\
+        "#################################################################"\n"\
+        "#####        CONFIGURE OPENVIM SERVICE                      #####"\n"\
+        "#################################################################"
+
+    ${BASEFOLDER}/scripts/install-openvim-service.sh -f ${BASEFOLDER} `[[ -z "$NOCLONE" ]] && echo "-d"`
+    # rm -rf ${BASEFOLDER}
+    # alias service-openvim="service openvim"
+    # echo 'alias service-openvim="service openvim"' >> ${HOME}/.bashrc
     echo
     echo "Done!  installed at /opt/openvim"
     echo
     echo "Done!  installed at /opt/openvim"
-    echo " Manage server with 'service openvim start|stop|status|...' "
-
-
+    echo " Manage server with 'sudo service osm-openvim start|stop|status|...' "
 else
 else
-
     echo
     echo "Done!  you may need to logout and login again for loading client configuration"
     echo
     echo "Done!  you may need to logout and login again for loading client configuration"
-    echo " Run 'service-openvim start' for starting openvim in a screen"
-
+    echo " Run './${BASEFOLDER}/scripts/service-openvim start' for starting openvim in a screen"
 fi
 fi