updated Dockerfile for O1 Module [Issue-Id: ODUHIGH-257]
[o-du/l2.git] / build / o1 / 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 MAKE_PATH="$HOME/build/o1"
26 NETCONF_PATH="$HOME/build/o1/netconf"
27 SYSREPOCTL_PATH="$NETCONF_PATH/sysrepo/build/sysrepoctl"
28 YANG_PATH="$HOME/build/o1/yang"
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
55
56 #functions definitions
57 #TBD: install only mandatory packages
58
59 #install pre-requisite packages
60
61 prerequisite_netconf() {
62       $SUDO apt-get update
63
64       $SUDO apt-get install -y jq \
65       cmake \
66       build-essential \
67       supervisor \
68       libpcre3-dev \
69       pkg-config \
70       libavl-dev \
71       libev-dev \
72       libprotobuf-c-dev \
73       protobuf-c-compiler \
74       libssh-dev \
75       libssl-dev \
76       swig \
77       iputils-ping \
78       python-dev
79 }
80
81 #check return value
82 check_ret() {
83
84    if [ $2 -eq 0 ]; then
85       log_success " $1 INSTALLATION DONE"
86    else
87       log_error " $1 INSTALLATION FAILED "
88       show_help
89    fi
90 }
91
92
93 #install netconf  libraries
94 install_netconf_lib() {
95
96    #with sudo we can not create new user so we need to create it manually using 
97    #root credentials.
98
99       #$SUDO adduser --system netconf && \
100       #      echo "netconf:netconf" | chpasswd
101
102       #$SUDO mkdir -p /home/netconf/.ssh && \
103       #      ssh-keygen -A && \
104       #      ssh-keygen -t dsa -P '' -f /home/netconf/.ssh/id_dsa && \
105       #      cat /home/netconf/.ssh/id_dsa.pub > /home/netconf/.ssh/authorized_keys
106
107    if [[ "$CLEANUP" == "cleanup" ]]; then
108       rm -rf $NETCONF_PATH
109       log_warning "DELETED $NETCONF_PATH"
110    fi
111
112    mkdir -p $NETCONF_PATH
113
114    #1. libssh
115    cd $NETCONF_PATH && \
116       git clone http://git.libssh.org/projects/libssh.git && \
117       cd libssh; mkdir build; cd build && \
118       cmake .. && \
119       make && \
120       $SUDO make install
121
122    check_ret "LIBSSH" "$?"
123
124    # libyang
125    cd $NETCONF_PATH && \
126       git clone https://github.com/CESNET/libyang.git && \
127       cd libyang && mkdir build && cd build && \
128       cmake -DGEN_LANGUAGE_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF \
129             -DCMAKE_BUILD_TYPE:String="Debug" -DENABLE_BUILD_TESTS=OFF .. && \
130       make -j2 && \
131       $SUDO make install && \
132       $SUDO ldconfig
133
134    check_ret "LIBYANG" "$?"
135
136    # sysrepo
137    cd $NETCONF_PATH && \
138       git clone https://github.com/sysrepo/sysrepo.git && \
139       cd sysrepo && sed -i -e 's/2000/30000/g;s/5000/30000/g' src/common.h.in && \
140       mkdir build && cd build && \
141       cmake -DGEN_LANGUAGE_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF \
142             -DCMAKE_BUILD_TYPE:String="Debug" -DENABLE_TESTS=OFF \
143             -DREPOSITORY_LOC:PATH=/etc/sysrepo .. && \
144       make -j2 && \
145       $SUDO make install && $SUDO make sr_clean && \
146       $SUDO ldconfig
147
148    check_ret "SYSREPO" "$?"
149
150    # libnetconf2
151    cd $NETCONF_PATH && \
152       git clone https://github.com/CESNET/libnetconf2.git && \
153       cd libnetconf2 && mkdir build && cd build && \
154       cmake -DCMAKE_BUILD_TYPE:String="Debug" -DENABLE_BUILD_TESTS=OFF .. && \
155       make -j2 && \
156       $SUDO make install && \
157       $SUDO ldconfig
158
159    check_ret "LIBNETCONF2" "$?"
160
161    # netopeer2
162    cd $NETCONF_PATH && \
163       git clone https://github.com/CESNET/Netopeer2.git && \
164       cd Netopeer2 && mkdir build && cd build && \
165       cmake -DCMAKE_BUILD_TYPE:String="Debug" -DNP2SRV_DATA_CHANGE_TIMEOUT=30000 \
166             -DNP2SRV_DATA_CHANGE_WAIT=OFF .. && \
167       make -j2 && \
168       $SUDO make install -d
169    check_ret "NETOPEER2" "$?"
170
171 }
172
173 #install yang module
174
175 install_yang_module() {
176    $SYSREPOCTL_PATH -i "$YANG_PATH/o-ran-sc-du-alarm-v1.yang"
177 }
178
179
180 #wait for ack of user
181 acknowledge() {
182    echo "$1"
183    read -n 1 -p "Press any key to continue, or CTRL+C to abort" mainmenuinout
184    echo
185    }
186
187 #show help for user to provide valid input
188 show_help(){
189    echo "use -c option for cleanup"
190    echo "ex : $./install_lib.sh -c"
191    exit
192 }
193
194 main() {
195
196    unset INSTALL CLEANUP
197    while (( "$#" )); do
198       case "$1" in
199          -h|\?)
200             show_help
201             shift
202             exit 0
203             ;;
204          -c)  CLEANUP="cleanup"
205             shift
206             ;;
207       esac
208    done
209
210    shift $((OPTIND-1))
211
212    [ "${1:-}" = "--" ] && shift
213
214    log_success "MAIN: PARSING OF ARGUMENT DONE"
215
216 }
217
218 #start execution / function calls
219 if [[ "$#" -ge 2 ]] ; then
220    log_error " NUMBER OF PARAMETER : $# "
221    show_help
222 fi
223
224 main $@
225
226 prerequisite_netconf
227
228 install_netconf_lib
229
230 #yang installation yet not enabled
231 if [[ "$INSTALL" == "yang" ]] ; then
232 {
233    log " YANG INSTALLATION PROCESSING "
234    install_yang_module
235    log_success " YANG INSTALLATION DONE "
236 }
237 fi
238
239
240 log_success " SCRIPT COMPLETED"
241 exit
242
243 #**********************************************************************
244 #    End of file
245 #**********************************************************************