Fixing syntax in vCPE scripts
[demo.git] / vnfs / vCPE / scripts / v_brgemu_build.sh
1 #!/bin/bash
2
3 VPP_SOURCE_REPO_URL=$(cat /opt/config/vpp_source_repo_url.txt)
4 VPP_SOURCE_REPO_RELEASE_TAG=$(cat /opt/config/vpp_source_repo_release_tag.txt)
5 VPP_PATCH_URL=$(cat /opt/config/vpp_patch_url.txt)
6 HC2VPP_SOURCE_REPO_URL=$(cat /opt/config/hc2vpp_source_repo_url.txt)
7 HC2VPP_SOURCE_REPO_RELEASE_TAG=$(cat /opt/config/hc2vpp_source_repo_release_tag.txt)
8 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
9 ERROR_MESSAGE='Execution of vBRG build 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 # Download required dependencies
20     echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
21     echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
22     apt-get update
23     apt-get install --allow-unauthenticated -y wget openjdk-8-jdk apt-transport-https ca-certificates g++ libcurl4-gnutls-dev
24     sleep 1
25
26 # Install the tools required for download codes
27     apt-get install -y expect git patch make linux-image-extra-`uname -r`
28 # Download and build the VPP codes
29     cd /opt
30     git clone ${VPP_SOURCE_REPO_URL} -b ${VPP_SOURCE_REPO_RELEASE_TAG} vpp
31     wget -O VPP-Add-Option82-Nat-Filter-For-vBRG.patch ${VPP_PATCH_URL}
32
33     cd vpp
34     patch -p1 < ../VPP-Add-Option82-Nat-Filter-For-vBRG.patch
35     yes y | make install-dep
36
37 # Check vpp build status
38     if [[ $? -ne 0 ]]
39     then
40         echo $ERROR_MESSAGE 'Reason: VPP build failed' > /opt/script_status.txt
41         exit
42     fi
43
44     cd build-root
45     ./bootstrap.sh
46     make V=0 PLATFORM=vpp TAG=vpp install-deb
47
48 # Check vpp/build-root build status
49     if [[ $? -ne 0 ]]
50     then
51         echo $ERROR_MESSAGE 'Reason: vpp/build-root build failed' > /opt/script_status.txt
52         exit
53     fi
54
55 # Install the VPP package
56     dpkg -i *.deb
57
58 # Check vpp package installation status
59     if [[ $? -ne 0 ]]
60     then
61         echo $ERROR_MESSAGE 'Reason: VPP package installation failed' > /opt/script_status.txt
62         exit
63     fi
64
65     systemctl stop vpp
66
67 # Download and install HC2VPP from source
68     cd /opt
69     git clone ${HC2VPP_SOURCE_REPO_URL} -b ${HC2VPP_SOURCE_REPO_RELEASE_TAG} hc2vpp
70
71     apt-get -f -y install
72     apt-get install -y maven
73     mkdir -p /root/.m2
74     cat > ~/.m2/settings.xml << EOF
75 <?xml version="1.0" encoding="UTF-8"?>
76 <!-- vi: set et smarttab sw=2 tabstop=2: -->
77 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
78   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
79   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
80
81   <profiles>
82     <profile>
83    <id>fd.io-release</id>
84       <repositories>
85         <repository>
86           <id>fd.io-mirror</id>
87           <name>fd.io-mirror</name>
88           <url>https://nexus.fd.io/content/groups/public/</url>
89           <releases>
90             <enabled>true</enabled>
91             <updatePolicy>never</updatePolicy>
92           </releases>
93           <snapshots>
94             <enabled>false</enabled>
95           </snapshots>
96         </repository>
97       </repositories>
98       <pluginRepositories>
99         <pluginRepository>
100           <id>fd.io-mirror</id>
101           <name>fd.io-mirror</name>
102           <url>https://nexus.fd.io/content/repositories/public/</url>
103           <releases>
104             <enabled>true</enabled>
105             <updatePolicy>never</updatePolicy>
106           </releases>
107           <snapshots>
108             <enabled>false</enabled>
109           </snapshots>
110         </pluginRepository>
111       </pluginRepositories>
112     </profile>
113
114     <profile>
115       <id>fd.io-snapshots</id>
116       <repositories>
117         <repository>
118           <id>fd.io-snapshot</id>
119           <name>fd.io-snapshot</name>
120           <url>https://nexus.fd.io/content/repositories/fd.io.snapshot/</url>
121           <releases>
122             <enabled>false</enabled>
123           </releases>
124           <snapshots>
125             <enabled>true</enabled>
126           </snapshots>
127         </repository>
128       </repositories>
129       <pluginRepositories>
130         <pluginRepository>
131             <id>fd.io-snapshot</id>
132           <name>fd.io-snapshot</name>
133           <url>https://nexus.fd.io/content/repositories/fd.io.snapshot/</url>
134           <releases>
135             <enabled>false</enabled>
136           </releases>
137           <snapshots>
138             <enabled>true</enabled>
139           </snapshots>
140         </pluginRepository>
141       </pluginRepositories>
142     </profile>
143     <profile>
144       <id>opendaylight-snapshots</id>
145       <repositories>
146         <repository>
147           <id>opendaylight-snapshot</id>
148           <name>opendaylight-snapshot</name>
149           <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
150           <releases>
151             <enabled>false</enabled>
152           </releases>
153           <snapshots>
154             <enabled>true</enabled>
155           </snapshots>
156         </repository>
157       </repositories>
158       <pluginRepositories>
159         <pluginRepository>
160           <id>opendaylight-shapshot</id>
161           <name>opendaylight-snapshot</name>
162           <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
163           <releases>
164             <enabled>false</enabled>
165           </releases>
166           <snapshots>
167             <enabled>true</enabled>
168           </snapshots>
169         </pluginRepository>
170       </pluginRepositories>
171     </profile>
172   </profiles>
173
174   <activeProfiles>
175     <activeProfile>fd.io-release</activeProfile>
176     <activeProfile>fd.io-snapshots</activeProfile>
177     <activeProfile>opendaylight-snapshots</activeProfile>
178   </activeProfiles>
179 </settings>
180 EOF
181
182     cd hc2vpp
183     mvn clean install
184
185 # Check hc2vpp build status
186     if [[ $? -ne 0 ]]
187     then
188         echo $ERROR_MESSAGE 'Reason: hc2vpp build failed' > /opt/script_status.txt
189         exit
190     fi
191
192     l_version=$(cat pom.xml | grep "<version>" | head -1)
193     l_version=$(echo "${l_version%<*}")
194     l_version=$(echo "${l_version#*>}")
195     mv vpp-integration/minimal-distribution/target/vpp-integration-distribution-${l_version}-hc/vpp-integration-distribution-${l_version} /opt/honeycomb
196     sed -i 's/127.0.0.1/0.0.0.0/g' /opt/honeycomb/config/honeycomb.json
197
198 # Disable automatic upgrades
199     if [[ $CLOUD_ENV != "rackspace" ]]
200     then
201         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
202         sed -i 's/\(APT::Periodic::Unattended-Upgrade\) "1"/\1 "0"/' /etc/apt/apt.conf.d/20auto-upgrades
203     fi
204
205 # Indicate script has finished executing
206     echo 'Execution of vBRG build script completed' > /opt/script_status.txt