[Task-ID: ODUHIGH-608] | Fix for o-du-l2-docker-verify-master failure
[o-du/l2.git] / build / scripts / install_lib_O1.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 -c http.sslverify=false --depth 1 https://github.com/libssh/libssh-mirror.git && \
101       mv libssh-mirror libssh && \
102       cd libssh; mkdir build; cd build && \
103       cmake .. && \
104       make && \
105       $SUDO make install
106
107    check_ret "LIBSSH" "$?"
108
109    #cJSON
110    cd $NETCONF_PATH && \
111       git clone --single-branch --branch v1.7.14 https://github.com/DaveGamble/cJSON.git && \
112       cd cJSON && \
113       mkdir build && cd build && \
114       cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_CJSON_TEST=Off && \
115       make -j4 && \
116       $SUDO make install && \
117       $SUDO ldconfig
118    check_ret "LIBJSON" "$?"
119
120    #CURL
121    cd $NETCONF_PATH && \
122       git clone --single-branch --branch curl-7_72_0 https://github.com/curl/curl.git &&\
123       cd curl && \
124       mkdir build && cd build && \
125       cmake -DBUILD_TESTING=OFF .. && \
126       make -j4 && \
127       $SUDO make install && \
128       $SUDO ldconfig
129    check_ret "LIBCURL" "$?"
130
131    # libyang
132    cd $NETCONF_PATH && \
133       git clone -b v1.0.184 --depth 1 https://github.com/CESNET/libyang.git && \
134       cd libyang && mkdir build && cd build && \
135       cmake -DGEN_LANGUAGE_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF \
136             -DCMAKE_BUILD_TYPE:String="Debug" -DENABLE_BUILD_TESTS=OFF .. && \
137       make -j2 && \
138       $SUDO make install && \
139       $SUDO ldconfig
140
141    check_ret "LIBYANG" "$?"
142
143    # sysrepo
144    cd $NETCONF_PATH && \
145       git clone -b v1.4.70 --depth 1  https://github.com/sysrepo/sysrepo.git && \
146       cd sysrepo && sed -i -e 's/2000/30000/g;s/5000/30000/g' src/common.h.in && \
147       mkdir build && cd build && \
148       cmake -DGEN_LANGUAGE_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF \
149             -DCMAKE_BUILD_TYPE:String="Debug" -DENABLE_TESTS=OFF \
150             -DREPOSITORY_LOC:PATH=/etc/sysrepo .. && \
151       make -j2 && \
152       $SUDO make install && $SUDO make sr_clean && \
153       $SUDO ldconfig
154
155    check_ret "SYSREPO" "$?"
156
157    # libnetconf2
158    cd $NETCONF_PATH && \
159       git clone -b v1.1.36 --depth 1 https://github.com/CESNET/libnetconf2.git && \
160       cd libnetconf2 && mkdir build && cd build && \
161       cmake -DCMAKE_BUILD_TYPE:String="Debug" -DENABLE_BUILD_TESTS=OFF .. && \
162       make -j2 && \
163       $SUDO make install && \
164       $SUDO ldconfig
165
166    check_ret "LIBNETCONF2" "$?"
167
168    # netopeer2
169    cd $NETCONF_PATH && \
170       git clone -b v1.1.53 --depth 1 https://github.com/CESNET/Netopeer2.git && \
171       cd Netopeer2 && mkdir build && cd build && \
172       cmake -DCMAKE_BUILD_TYPE:String="Debug" -DNP2SRV_DATA_CHANGE_TIMEOUT=30000 \
173             -DNP2SRV_DATA_CHANGE_WAIT=OFF .. && \
174       make -j2 && \
175       $SUDO make install -d
176    check_ret "NETOPEER2" "$?"
177
178 }
179
180 #install yang module
181
182 install_yang_module() {
183    sysrepoctl -i "$YANG_PATH/o-ran-sc-odu-alarm-v1.yang"
184    sysrepoctl -i "$YANG_PATH/o-ran-sc-odu-interface-v1.yang"
185    sysrepocfg --import="$CONFIG_PATH/$STARTUP_CONFIG" --datastore startup --module  o-ran-sc-odu-interface-v1
186 }
187
188
189 #wait for ack of user
190 acknowledge() {
191    echo "$1"
192    read -n 1 -p "Press any key to continue, or CTRL+C to abort" mainmenuinout
193    echo
194    }
195
196 #show help for user to provide valid input
197 show_help(){
198    echo "use -c option for cleanup"
199    echo "ex : $./install_lib_O1.sh -c"
200    exit
201 }
202
203 main() {
204
205    unset INSTALL CLEANUP
206    while (( "$#" )); do
207       case "$1" in
208          -h|\?)
209             show_help
210             shift
211             exit 0
212             ;;
213          -c)  CLEANUP="cleanup"
214             shift
215             ;;
216       esac
217    done
218
219    shift $((OPTIND-1))
220
221    [ "${1:-}" = "--" ] && shift
222
223    log_success "MAIN: PARSING OF ARGUMENT DONE"
224
225 }
226
227 #start execution / function calls
228 if [[ "$#" -ge 3 ]] ; then
229    log_error " NUMBER OF PARAMETER : $# "
230    show_help
231 fi
232
233 main $@
234
235 prerequisite_netconf
236
237 install_netconf_lib
238
239 #yang installation yet not enabled
240 if [[ "$INSTALL" == "yang" ]] ; then
241 {
242    log " YANG INSTALLATION PROCESSING "
243    install_yang_module
244    log_success " YANG INSTALLATION DONE "
245 }
246 fi
247
248
249 log_success " SCRIPT COMPLETED"
250 exit
251
252 #**********************************************************************
253 #    End of file
254 #**********************************************************************