4 # Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U.
5 # This file is part of openmano
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
12 # http://www.apache.org/licenses/LICENSE-2.0
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
22 # author: Alfonso Tierno
24 # It uses following env, if not provided filling by default
25 [ -z "$GIT_OSMIM_URL" ] && GIT_OSMIM_URL
=https
://osm.etsi.org
/gerrit
/osm
/IM.git
26 [ -z "$DEVELOP" ] && DEVELOP
=""
27 # folder where RO is installed
28 [ -z "$BASEFOLDER" ] && HERE
=$
(dirname $
(readlink
-f ${BASH_SOURCE[0]})) && BASEFOLDER
=$
(dirname $
(dirname $HERE))
29 [ -z "$SUDO_USER" ] && SUDO_USER
="$USER"
30 [ -z "$NO_PACKAGES" ] && NO_PACKAGES
=""
31 [ -z "$_DISTRO" ] && _DISTRO
="Ubuntu"
34 echo -e "usage: sudo -E $0 [OPTIONS]"
35 echo -e "Install last stable source code of osm-im and the needed packages"
37 echo -e " -h --help: show this help"
38 echo -e " -b REFSPEC: install from source code using a specific branch (master, v2.0, ...) or tag"
39 echo -e " -b master (main branch)"
40 echo -e " -b v2.0 (v2.0 branch)"
41 echo -e " -b tags/v1.1.0 (a specific tag)"
43 echo -e " --develop: install last master version for developers"
44 echo -e " --no-install-packages: use this option to skip updating and installing the requires packages. This" \
45 "avoid wasting time if you are sure requires packages are present e.g. because of a previous installation"
47 while getopts ":b:h-:" o
; do
50 export COMMIT_ID
=${OPTARG}
56 [ "${OPTARG}" == "help" ] && usage
&& exit 0
57 [ "${OPTARG}" == "develop" ] && export DEVELOP
="y" && continue
58 [ "${OPTARG}" == "quiet" ] && export QUIET_MODE
=yes && export DEBIAN_FRONTEND
=noninteractive
&& continue
59 [ "${OPTARG}" == "no-install-packages" ] && export NO_PACKAGES
=yes && continue
60 echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
64 echo -e "Invalid option: '-$OPTARG'\nTry $0 --help for more information" >&2
68 echo -e "Option '-$OPTARG' requires an argument\nTry $0 --help for more information" >&2
78 su
$SUDO_USER -c "git -C ${BASEFOLDER} clone ${GIT_OSMIM_URL} IM" ||
79 ! echo "Error cannot clone from '${GIT_OSMIM_URL}'" >&2 ||
exit 1
80 if [[ -n $COMMIT_ID ]] ; then
81 echo -e "Installing osm-IM from refspec: $COMMIT_ID"
82 su
$SUDO_USER -c "git -C ${BASEFOLDER}/IM checkout $COMMIT_ID" ||
83 ! echo "Error cannot checkout '$COMMIT_ID' from '${GIT_OSMIM_URL}'" >&2 ||
exit 1
84 elif [[ -z $DEVELOP ]]; then
85 LATEST_STABLE_TAG
=`git -C "${BASEFOLDER}/IM" tag -l "v[0-9]*" | sort -V | tail -n1`
86 echo -e "Installing osm-IM from refspec: tags/${LATEST_STABLE_TAG}"
87 su
$SUDO_USER -c "git -C ${BASEFOLDER}/IM checkout tags/${LATEST_STABLE_TAG}" ||
88 ! echo "Error cannot checkout 'tags/${LATEST_STABLE_TAG}' from '${GIT_OSMIM_URL}'" >&2 ||
exit 1
90 echo -e "Installing osm-IM from refspec: master"
93 # Install debian dependencies before setup.py
94 if [[ -z "$NO_PACKAGES" ]]
97 # apt-get install -y git python-pip
98 # pip2 install pip==9.0.3
99 python3
-m pip
install pyangbind ||
exit 1
102 PYBINDPLUGIN
=$
(python3
-c 'import pyangbind; import os; print(os.path.dirname(pyangbind.__file__)+"/plugin")')
103 su
$SUDO_USER -c 'mkdir -p "'${BASEFOLDER}/IM
/osm_im
'"'
104 su
$SUDO_USER -c 'touch "'${BASEFOLDER}/IM
/osm_im
/__init__.py
'"'
105 # wget -q https://raw.githubusercontent.com/RIFTIO/RIFT.ware/RIFT.ware-4.4.1/modules/core/util/yangtools/yang/rw-pb-ext.yang -O "${BASEFOLDER}/IM/models/yang/rw-pb-ext.yang"
106 for target
in vnfd nsd
; do
107 pyang
-Werror --path "${BASEFOLDER}/IM/models/yang" --plugindir "${PYBINDPLUGIN}" -f pybind \
108 -o "${BASEFOLDER}/IM/osm_im/${target}.py" "${BASEFOLDER}/IM/models/yang/${target}.yang"
111 python3
-m pip
install -e "${BASEFOLDER}/IM" ||
! echo "ERROR installing python-osm-im library!!!" >&2 ||
exit 1