Fixing syntax in vCPE scripts
[demo.git] / vnfs / vCPE / scripts / v_bng_build.sh
1 #!/bin/bash
2 set -o xtrace  # print commands during script execution
3 set -o errexit # exit on command errors
4
5 VPP_SOURCE_REPO_URL=$(cat /opt/config/vpp_source_repo_url.txt)
6 VPP_SOURCE_REPO_RELEASE_TAG=$(cat /opt/config/vpp_source_repo_release_tag.txt)
7 VPP_PATCH_URL=$(cat /opt/config/vpp_patch_url.txt)
8 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
9 ERROR_MESSAGE='Execution of vBRG script failed.'
10
11 # Convert Network CIDR to Netmask
12 cdr2mask () {
13         # Number of args to shift, 255..255, first non-255 byte, zeroes
14         set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
15         [ $1 -gt 1 ] && shift $1 || shift
16         echo ${1-0}.${2-0}.${3-0}.${4-0}
17 }
18
19
20 # Enable IPV4 forwarding through kernel
21     sed -i 's/^.*\(net.ipv4.ip_forward\).*/\1=1/g' /etc/sysctl.conf
22     sysctl -p /etc/sysctl.conf
23
24 # Download required dependencies
25     echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
26     echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
27     apt-get update
28     apt-get install --allow-unauthenticated -y wget openjdk-8-jdk apt-transport-https ca-certificates g++ libcurl4-gnutls-dev
29     sleep 1
30
31 # Install the tools required for download codes
32     apt-get install -y expect git patch make autoconf libtool linux-image-extra-`uname -r`
33
34 # Download and build the VPP codes
35     cd /opt
36     git clone ${VPP_SOURCE_REPO_URL} -b ${VPP_SOURCE_REPO_RELEASE_TAG} vpp
37     wget -O Vpp-Integrate-FreeRADIUS-Client-for-vBNG.patch ${VPP_PATCH_URL}
38     cd vpp
39     # The patch will place a "dummy" version of dhcp.api.h so the build will succeed
40     mkdir -p build-root/build-vpp-native/vpp/vnet/dhcp/
41     patch -p1 < ../Vpp-Integrate-FreeRADIUS-Client-for-vBNG.patch
42     UNATTENDED='y' make install-dep
43
44 # Check VPP build status
45     if [[ $? -ne 0 ]]
46     then
47         echo $ERROR_MESSAGE 'Reason: VPP build failed' > /opt/script_status.txt
48         exit
49     fi
50
51 # Install the FreeRADIUS client since we need the lib
52     cd /opt
53     git clone https://github.com/FreeRADIUS/freeradius-client.git
54     cd freeradius-client
55     ./configure
56     make && make install
57     cd /usr/local/lib && ln -s -f libfreeradius-client.so.2.0.0 libfreeradiusclient.so
58     ldconfig
59
60     cd /opt/vpp/build-root
61     ./bootstrap.sh
62     make V=0 PLATFORM=vpp TAG=vpp install-deb
63
64 # Check vpp/build-root status
65     if [[ $? -ne 0 ]]
66     then
67         echo $ERROR_MESSAGE 'Reason: vpp/build-root build failed' > /opt/script_status.txt
68         exit
69     fi
70
71 # Install additional dependencies for vpp
72     apt-get install -y python-cffi python-ply python-pycparser
73
74 # Install the VPP package
75     cd /opt/vpp/build-root
76     dpkg -i *.deb
77
78 # Check VPP package installation status
79     if [[ $? -ne 0 ]]
80     then
81         echo $ERROR_MESSAGE 'Reason: VPP package installation failed' > /opt/script_status.txt
82         exit
83     fi
84
85     systemctl stop vpp
86
87 # Disable automatic upgrades
88     if [[ $CLOUD_ENV != "rackspace" ]]
89     then
90         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
91         sed -i 's/\(APT::Periodic::Unattended-Upgrade\) "1"/\1 "0"/' /etc/apt/apt.conf.d/20auto-upgrades
92     fi
93
94 # Indicate script has finished executing
95     echo 'Execution of vBNG build script completed' > /opt/script_status.txt