Revert "Removing deprecated/unused/outdated code"
[osm/RO.git] / RO / osm_ro / scripts / install-lib-osm-openvim.sh
1 #!/bin/bash
2
3 ##
4 # Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U.
5 # This file is part of openmano
6 # All Rights Reserved.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
18 # under the License.
19 #
20 ##
21
22 # author: Alfonso Tierno
23
24 exit 0 # TODO py3 for the moment no openvim library is installed
25
26 # It uses following env, if not provided filling by default
27 [ -z "$GIT_OVIM_URL" ] && GIT_OVIM_URL=https://osm.etsi.org/gerrit/osm/openvim.git
28 [ -z "$DEVELOP" ] && DEVELOP=""
29 # folder where RO is installed
30 [ -z "$BASEFOLDER" ] && HERE=$(dirname $(readlink -f ${BASH_SOURCE[0]})) && BASEFOLDER=$(dirname $HERE)
31 [ -z "$SUDO_USER" ] && SUDO_USER="$USER"
32 [ -z "$NO_PACKAGES" ] && NO_PACKAGES=""
33 [ -z "$_DISTRO" ] && _DISTRO="Ubuntu"
34
35
36 function usage(){
37 echo -e "usage: sudo -E $0 [OPTIONS]"
38 echo -e "Install last stable source code of lib-osm-openvim and the needed packages"
39 echo -e " OPTIONS"
40 echo -e " -h --help: show this help"
41 echo -e " -b REFSPEC: install from source code using a specific branch (master, v2.0, ...) or tag"
42 echo -e " -b master (main branch)"
43 echo -e " -b v2.0 (v2.0 branch)"
44 echo -e " -b tags/v1.1.0 (a specific tag)"
45 echo -e " ..."
46 echo -e " --develop: install last master version for developers"
47 echo -e " --no-install-packages: use this option to skip updating and installing the requires packages. This" \
48 "avoid wasting time if you are sure requires packages are present e.g. because of a previous installation"
49 }
50 while getopts ":b:h-:" o; do
51 case "${o}" in
52 b)
53 export COMMIT_ID=${OPTARG}
54 ;;
55 h)
56 usage && exit 0
57 ;;
58 -)
59 [ "${OPTARG}" == "help" ] && usage && exit 0
60 [ "${OPTARG}" == "develop" ] && export DEVELOP="y" && continue
61 [ "${OPTARG}" == "quiet" ] && export QUIET_MODE=yes && export DEBIAN_FRONTEND=noninteractive && continue
62 [ "${OPTARG}" == "no-install-packages" ] && export NO_PACKAGES=yes && continue
63 echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
64 exit 1
65 ;;
66 \?)
67 echo -e "Invalid option: '-$OPTARG'\nTry $0 --help for more information" >&2
68 exit 1
69 ;;
70 :)
71 echo -e "Option '-$OPTARG' requires an argument\nTry $0 --help for more information" >&2
72 exit 1
73 ;;
74 *)
75 usage >&2
76 exit 1
77 ;;
78 esac
79 done
80
81 su $SUDO_USER -c "git -C '${BASEFOLDER}' clone ${GIT_OVIM_URL} lib-openvim" ||
82 ! echo "Error cannot clone from '${GIT_OVIM_URL}'" >&2 || exit 1
83 if [[ -n $COMMIT_ID ]] ; then
84 echo -e "Installing lib-osm-openvim from refspec: $COMMIT_ID"
85 su $SUDO_USER -c "git -C '${BASEFOLDER}/lib-openvim' checkout $COMMIT_ID" ||
86 ! echo "Error cannot checkout '$COMMIT_ID' from '${GIT_OVIM_URL}'" >&2 || exit 1
87 elif [[ -z $DEVELOP ]]; then
88 LATEST_STABLE_TAG=`git -C "${BASEFOLDER}/lib-openvim" tag -l "v[0-9]*" | sort -V | tail -n1`
89 echo -e "Installing lib-osm-openvim from refspec: tags/${LATEST_STABLE_TAG}"
90 su $SUDO_USER -c "git -C '${BASEFOLDER}/lib-openvim' checkout tags/${LATEST_STABLE_TAG}" ||
91 ! echo "Error cannot checkout 'tags/${LATEST_STABLE_TAG}' from '${GIT_OVIM_URL}'" >&2 || exit 1
92 else
93 echo -e "Installing lib-osm-openvim from refspec: master"
94 fi
95
96 make -C "${BASEFOLDER}/lib-openvim" prepare_lite
97 export LANG="en_US.UTF-8"
98 pip2 install -e "${BASEFOLDER}/lib-openvim/build" || ! echo "ERROR installing lib-osm-openvim library!!!" >&2 ||
99 exit 1