X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=scripts%2Finstall-openvim.sh;h=5f0867f69f8c5c3f5c925aabd38707bdcb79a58f;hb=9cc283fdb8f9abcb9ea8e9ce9d98dad352c06f82;hp=747c8e6f3e46fdfcfbecc14e5f9465abedfb60ad;hpb=8940f6c1341c3fa60bf0c20727b65dc79d345d88;p=osm%2Fopenvim.git diff --git a/scripts/install-openvim.sh b/scripts/install-openvim.sh index 747c8e6..5f0867f 100755 --- a/scripts/install-openvim.sh +++ b/scripts/install-openvim.sh @@ -37,10 +37,10 @@ function usage(){ echo -e " -q --quiet: install in an 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 " --forcedb: reinstall vim_db DB, deleting previous database if exists and creating a new one" echo -e " --force: makes idenpotent, delete previous installations folders if needed" 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" } function install_packages(){ @@ -62,7 +62,7 @@ function install_packages(){ } function db_exists() { - RESULT=`mysqlshow --defaults-extra-file="$2" | grep -v Wildcard | grep -o $1` + RESULT=`mysqlshow --defaults-extra-file="$2" | grep -v Wildcard | grep -w $1` if [ "$RESULT" == "$1" ]; then echo " DB $1 exists" return 0 @@ -78,10 +78,11 @@ DBPASSWD="" DBPASSWD_PARAM="" QUIET_MODE="" DEVELOP="" -FORCEDB="" FORCE="" NOCLONE="" NO_PACKAGES="" +NO_DB="" + while getopts ":u:p:hiq-:" o; do case "${o}" in u) @@ -101,11 +102,11 @@ while getopts ":u:p:hiq-:" o; do -) [ "${OPTARG}" == "help" ] && usage && exit 0 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue - [ "${OPTARG}" == "forcedb" ] && FORCEDB="y" && continue - [ "${OPTARG}" == "force" ] && FORCEDB="y" && FORCE="y" && 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}" == "no-db" ] && NO_DB="y" && continue echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2 exit 1 ;; @@ -184,7 +185,7 @@ if [[ -z "$NOCLONE" ]]; then fi [[ -n "$FORCE" ]] && rm -rf $OPENVIM_BASEFOLDER #make idempotent else - HERE=$(realpath $(dirname $0)) + HERE=$(dirname $(readlink -f ${BASH_SOURCE[0]})) OPENVIM_BASEFOLDER=$(dirname $HERE) fi @@ -258,6 +259,7 @@ fi if [[ -z "$NO_PACKAGES" ]] then + echo ' ################################################################# ##### INSTALL PYTHON PACKAGES ##### @@ -298,47 +300,18 @@ if [[ -z $NOCLONE ]]; then 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 tags/v1.0.2" + [[ -z $DEVELOP ]] && su $SUDO_USER -c "git -C ${OPENVIM_BASEFOLDER} checkout v2.0" fi -echo ' -################################################################# -##### CREATE DATABASE ##### -#################################################################' -echo -e "\nCreating temporary file form MYSQL installation and initialization" -TEMPFILE="$(mktemp -q --tmpdir "installopenvim.XXXXXX")" -trap 'rm -f "$TEMPFILE"' EXIT -chmod 0600 "$TEMPFILE" -echo -e "[client]\n user='$DBUSER'\n password='$DBPASSWD'">"$TEMPFILE" - -if db_exists "vim_db" $TEMPFILE ; then - if [[ -n $FORCEDB ]]; then - echo " Deleting previous database vim_db" - DBDELETEPARAM="" - [[ -n $QUIET_MODE ]] && DBDELETEPARAM="-f" - mysqladmin --defaults-extra-file=$TEMPFILE -s drop vim_db $DBDELETEPARAM || ! echo "Could not delete vim_db database" || exit 1 - #echo "REVOKE ALL PRIVILEGES ON vim_db.* FROM 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 - #echo "DELETE USER 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 - mysqladmin --defaults-extra-file=$TEMPFILE -s create vim_db || ! echo "Error creating vim_db database" || exit 1 - echo "DROP USER 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 - echo "CREATE USER 'vim'@'localhost' identified by 'vimpw';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 - echo "GRANT ALL PRIVILEGES ON vim_db.* TO 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 - echo " Database 'vim_db' created, user 'vim' password 'vimpw'" - else - echo "Database exists. Use option '--forcedb' to force the deletion of the existing one" && exit 1 +DB_QUIET='' +if [ -z "$NO_DB" ]; then + if [ -n "$QUIET_MODE" ]; then + DB_QUIET='-q' fi -else - mysqladmin -u$DBUSER $DBPASSWD_PARAM -s create vim_db || ! echo "Error creating vim_db database" || exit 1 - echo "CREATE USER 'vim'@'localhost' identified by 'vimpw';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 - echo "GRANT ALL PRIVILEGES ON vim_db.* TO 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 - echo " Database 'vim_db' created, user 'vim' password 'vimpw'" -fi -echo ' -################################################################# -##### INIT DATABASE ##### -#################################################################' -su $SUDO_USER -c "${OPENVIM_BASEFOLDER}/database_utils/init_vim_db.sh -u vim -p vimpw -d vim_db" || ! echo "Failed while initializing database" || exit 1 + 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" ] @@ -388,10 +361,10 @@ then 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.sh' "'${HOME}/bin/service-openvim' - su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/initopenvim.sh' "'${HOME}/bin/initopenvim' - su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/service-floodlight.sh' "'${HOME}/bin/service-floodlight' - su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/service-opendaylight.sh' "'${HOME}/bin/service-opendaylight' + 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' #insert /home//bin in the PATH