inject_user_key routine fixes
[osm/RO.git] / 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 # It uses following env, if not provided filling by default
25 [ -z "$GIT_OVIM_URL" ] && GIT_OVIM_URL=https://osm.etsi.org/gerrit/osm/openvim.git
26 [ -z "$DEVELOP" ] && DEVELOP=""
27 # folder where RO is installed
28 [ -z "$BASEFOLDER" ] && HERE=$(dirname $(readlink -f ${BASH_SOURCE[0]})) && BASEFOLDER=$(dirname $HERE)
29 [ -z "$SUDO_USER" ] && SUDO_USER="$USER"
30 [ -z "$NO_PACKAGES" ] && NO_PACKAGES=""
31 [ -z "$_DISTRO" ] && _DISTRO="Ubuntu"
32
33
34 function usage(){
35 echo -e "usage: sudo -E $0 [OPTIONS]"
36 echo -e "Install last stable source code of lib-osm-openvim and the needed packages"
37 echo -e " OPTIONS"
38 echo -e " -h --help: show this help"
39 echo -e " -b REFSPEC: install from source code using a specific branch (master, v2.0, ...) or tag"
40 echo -e " -b master (main branch)"
41 echo -e " -b v2.0 (v2.0 branch)"
42 echo -e " -b tags/v1.1.0 (a specific tag)"
43 echo -e " ..."
44 echo -e " --develop: install last master version for developers"
45 echo -e " --no-install-packages: use this option to skip updating and installing the requires packages. This" \
46 "avoid wasting time if you are sure requires packages are present e.g. because of a previous installation"
47 }
48 while getopts ":b:h-:" o; do
49 case "${o}" in
50 b)
51 export COMMIT_ID=${OPTARG}
52 ;;
53 h)
54 usage && exit 0
55 ;;
56 -)
57 [ "${OPTARG}" == "help" ] && usage && exit 0
58 [ "${OPTARG}" == "develop" ] && export DEVELOP="y" && continue
59 [ "${OPTARG}" == "quiet" ] && export QUIET_MODE=yes && export DEBIAN_FRONTEND=noninteractive && continue
60 [ "${OPTARG}" == "no-install-packages" ] && export NO_PACKAGES=yes && continue
61 echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
62 exit 1
63 ;;
64 \?)
65 echo -e "Invalid option: '-$OPTARG'\nTry $0 --help for more information" >&2
66 exit 1
67 ;;
68 :)
69 echo -e "Option '-$OPTARG' requires an argument\nTry $0 --help for more information" >&2
70 exit 1
71 ;;
72 *)
73 usage >&2
74 exit 1
75 ;;
76 esac
77 done
78
79 su $SUDO_USER -c "git -C '${BASEFOLDER}' clone ${GIT_OVIM_URL} lib-openvim" ||
80 ! echo "Error cannot clone from '${GIT_OVIM_URL}'" >&2 || exit 1
81 if [[ -n $COMMIT_ID ]] ; then
82 echo -e "Installing lib-osm-openvim from refspec: $COMMIT_ID"
83 su $SUDO_USER -c "git -C '${BASEFOLDER}/lib-openvim' checkout $COMMIT_ID" ||
84 ! echo "Error cannot checkout '$COMMIT_ID' from '${GIT_OVIM_URL}'" >&2 || exit 1
85 elif [[ -z $DEVELOP ]]; then
86 LATEST_STABLE_TAG=`git -C "${BASEFOLDER}/lib-openvim" tag -l "v[0-9]*" | sort -V | tail -n1`
87 echo -e "Installing lib-osm-openvim from refspec: tags/${LATEST_STABLE_TAG}"
88 su $SUDO_USER -c "git -C '${BASEFOLDER}/lib-openvim' checkout tags/${LATEST_STABLE_TAG}" ||
89 ! echo "Error cannot checkout 'tags/${LATEST_STABLE_TAG}' from '${GIT_OVIM_URL}'" >&2 || exit 1
90 else
91 echo -e "Installing lib-osm-openvim from refspec: master"
92 fi
93
94 make -C "${BASEFOLDER}/lib-openvim" prepare_lite
95 export LANG="en_US.UTF-8"
96 pip2 install -e "${BASEFOLDER}/lib-openvim/build" || ! echo "ERROR installing lib-osm-openvim library!!!" >&2 ||
97 exit 1