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