#Ask for database user and password if not provided
function usage(){
- echo -e "usage: sudo $0 [OPTIONS]"
+ echo -e "usage: sudo -E $0 [OPTIONS]"
echo -e "Install last stable source code in ./openmano and the needed packages"
echo -e "On a Ubuntu 16.04 it configures openmano as a service"
echo -e " OPTIONS"
echo -e " -p PASS: database admin password to be used or installed. Prompts if needed"
echo -e " -q --quiet: install in unattended mode"
echo -e " -h --help: show this help"
+ echo -e " -b REFSPEC: install from source code using a specific branch (master, v2.0, ...) or tag"
+ echo -e " -b master (main RO branch)"
+ echo -e " -b v2.0 (v2.0 branch)"
+ echo -e " -b tags/v1.1.0 (a specific tag)"
+ echo -e " ..."
echo -e " --develop: install last version for developers, and do not configure as a service"
- echo -e " --forcedb: reinstall mano_db DB, deleting previous database and creating a new one"
+ echo -e " --forcedb: reinstall mano_db DB, deleting previous database if exists and creating a new one"
+ echo -e " --updatedb: do not reinstall mano_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 openmano 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 install mysql server"
}
function install_packages(){
done
}
-function db_exists() {
- RESULT=`mysqlshow --defaults-extra-file="$2" | grep -v Wildcard | grep -o $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
}
GIT_URL=https://osm.etsi.org/gerrit/osm/RO.git
+GIT_OVIM_URL=https://osm.etsi.org/gerrit/osm/openvim.git
+GIT_OSMIM_URL=https://osm.etsi.org/gerrit/osm/IM.git
DBUSER="root"
DBPASSWD=""
DBPASSWD_PARAM=""
QUIET_MODE=""
DEVELOP=""
-FORCEDB=""
+DB_FORCE_UPDATE=""
+UPDATEDB=""
+FORCE=""
NOCLONE=""
NO_PACKAGES=""
-while getopts ":u:p:hiq-:" o; do
+NO_DB=""
+COMMIT_ID=""
+
+while getopts ":u:p:b:hiq-:" o; do
case "${o}" in
u)
export DBUSER="$OPTARG"
export DBPASSWD="$OPTARG"
export DBPASSWD_PARAM="-p$OPTARG"
;;
+ b)
+ export COMMIT_ID=${OPTARG}
+ ;;
q)
export QUIET_MODE=yes
export DEBIAN_FRONTEND=noninteractive
-)
[ "${OPTARG}" == "help" ] && usage && exit 0
[ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
- [ "${OPTARG}" == "forcedb" ] && FORCEDB="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
- echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
+ [ "${OPTARG}" == "no-db" ] && NO_DB="y" && continue
+ echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
exit 1
- ;;
+ ;;
\?)
echo -e "Invalid option: '-$OPTARG'\nTry $0 --help for more information" >&2
exit 1
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
[ "$USER" != "root" ] && echo "Needed root privileges" >&2 && exit 1
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
-#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)
-#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
- [[ -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
+ if [[ ${_RELEASE%%.*} != 14 ]] && [[ ${_RELEASE%%.*} != 16 ]]
+ then
+ [[ -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="7"
if ! cat /etc/redhat-release | grep -q "7."
then
- [[ -z $QUIET_MODE ]] && read -e -p "WARNING! Not tested CentOS version. Continue assuming a '_RELEASE' type? (y/N)" KK
- [[ -z $QUIET_MODE ]] && [[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && echo "Cancelled" && exit 1
+ [[ -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
- [[ -z $QUIET_MODE ]] && read -e -p "WARNING! Not tested Red Hat OS version. Continue assuming a '_RELEASE' type? (y/N)" KK
- [[ -z $QUIET_MODE ]] && [[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && echo "Cancelled" && exit 1
+ [[ -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"
- [[ -z $QUIET_MODE ]] && read -e -p "WARNING! Not tested Linux distribution '$_DISTRO_DISCOVER '. Continue assuming a '$_DISTRO $_RELEASE' type? (y/N)" KK
- [[ -z $QUIET_MODE ]] && [[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && echo "Cancelled" && exit 1
+ [[ -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"
-
-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
-
+# Next operations require knowing BASEFOLDER
+if [[ -z "$NOCLONE" ]]; then
+ if [[ -n "$INSTALL_AS_A_SERVICE" ]] ; then
+ BASEFOLDER=__openmano__${RANDOM}
+ else
+ BASEFOLDER="${PWD}/openmano"
+ fi
+ [[ -n "$FORCE" ]] && rm -rf $BASEFOLDER #make idempotent
+else
+ HERE=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
+ BASEFOLDER=$(dirname $HERE)
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
+ echo -e "\n"\
+ "#################################################################\n"\
+ "##### UPDATE REPOSITORIES #####\n"\
+ "#################################################################"
+ [ "$_DISTRO" == "Ubuntu" ] && apt-get update -y
+
+ [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && yum check-update -y
+ [ "$_DISTRO" == "CentOS" ] && yum install -y epel-release
+ [ "$_DISTRO" == "Red" ] && wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm \
+ && rpm -ivh epel-release-7-5.noarch.rpm && yum install -y epel-release && rm -f epel-release-7-5.noarch.rpm
+ [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && 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-bottle python-mysqldb python-jsonschema python-paramiko python-argcomplete python-requests python-logutils libxml2-dev libxslt-dev python-dev python-pip python-crypto"
+ [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "PyYAML MySQL-python python-jsonschema python-paramiko python-argcomplete python-requests python-logutils libxslt-devel libxml2-devel python-devel python-pip python-crypto"
+ # The only way to install python-bottle on Centos7 is with easy_install or pip
+ [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && easy_install -U bottle
+
+ # required for vmware connector TODO move that to separete opt in install script
+ pip install --upgrade pip || exit 1
+ pip install pyvcloud==18.2.2 || exit 1
+ pip install progressbar || exit 1
+ pip install prettytable || exit 1
+ pip install pyvmomi || exit 1
+
+ # required for AWS connector
+ [ "$_DISTRO" == "Ubuntu" ] && install_packages "python-boto"
+ [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "python-boto" #TODO check if at Centos it exists with this name, or PIP should be used
+
+ # install openstack client needed for using openstack as a VIM
+ [ "$_DISTRO" == "Ubuntu" ] && install_packages "python-novaclient python-keystoneclient python-glanceclient "\
+ "python-neutronclient python-cinderclient python-openstackclient"
+ [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "python-devel" && easy_install \
+ python-novaclient python-keystoneclient python-glanceclient python-neutronclient python-cinderclient \
+ python-openstackclient #TODO revise if gcc python-pip is needed
+fi # [[ -z "$NO_PACKAGES" ]]
-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 (recommended 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
+if [[ -z $NOCLONE ]]; then
+ 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
+ echo "'${BASEFOLDER}' folder exists. Use "--force" to overwrite" >&2 && exit 1
+ fi
+ fi
+ su $SUDO_USER -c "git clone ${GIT_URL} ${BASEFOLDER}" || ! echo "Error cannot clone from '$GIT_URL'" >&2 || exit 1
+ if [[ -n $COMMIT_ID ]] ; then
+ echo -e "Installing osm-RO from refspec: $COMMIT_ID"
+ su $SUDO_USER -c "git -C ${BASEFOLDER} checkout $COMMIT_ID" ||
+ ! echo "Error cannot checkout '$COMMIT_ID' from '$GIT_URL'" >&2 || exit 1
+ elif [[ -z $DEVELOP ]]; then
+ LATEST_STABLE_TAG=`git -C "${BASEFOLDER}" tag -l "v[0-9]*" | sort -V | tail -n1`
+ echo -e "Installing osm-RO from refspec: tags/${LATEST_STABLE_TAG}"
+ su $SUDO_USER -c "git -C ${BASEFOLDER} checkout tags/${LATEST_STABLE_TAG}" ||
+ ! echo "Error cannot checkout 'tags/${LATEST_STABLE_TAG}' from '$GIT_URL'" >&2 || exit 1
+ else
+ echo -e "Installing osm-RO from refspec: master"
+ fi
+ su $SUDO_USER -c "cp ${BASEFOLDER}/.gitignore-common ${BASEFOLDER}/.gitignore"
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
+echo -e "\n"\
+ "#################################################################\n"\
+ "##### INSTALLING OSM-IM LIBRARY #####\n"\
+ "#################################################################"
+su $SUDO_USER -c "git -C ${BASEFOLDER} clone ${GIT_OSMIM_URL} IM" ||
+ ! echo "Error cannot clone from '${GIT_OSMIM_URL}'" >&2 || exit 1
+if [[ -n $COMMIT_ID ]] ; then
+ echo -e "Installing osm-IM from refspec: $COMMIT_ID"
+ su $SUDO_USER -c "git -C ${BASEFOLDER}/IM checkout $COMMIT_ID" ||
+ ! echo "Error cannot checkout '$COMMIT_ID' from '${GIT_OSMIM_URL}'" >&2 || exit 1
+elif [[ -z $DEVELOP ]]; then
+ LATEST_STABLE_TAG=`git -C "${BASEFOLDER}/IM" tag -l "v[0-9]*" | sort -V | tail -n1`
+ echo -e "Installing osm-IM from refspec: tags/${LATEST_STABLE_TAG}"
+ su $SUDO_USER -c "git -C ${BASEFOLDER}/IM checkout tags/${LATEST_STABLE_TAG}" ||
+ ! echo "Error cannot checkout 'tags/${LATEST_STABLE_TAG}' from '${GIT_OSMIM_URL}'" >&2 || exit 1
+else
+ echo -e "Installing osm-IM from refspec: master"
fi
+# Install debian dependencies before setup.py
if [[ -z "$NO_PACKAGES" ]]
then
-echo '
-#################################################################
-##### INSTALL PYTHON PACKAGES #####
-#################################################################'
-[ "$_DISTRO" == "Ubuntu" ] && install_packages "python-yaml python-bottle python-mysqldb python-jsonschema python-paramiko python-argcomplete python-requests python-logutils"
-[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "PyYAML MySQL-python python-jsonschema python-paramiko python-argcomplete python-requests python-logutils"
-
-#The only way to install python-bottle on Centos7 is with easy_install or pip
-[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && easy_install -U bottle
-
-#install openstack client needed for using openstack as a VIM
-[ "$_DISTRO" == "Ubuntu" ] && install_packages "python-novaclient python-keystoneclient python-glanceclient python-neutronclient"
-[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "python-devel" && easy_install python-novaclient python-keystoneclient python-glanceclient python-neutronclient #TODO revise if gcc python-pip is needed
-fi #[[ -z "$NO_PACKAGES" ]]
-
-if [[ -z $NOCLONE ]]; then
- echo '
-#################################################################
-##### DOWNLOAD SOURCE #####
-#################################################################'
- su $SUDO_USER -c 'git clone '"${GIT_URL}"' openmano'
- #[[ -z $DEVELOP ]] && su $SUDO_USER -c 'git checkout <tag version>'
+ [ "$_DISTRO" == "Ubuntu" ] && install_packages "tox debhelper python-bitarray python-lxml python-six"
+ # TODO check packages for CentOS and RedHat
+ [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "tox debhelper python-bitarray python-lxml python-six"
+ pip install --upgrade stdeb pyangbind || exit 1
fi
-
-echo '
-#################################################################
-##### CREATE DATABASE #####
-#################################################################'
-echo -e "\nCreating temporary file form MYSQL installation and initialization"
-TEMPFILE="$(mktemp -q --tmpdir "installopenmano.XXXXXX")"
-trap 'rm -f "$TEMPFILE"' EXIT
-chmod 0600 "$TEMPFILE"
-cat >"$TEMPFILE" <<EOF
-[client]
-user=$DBUSER
-password=$DBPASSWD
-EOF
-
-if db_exists "mano_db" $TEMPFILE ; then
- if [[ -n $FORCEDB ]]; then
- echo " Deleting previous database mano_db"
- DBDELETEPARAM=""
- [[ -n $QUIET_MODE ]] && DBDELETEPARAM="-f"
- mysqladmin --defaults-extra-file=$TEMPFILE -s drop mano_db $DBDELETEPARAM || ! echo "Could not delete mano_db database" || exit 1
- #echo "REVOKE ALL PRIVILEGES ON mano_db.* FROM 'mano'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user mano at database" || exit 1
- #echo "DELETE USER 'mano'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user mano at database" || exit 1
- mysqladmin --defaults-extra-file=$TEMPFILE -s create mano_db || ! echo "Error creating mano_db database" || exit 1
- echo "DROP USER 'mano'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user mano at database" || exit 1
- echo "CREATE USER 'mano'@'localhost' identified by 'manopw';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user mano at database" || exit 1
- echo "GRANT ALL PRIVILEGES ON mano_db.* TO 'mano'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user mano at database" || exit 1
- echo " Database 'mano_db' created, user 'mano' password 'manopw'"
- else
- echo "Database exists. Use option '--forcedb' to force the deletion of the existing one" && exit 1
- fi
+su $SUDO_USER -c "make -C ${BASEFOLDER}/IM all"
+dpkg -i ${BASEFOLDER}/IM/deb_dist/python-osm-im*.deb ${BASEFOLDER}/IM/pyangbind/deb_dist/*.deb \
+ ${BASEFOLDER}/IM/pyang/deb_dist/*.deb
+rm -rf "${BASEFOLDER}/IM"
+OSM_IM_PATH=`python -c 'import osm_im; print osm_im.__path__[0]'` ||
+ ! echo "ERROR installing python-osm-im library!!!" >&2 || exit 1
+
+
+echo -e "\n"\
+ "#################################################################\n"\
+ "##### INSTALLING OVIM LIBRARY #####\n"\
+ "#################################################################"
+su $SUDO_USER -c "git -C ${BASEFOLDER} clone ${GIT_OVIM_URL} openvim" ||
+ ! echo "Error cannot clone from '${GIT_OVIM_URL}'" || exit 1
+if [[ -n $COMMIT_ID ]] ; then
+ echo -e "Installing lib_osm_openvim from refspec: $COMMIT_ID"
+ su $SUDO_USER -c "git -C ${BASEFOLDER}/openvim checkout $COMMIT_ID" ||
+ ! echo "Error cannot checkout '$COMMIT_ID' from '${GIT_OVIM_URL}'" || exit 1
+elif [[ -z $DEVELOP ]]; then
+ LATEST_STABLE_TAG=`git -C "${BASEFOLDER}/openvim" tag -l "v[0-9]*" | sort -V | tail -n1`
+ echo -e "Installing lib_osm_openvim from refspec: tags/${LATEST_STABLE_TAG}"
+ su $SUDO_USER -c "git -C ${BASEFOLDER}/openvim checkout tags/${LATEST_STABLE_TAG}" ||
+ ! echo "Error cannot checkout 'tags/${LATEST_STABLE_TAG}' from '${GIT_OVIM_URL}'" || exit 1
else
- mysqladmin -u$DBUSER $DBPASSWD_PARAM -s create mano_db || ! echo "Error creating mano_db database" || exit 1
- echo "CREATE USER 'mano'@'localhost' identified by 'manopw';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user mano at database" || exit 1
- echo "GRANT ALL PRIVILEGES ON mano_db.* TO 'mano'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user mano at database" || exit 1
- echo " Database 'mano_db' created, user 'mano' password 'manopw'"
+ echo -e "Installing lib_osm_openvim from refspec: master"
fi
-
-#Next operations require knowing OPENMANO_BASEFOLDER
-HERE=$(realpath $(dirname $0))
-if [[ -z $NOCLONE ]]; then
- OPENMANO_BASEFOLDER="${HERE}/openmano"
-else
- OPENMANO_BASEFOLDER=$(dirname $HERE)
+# Install debian dependencies before setup.py
+if [[ -z "$NO_PACKAGES" ]]
+then
+ [ "$_DISTRO" == "Ubuntu" ] && install_packages \
+ "libmysqlclient-dev python-cffi python-packaging python-pkgconfig python-pycparser libssl-dev libffi-dev"
+ # TODO check if that is the name in CentOS and RedHat
+ [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages \
+ "libmysqlclient-dev python-cffi python-packaging python-pkgconfig python-pycparser libssl-dev libffi-dev"
+ pip install --upgrade stdeb setuptools-version-command || exit 1
fi
-
-
-echo '
-#################################################################
-##### INIT DATABASE #####
-#################################################################'
-su $SUDO_USER -c "${OPENMANO_BASEFOLDER}"'/database_utils/init_mano_db.sh -u mano -p manopw -d mano_db' || ! echo "Failed while initializing database" || exit 1
-
+su $SUDO_USER -c "make -C ${BASEFOLDER}/openvim lite"
+dpkg -i ${BASEFOLDER}/openvim/.build/python-lib-osm-openvim*.deb
+rm -rf "${BASEFOLDER}/openvim"
+OSMLIBOVIM_PATH=`python -c 'import lib_osm_openvim; print lib_osm_openvim.__path__[0]'` ||
+ ! echo "ERROR installing python-lib-osm-openvim library!!!" >&2 || exit 1
if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ]
then
- echo '
-#################################################################
-##### CONFIGURE firewalld #####
-#################################################################'
- KK=yes
- [[ -z $QUIET_MODE ]] && read -e -p "Configure firewalld for openmanod port 9090? (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 openmanod port 9090 (Y/n)? " y
then
#Creates a service file for openmano
echo '<?xml version="1.0" encoding="utf-8"?>
fi
fi
-echo '
-#################################################################
-##### CONFIGURE OPENMANO CLIENT #####
-#################################################################'
-#creates a link at ~/bin
-su $SUDO_USER -c 'mkdir -p ${HOME}/bin'
-su $SUDO_USER -c 'rm -f ${HOME}/bin/openmano'
-su $SUDO_USER -c 'rm -f ${HOME}/bin/openmano-report'
-su $SUDO_USER -c 'rm -f ${HOME}/bin/service-openmano'
-su $SUDO_USER -c 'ln -s '${OPENMANO_BASEFOLDER}'/openmano ${HOME}/bin/openmano'
-su $SUDO_USER -c 'ln -s '${OPENMANO_BASEFOLDER}'/scripts/openmano-report.sh ${HOME}/bin/openmano-report'
-su $SUDO_USER -c 'ln -s '${OPENMANO_BASEFOLDER}'/scripts/service-openmano.sh ${HOME}/bin/service-openmano'
-
-#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}/bin"
-#then
-# echo " inserting /home/$SUDO_USER/bin in the PATH at .bashrc"
-# su $SUDO_USER -c 'echo "PATH=\$PATH:\${HOME}/bin" >> ~/.bashrc'
-#fi
-if [[ $SUDO_USER == root ]]
+echo -e "\n"\
+ "#################################################################\n"\
+ "##### CONFIGURE OPENMANO CLIENT #####\n"\
+ "#################################################################"
+#creates a link at ~/bin if not configured as a service
+if [[ -z "$INSTALL_AS_A_SERVICE" ]]
then
- if ! echo $PATH | grep -q "${HOME}/bin"
+ su $SUDO_USER -c 'mkdir -p ${HOME}/bin'
+ su $SUDO_USER -c 'rm -f ${HOME}/bin/openmano'
+ su $SUDO_USER -c 'rm -f ${HOME}/bin/openmano-report'
+ su $SUDO_USER -c 'rm -f ${HOME}/bin/service-openmano'
+ su $SUDO_USER -c "ln -s '${BASEFOLDER}/openmano' "'${HOME}/bin/openmano'
+ su $SUDO_USER -c "ln -s '${BASEFOLDER}/scripts/openmano-report.sh' "'${HOME}/bin/openmano-report'
+ su $SUDO_USER -c "ln -s '${BASEFOLDER}/scripts/service-openmano' "'${HOME}/bin/service-openmano'
+
+ #insert /home/<user>/bin in the PATH
+ #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"
+ # su $SUDO_USER -c 'echo "PATH=\$PATH:\${HOME}/bin" >> ~/.bashrc'
+ #fi
+
+ if [[ $SUDO_USER == root ]]
then
- echo "PATH=\$PATH:\${HOME}/bin" >> ${HOME}/.bashrc
+ if ! echo $PATH | grep -q "${HOME}/bin"
+ then
+ echo "PATH=\$PATH:\${HOME}/bin" >> ${HOME}/.bashrc
+ fi
fi
-fi
+fi
#configure arg-autocomplete for this user
#in case of minimal instalation this package is not installed by default
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 [[ "$_DISTRO" == "Ubuntu" ]] && [[ ${_RELEASE%%.*} == 16 ]] && [[ -z $DEVELOP ]]
+ 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
+ echo -e "\n"\
+ "#################################################################\n"\
+ "##### CREATE AND INIT MANO_VIM DATABASE #####\n"\
+ "#################################################################"
+ # Install mano_vim_db after setup
+ ${OSMLIBOVIM_PATH}/database_utils/install-db-server.sh -U $DBUSER ${DBPASSWD_PARAM/p/P} -u mano -p manopw -d mano_vim_db --no-install-packages $DB_QUIET $DB_FORCE_UPDATE || exit 1
+fi # [ -z "$NO_DB" ]
+
+if [[ -n "$INSTALL_AS_A_SERVICE" ]]
then
-echo '
-#################################################################
-##### CONFIGURE OPENMANO SERVICE #####
-#################################################################'
-
- ${OPENMANO_BASEFOLDER}/scripts/install-openmano-service.sh -f ${OPENMANO_BASEFOLDER} #-u $SUDO_USER
-# alias service-openmano="service openmano"
-# echo 'alias service-openmano="service openmano"' >> ${HOME}/.bashrc
-
+ echo -e "\n"\
+ "#################################################################\n"\
+ "##### CONFIGURE OPENMANO SERVICE #####\n"\
+ "#################################################################"
+
+ ${BASEFOLDER}/scripts/install-openmano-service.sh -f ${BASEFOLDER} `[[ -z "$NOCLONE" ]] && echo "-d"`
+ # rm -rf ${BASEFOLDER}
+ # alias service-openmano="service openmano"
+ # echo 'alias service-openmano="service openmano"' >> ${HOME}/.bashrc
echo
- echo "Done! you may need to logout and login again for loading client configuration"
- echo " Manage server with 'service openmano start|stop|status|...' "
-
-
+ echo "Done! installed at /opt/openmano"
+ echo " Manage server with 'sudo -E service osm-ro start|stop|status|...' "
else
-
echo
echo "Done! you may need to logout and login again for loading client configuration"
- echo " Run './openmano/scripts/service-openmano.sh start' for starting openmano in a screen"
-
+ echo " Run './${BASEFOLDER}/scripts/service-openmano start' for starting openmano in a screen"
fi
-
-
-