Fix bug 535 propagate instantiaon paramget mac_address
[osm/RO.git] / scripts / install-openmano.sh
index ac28f0d..7d1df99 100755 (executable)
@@ -26,7 +26,7 @@
 #Ask for database user and password if not provided
 
 function usage(){
 #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 "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"
@@ -34,6 +34,11 @@ function usage(){
     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 "     -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 if exists and creating a new one"
     echo -e "     --updatedb: do not reinstall mano_db DB if it exists, just update database"
     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 if exists and creating a new one"
     echo -e "     --updatedb: do not reinstall mano_db DB if it exists, just update database"
@@ -77,6 +82,7 @@ function ask_user(){
 
 GIT_URL=https://osm.etsi.org/gerrit/osm/RO.git
 GIT_OVIM_URL=https://osm.etsi.org/gerrit/osm/openvim.git
 
 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=""
 DBUSER="root"
 DBPASSWD=""
 DBPASSWD_PARAM=""
@@ -88,8 +94,9 @@ FORCE=""
 NOCLONE=""
 NO_PACKAGES=""
 NO_DB=""
 NOCLONE=""
 NO_PACKAGES=""
 NO_DB=""
+COMMIT_ID=""
 
 
-while getopts ":u:p:hiq-:" o; do
+while getopts ":u:p:b:hiq-:" o; do
     case "${o}" in
         u)
             export DBUSER="$OPTARG"
     case "${o}" in
         u)
             export DBUSER="$OPTARG"
@@ -98,6 +105,9 @@ while getopts ":u:p:hiq-:" o; do
             export DBPASSWD="$OPTARG"
             export DBPASSWD_PARAM="-p$OPTARG"
             ;;
             export DBPASSWD="$OPTARG"
             export DBPASSWD_PARAM="-p$OPTARG"
             ;;
+        b)
+            export COMMIT_ID=${OPTARG}
+            ;;
         q)
             export QUIET_MODE=yes
             export DEBIAN_FRONTEND=noninteractive
         q)
             export QUIET_MODE=yes
             export DEBIAN_FRONTEND=noninteractive
@@ -213,13 +223,14 @@ then
         "#################################################################\n"\
         "#####        UPDATE REPOSITORIES                            #####\n"\
         "#################################################################"
         "#################################################################\n"\
         "#####        UPDATE REPOSITORIES                            #####\n"\
         "#################################################################"
-    [ "$_DISTRO" == "Ubuntu" ] && apt-get update -y
+    [ "$_DISTRO" == "Ubuntu" ] && apt-get update -y &&
+        add-apt-repository -y cloud-archive:pike && apt-get update -y
 
     [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && yum check-update -y
 
     [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && yum check-update -y
-    [ "$_DISTRO" == "CentOS" ] && sudo yum install -y epel-release
+    [ "$_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 \
     [ "$_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
+        && 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"\
 
     echo -e "\n"\
         "#################################################################\n"\
@@ -232,17 +243,25 @@ then
         "#################################################################\n"\
         "#####        INSTALL PYTHON PACKAGES                        #####\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"
-    [ "$_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"
+    [ "$_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
     # 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
-    sudo pip install --upgrade pip
-    sudo pip install pyvcloud
-    sudo pip install progressbar
-    sudo pip install prettytable
-    sudo pip install pyvmomi
+    pip2 install pip==9.0.3 || exit 1   #  --upgrade pip    install pip 10 that does not work
+    pip2 install pyvcloud==19.1.1 || exit 1
+    pip2 install progressbar || exit 1
+    pip2 install prettytable || exit 1
+    pip2 install pyvmomi || exit 1
+
+    # required for OpenNebula connector
+    pip2 install untangle || exit 1
+    pip2 install -e git+https://github.com/python-oca/python-oca#egg=oca || exit 1
 
     # required for AWS connector
     [ "$_DISTRO" == "Ubuntu" ] && install_packages "python-boto"
 
     # required for AWS connector
     [ "$_DISTRO" == "Ubuntu" ] && install_packages "python-boto"
@@ -272,26 +291,91 @@ if [[ -z $NOCLONE ]]; then
             echo "'${BASEFOLDER}' folder exists. Use "--force" to overwrite" >&2 && exit 1
         fi
     fi
             echo "'${BASEFOLDER}' folder exists. Use "--force" to overwrite" >&2 && exit 1
         fi
     fi
-    su $SUDO_USER -c "git clone ${GIT_URL} ${BASEFOLDER}"
-    LATEST_STABLE_TAG=`git -C "${BASEFOLDER}" tag -l v[0-9].* | tail -n1`
-    [[ -z $DEVELOP ]] && su $SUDO_USER -c "git -C ${BASEFOLDER} checkout tags/${LATEST_STABLE_TAG}"
+    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
 
     su $SUDO_USER -c "cp ${BASEFOLDER}/.gitignore-common ${BASEFOLDER}/.gitignore"
 fi
 
+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
+    [ "$_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"
+    pip2 install --upgrade stdeb pyangbind || 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"\
     "#################################################################"
 echo -e "\n"\
     "#################################################################\n"\
     "#####        INSTALLING OVIM LIBRARY                        #####\n"\
     "#################################################################"
-su $SUDO_USER -c "git -C ${BASEFOLDER} clone ${GIT_OVIM_URL} openvim"
-LATEST_STABLE_TAG=`git -C "${BASEFOLDER}/openvim" tag -l v[0-9].* | tail -n1`
-[[ -z $DEVELOP ]] && su $SUDO_USER -c "git -C ${BASEFOLDER}/openvim checkout tags/${LATEST_STABLE_TAG}"
+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
+    echo -e "Installing lib_osm_openvim from refspec: master"
+fi
 
 # Install debian dependencies before setup.py
 
 # Install debian dependencies before setup.py
-[ "$_DISTRO" == "Ubuntu" ] && install_packages "libmysqlclient-dev"
-[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "libmysqlclient-dev"  #TODO check if that's the name in CentOS and RedHat
-make -C ${BASEFOLDER}/openvim lite
+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"
+    pip2 install --upgrade stdeb setuptools-version-command || exit 1
+fi
+su $SUDO_USER -c "make -C ${BASEFOLDER}/openvim lite"
+dpkg -i ${BASEFOLDER}/openvim/.build/python-lib-osm-openvim*.deb
 rm -rf "${BASEFOLDER}/openvim"
 rm -rf "${BASEFOLDER}/openvim"
-OSMLIBOVIM_PATH=`python -c 'import lib_osm_openvim; print lib_osm_openvim.__path__[0]'`
+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
 
 if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ]
 then
@@ -396,7 +480,7 @@ then
     # echo 'alias service-openmano="service openmano"' >> ${HOME}/.bashrc
     echo
     echo "Done!  installed at /opt/openmano"
     # echo 'alias service-openmano="service openmano"' >> ${HOME}/.bashrc
     echo
     echo "Done!  installed at /opt/openmano"
-    echo " Manage server with 'sudo service osm-ro start|stop|status|...' "
+    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"
 else
     echo
     echo "Done!  you may need to logout and login again for loading client configuration"