X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=scripts%2Finstall-openmano.sh;h=4a2ff7252fd4f1328e5269a293dd345de41874dd;hb=60f4d2287e906417f151f8b41f07493eb1bf5af4;hp=e9398b76bcfbec9c1126c1c3ad8d3689743eb0c9;hpb=2e7e709fbf156dec14edcf3ae22fd982864b2989;p=osm%2FRO.git diff --git a/scripts/install-openmano.sh b/scripts/install-openmano.sh index e9398b76..4a2ff725 100755 --- a/scripts/install-openmano.sh +++ b/scripts/install-openmano.sh @@ -21,7 +21,7 @@ # contact with: nfvlabs@tid.es ## -#ONLY TESTED for Ubuntu 14.10 14.04, CentOS7 and RHEL7 +#ONLY TESTED in Ubuntu 16.04 #Get needed packages, source code and configure to run openmano #Ask for database user and password if not provided # $1: database user @@ -29,12 +29,16 @@ function usage(){ echo -e "usage: sudo $0 [OPTIONS]" - echo -e "Install source code in ./openmano and the needed packages" + 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 " -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: install in an unattended mode" - echo -e " -h: show this help" + 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 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 mano_db DB, deleting previous database and creating a new one" + echo -e " --noclone: assumes that openmano was cloned previously and that this script is run from the local repo" } function install_packages(){ @@ -50,15 +54,29 @@ function install_packages(){ if [ "$PACKAGE_INSTALLED" = "no" ] then echo "failed to install package '$PACKAGE'. Revise network connectivity and try again" >&2 - exit -1 + exit 1 fi 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 +} + +GIT_URL=https://osm.etsi.org/gerrit/osm/RO.git DBUSER="root" DBPASSWD="" DBPASSWD_PARAM="" QUIET_MODE="" +DEVELOP="" +FORCEDB="" +NOCLONE="" while getopts ":u:p:hiq-:" o; do case "${o}" in u) @@ -77,6 +95,10 @@ while getopts ":u:p:hiq-:" o; do ;; -) [ "${OPTARG}" == "help" ] && usage && exit 0 + [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue + [ "${OPTARG}" == "forcedb" ] && FORCEDB="y" && continue + [ "${OPTARG}" == "noclone" ] && NOCLONE="y" && continue + [ "${OPTARG}" == "quiet" ] && export QUIET_MODE=yes && export DEBIAN_FRONTEND=noninteractive && continue echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2 exit 1 ;; @@ -90,13 +112,13 @@ while getopts ":u:p:hiq-:" o; do ;; *) usage >&2 - exit -1 + exit 1 ;; esac done #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 [[ -z $QUIET_MODE ]] && read -e -p "Install in the root user (y/N)?" KK @@ -111,11 +133,12 @@ fi [ -f /etc/redhat-release ] || _DISTRO=$(lsb_release -is 2>/dev/null) if [ "$_DISTRO" == "Ubuntu" ] then - _RELEASE="14" - if ! lsb_release -rs | grep -q "14." + _RELEASE=$(lsb_release -rs) + if [[ ${_RELEASE%%.*} != 14 ]] && [[ ${_RELEASE%%.*} != 16 ]] then - [[ -z $QUIET_MODE ]] && read -e -p "WARNING! Not tested Ubuntu version. Continue assuming a '$_RELEASE' type? (y/N)" KK + [[ -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 + _RELEASE = 14 fi elif [ "$_DISTRO" == "CentOS" ] then @@ -192,7 +215,7 @@ fi if [[ -n $QUIET_MODE ]] then echo -e "\nCheking database connection and ask for credentials" - while ! mysqladmin -s -u$DBUSER $DBPASSWD_PARAM ping + 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" @@ -219,23 +242,68 @@ echo ' [ "$_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 -echo ' +if [[ -z $NOCLONE ]]; then + echo ' ################################################################# ##### DOWNLOAD SOURCE ##### #################################################################' -su $SUDO_USER -c 'git clone https://osm.etsi.org/gerrit/osm/openmano.git openmano' + su $SUDO_USER -c 'git clone '"${GIT_URL}"' openmano' + #[[ -z $DEVELOP ]] && su $SUDO_USER -c 'git checkout ' +fi echo ' ################################################################# ##### CREATE DATABASE ##### #################################################################' -mysqladmin -u$DBUSER $DBPASSWD_PARAM -s create mano_db || exit 1 +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" </bin in the PATH #skiped because normally this is done authomatically when ~/bin exist @@ -306,9 +375,32 @@ then su $SUDO_USER -c 'echo ". ${HOME}/.bash_completion.d/python-argcomplete.sh" >> ~/.bashrc' fi -echo -echo "Done! you may need to logout and login again for loading the configuration" -echo " Run './openmano/scripts/service-openmano.sh start' for starting openmano in a screen" + + + +if [[ "$_DISTRO" == "Ubuntu" ]] && [[ ${_RELEASE%%.*} == 16 ]] && [[ -z $DEVELOP ]] +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 + echo "Done! you may need to logout and login again for loading client configuration" + echo " Manage server with 'service openmano 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" + +fi