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(){
}
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
DBPASSWD_PARAM=""
QUIET_MODE=""
DEVELOP=""
-FORCEDB=""
FORCE=""
NOCLONE=""
NO_PACKAGES=""
+NO_DB=""
+
while getopts ":u:p:hiq-:" o; do
case "${o}" in
u)
-)
[ "${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
;;
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
if [[ -z "$NO_PACKAGES" ]]
then
+
echo '
#################################################################
##### INSTALL PYTHON PACKAGES #####
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" ]
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/<user>/bin in the PATH