Restructure O1 module to run as a thread in O-DU High binary [Issue-Id: ODUHIGH-297]
[o-du/l2.git] / build / scripts / install_lib.sh
1 ################################################################################
2 #   Copyright (c) [2020-2021] [HCL Technologies Ltd]                           #
3 #                                                                              #
4 #   Licensed under the Apache License, Version 2.0 (the "License");            #
5 #   you may not use this file except in compliance with the License.           #
6 #   You may obtain a copy of the License at                                    #
7 #                                                                              #
8 #       http://www.apache.org/licenses/LICENSE-2.0                             #
9 #                                                                              #
10 #   Unless required by applicable law or agreed to in writing, software        #
11 #   distributed under the License is distributed on an "AS IS" BASIS,          #
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
13 #   See the License for the specific language governing permissions and        #
14 #   limitations under the License.                                             #
15 ################################################################################
16
17 #!/bin/bash
18
19 # Pre-requisite script for installing Netconf Libraries
20 # and compiling the O1 module
21
22 #variable declaration
23 CURRENT_PATH=`pwd`
24 HOME="$CURRENT_PATH/../.."
25 NETCONF_PATH="$HOME/build/netconf"
26 YANG_PATH="$HOME/build/yang"
27 CONFIG_PATH="$HOME/build/config"
28 STARTUP_CONFIG="startup_config.xml"
29
30 INSTALL="netconf"
31 CLEANUP="no"
32 SUDO="sudo"
33
34 #logging functions
35 log_error(){
36    echo ""
37    echo -e "\e[1;31m *****  $1  ***** \e[0m"
38    echo ""
39 }
40 log_warning() {
41    echo ""
42    echo -e "\e[1;35m *****  $1  ***** \e[0m"
43    echo ""
44 }
45 log_success() {   
46    echo ""
47    echo -e "\e[1;32m *****  $1  ***** \e[0m"
48    echo ""
49 }
50 log()         {
51    echo -e "$1 "
52 }
53
54 #install pre-requisite packages
55
56 prerequisite_netconf() {
57       $SUDO apt-get update
58
59       $SUDO apt-get install -y jq \
60       cmake \
61       build-essential \
62       supervisor \
63       libpcre3-dev \
64       pkg-config \
65       libavl-dev \
66       libev-dev \
67       libprotobuf-c-dev \
68       protobuf-c-compiler \
69       libssh-dev \
70       libssl-dev \
71       swig \
72       iputils-ping \
73       python-dev
74 }
75
76 #check return value
77 check_ret() {
78
79    if [ $2 -eq 0 ]; then
80       log_success " $1 INSTALLATION DONE"
81    else
82       log_error " $1 INSTALLATION FAILED "
83       show_help
84    fi
85 }
86
87
88 #install netconf  libraries
89 install_netconf_lib() {
90
91    if [[ "$CLEANUP" == "cleanup" ]]; then
92       rm -rf $NETCONF_PATH
93       log_warning "DELETED $NETCONF_PATH"
94    fi
95
96    mkdir -p $NETCONF_PATH
97
98    #1. libssh
99    cd $NETCONF_PATH && \
100       git clone -b v0-7 --depth 1 http://git.libssh.org/projects/libssh.git && \
101       cd libssh; mkdir build; cd build && \
102       cmake .. && \
103       make && \
104       $SUDO make install
105
106    check_ret "LIBSSH" "$?"
107
108    # libyang
109    cd $NETCONF_PATH && \
110       git clone -b v1.0.184 --depth 1 https://github.com/CESNET/libyang.git && \
111       cd libyang && mkdir build && cd build && \
112       cmake -DGEN_LANGUAGE_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF \
113             -DCMAKE_BUILD_TYPE:String="Debug" -DENABLE_BUILD_TESTS=OFF .. && \
114       make -j2 && \
115       $SUDO make install && \
116       $SUDO ldconfig
117
118    check_ret "LIBYANG" "$?"
119
120    # sysrepo
121    cd $NETCONF_PATH && \
122       git clone -b v1.4.70 --depth 1  https://github.com/sysrepo/sysrepo.git && \
123       cd sysrepo && sed -i -e 's/2000/30000/g;s/5000/30000/g' src/common.h.in && \
124       mkdir build && cd build && \
125       cmake -DGEN_LANGUAGE_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF \
126             -DCMAKE_BUILD_TYPE:String="Debug" -DENABLE_TESTS=OFF \
127             -DREPOSITORY_LOC:PATH=/etc/sysrepo .. && \
128       make -j2 && \
129       $SUDO make install && $SUDO make sr_clean && \
130       $SUDO ldconfig
131
132    check_ret "SYSREPO" "$?"
133
134    # libnetconf2
135    cd $NETCONF_PATH && \
136       git clone -b v1.1.36 --depth 1 https://github.com/CESNET/libnetconf2.git && \
137       cd libnetconf2 && mkdir build && cd build && \
138       cmake -DCMAKE_BUILD_TYPE:String="Debug" -DENABLE_BUILD_TESTS=OFF .. && \
139       make -j2 && \
140       $SUDO make install && \
141       $SUDO ldconfig
142
143    check_ret "LIBNETCONF2" "$?"
144
145    # netopeer2
146    cd $NETCONF_PATH && \
147       git clone -b v1.1.53 --depth 1 https://github.com/CESNET/Netopeer2.git && \
148       cd Netopeer2 && mkdir build && cd build && \
149       cmake -DCMAKE_BUILD_TYPE:String="Debug" -DNP2SRV_DATA_CHANGE_TIMEOUT=30000 \
150             -DNP2SRV_DATA_CHANGE_WAIT=OFF .. && \
151       make -j2 && \
152       $SUDO make install -d
153    check_ret "NETOPEER2" "$?"
154
155 }
156
157 #install yang module
158
159 install_yang_module() {
160    sysrepoctl -i "$YANG_PATH/o-ran-sc-odu-alarm-v1.yang"
161    sysrepoctl -i "$YANG_PATH/o-ran-sc-odu-interface-v1.yang"
162    sysrepocfg --import="$CONFIG_PATH/$STARTUP_CONFIG" --datastore startup --module  o-ran-sc-odu-interface-v1
163 }
164
165
166 #wait for ack of user
167 acknowledge() {
168    echo "$1"
169    read -n 1 -p "Press any key to continue, or CTRL+C to abort" mainmenuinout
170    echo
171    }
172
173 #show help for user to provide valid input
174 show_help(){
175    echo "use -c option for cleanup"
176    echo "ex : $./install_lib.sh -c"
177    exit
178 }
179
180 main() {
181
182    unset INSTALL CLEANUP
183    while (( "$#" )); do
184       case "$1" in
185          -h|\?)
186             show_help
187             shift
188             exit 0
189             ;;
190          -c)  CLEANUP="cleanup"
191             shift
192             ;;
193       esac
194    done
195
196    shift $((OPTIND-1))
197
198    [ "${1:-}" = "--" ] && shift
199
200    log_success "MAIN: PARSING OF ARGUMENT DONE"
201
202 }
203
204 #start execution / function calls
205 if [[ "$#" -ge 3 ]] ; then
206    log_error " NUMBER OF PARAMETER : $# "
207    show_help
208 fi
209
210 main $@
211
212 prerequisite_netconf
213
214 install_netconf_lib
215
216 #yang installation yet not enabled
217 if [[ "$INSTALL" == "yang" ]] ; then
218 {
219    log " YANG INSTALLATION PROCESSING "
220    install_yang_module
221    log_success " YANG INSTALLATION DONE "
222 }
223 fi
224
225
226 log_success " SCRIPT COMPLETED"
227 exit
228
229 #**********************************************************************
230 #    End of file
231 #**********************************************************************