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