Cleanup ONAP installation via Heat
[demo.git] / boot / aaf_install.sh
1 #!/bin/bash
2
3 # Read configuration files
4 ARTIFACTS_VERSION=$(cat /opt/config/artifacts_version.txt)
5 DNS_IP_ADDR=$(cat /opt/config/dns_ip_addr.txt)
6 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
7 GERRIT_BRANCH=$(cat /opt/config/gerrit_branch.txt)
8 MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
9 CODE_REPO=$(cat /opt/config/remote_repo.txt)
10 HTTP_PROXY=$(cat /opt/config/http_proxy.txt)
11 HTTPS_PROXY=$(cat /opt/config/https_proxy.txt)
12
13 if [ $HTTP_PROXY != "no_proxy" ]
14 then
15     export http_proxy=$HTTP_PROXY
16     export https_proxy=$HTTPS_PROXY
17 fi
18
19
20 # Add host name to /etc/host to avoid warnings in openstack images
21 if [[ $CLOUD_ENV != "rackspace" ]]
22 then
23         echo 127.0.0.1 $(hostname) >> /etc/hosts
24
25         # Allow remote login as root
26         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
27         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
28 fi
29
30 # Download dependencies
31 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
32 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
33 apt-get update
34 apt-get install --allow-unauthenticated -y apt-transport-https ca-certificates wget openjdk-8-jdk git ntp ntpdate make maven
35
36 # Download scripts from Nexus
37 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip aaf_vm_init.sh > /opt/aaf_vm_init.sh
38 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip serv.sh > /opt/aaf_serv.sh
39 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip imagetest.sh > /opt/imagetest.sh
40 chmod +x /opt/imagetest.sh
41 chmod +x /opt/aaf_vm_init.sh
42 chmod +x /opt/aaf_serv.sh
43 sed -i "s|cmd=\"\"|cmd=\"./aaf_vm_init.sh\"|g" /opt/aaf_serv.sh
44 mv /opt/aaf_serv.sh /etc/init.d
45 update-rc.d aaf_serv.sh defaults
46
47 # Download and install docker-engine and docker-compose
48 echo "deb https://apt.dockerproject.org/repo ubuntu-$(lsb_release -cs) main" | tee /etc/apt/sources.list.d/docker.list
49 apt-get update
50 apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
51 apt-get install -y --allow-unauthenticated docker-engine
52
53 mkdir /opt/docker
54 curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose
55 chmod +x /opt/docker/docker-compose
56
57 # Set the MTU size of docker containers to the minimum MTU size supported by vNICs. OpenStack deployments may need to know the external DNS IP
58 DNS_FLAG=""
59 if [ -s /opt/config/dns_ip_addr.txt ]
60 then
61         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/dns_ip_addr.txt) "
62 fi
63 if [ -s /opt/config/external_dns.txt ]
64 then
65         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/external_dns.txt) "
66 fi
67 echo "DOCKER_OPTS=\"$DNS_FLAG--mtu=$MTU\"" >> /etc/default/docker
68
69 cp /lib/systemd/system/docker.service /etc/systemd/system
70 sed -i "/ExecStart/s/$/ --mtu=$MTU/g" /etc/systemd/system/docker.service
71 if [ $HTTP_PROXY != "no_proxy" ]
72 then
73 cd /opt
74 ./imagetest.sh
75 fi
76 service docker restart
77
78 # DNS IP address configuration
79 echo "nameserver "$DNS_IP_ADDR >> /etc/resolvconf/resolv.conf.d/head
80 resolvconf -u
81
82 # Clone Gerrit repository and run docker containers
83 cd /opt
84 git clone -b $GERRIT_BRANCH --single-branch $CODE_REPO
85 chmod +x /opt/authz/auth/auth-cass/docker/dinstall.sh
86 chmod +x /opt/authz/auth/auth-cass/docker/backup/backup.sh
87 chmod +x /opt/authz/auth/docker/dbuild.sh
88 chmod +x /opt/authz/auth/docker/drun.sh
89 chmod +x /opt/authz/auth/docker/dstart.sh
90 chmod +x /opt/authz/auth/docker/dstop.sh
91
92 #Update maven settings
93 cat > /usr/share/maven/conf/settings.xml << EOF
94 <?xml version="1.0" encoding="UTF-8"?>
95
96 <!--
97 Licensed to the Apache Software Foundation (ASF) under one
98 or more contributor license agreements.  See the NOTICE file
99 distributed with this work for additional information
100 regarding copyright ownership.  The ASF licenses this file
101 to you under the Apache License, Version 2.0 (the
102 "License"); you may not use this file except in compliance
103 with the License.  You may obtain a copy of the License at
104
105     http://www.apache.org/licenses/LICENSE-2.0
106
107 Unless required by applicable law or agreed to in writing,
108 software distributed under the License is distributed on an
109 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
110 KIND, either express or implied.  See the License for the
111 specific language governing permissions and limitations
112 under the License.
113 -->
114
115 <!--
116  | This is the configuration file for Maven. It can be specified at two levels:
117  |
118  |  1. User Level. This settings.xml file provides configuration for a single user,
119 |                 and is normally provided in \${user.home}/.m2/settings.xml.
120  |
121  |                 NOTE: This location can be overridden with the CLI option:
122  |
123  |                 -s /path/to/user/settings.xml
124  |
125  |  2. Global Level. This settings.xml file provides configuration for all Maven
126  |                 users on a machine (assuming they're all using the same Maven
127  |                 installation). It's normally provided in
128 |                 \${maven.home}/conf/settings.xml.
129  |
130  |                 NOTE: This location can be overridden with the CLI option:
131  |
132  |                 -gs /path/to/global/settings.xml
133  |
134  | The sections in this sample file are intended to give you a running start at
135  | getting the most out of your Maven installation. Where appropriate, the default
136  | values (values used when the setting is not specified) are provided.
137  |
138  |-->
139 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
140           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
141           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
142   <!-- localRepository
143    | The path to the local repository maven will use to store artifacts.
144    |
145 | Default: \${user.home}/.m2/repository
146   <localRepository>/path/to/local/repo</localRepository>
147   -->
148
149   <!-- interactiveMode
150    | This will determine whether maven prompts you when it needs input. If set to false,
151    | maven will use a sensible default value, perhaps based on some other setting, for
152    | the parameter in question.
153    |
154    | Default: true
155   <interactiveMode>true</interactiveMode>
156   -->
157
158   <!-- offline
159    | Determines whether maven should attempt to connect to the network when executing a build.
160    | This will have an effect on artifact downloads, artifact deployment, and others.
161    |
162    | Default: false
163   <offline>false</offline>
164   -->
165
166   <!-- pluginGroups
167    | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
168    | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
169    | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
170    |-->
171   <pluginGroups>
172     <!-- pluginGroup
173      | Specifies a further group identifier to use for plugin lookup.
174     <pluginGroup>com.your.plugins</pluginGroup>
175     -->
176   </pluginGroups>
177
178   <!-- proxies
179    | This is a list of proxies which can be used on this machine to connect to the network.
180    | Unless otherwise specified (by system property or command-line switch), the first proxy
181    | specification in this list marked as active will be used.
182    |-->
183   <proxies>
184     <proxy>
185       <id>optional</id>
186       <active>true</active>
187       <protocol>http</protocol>
188       <username>proxyuser</username>
189       <password>proxypass</password>
190       <host>$(cat /opt/config/http_proxy.txt | cut -d ':' -f1)</host>
191       <port>$(cat /opt/config/http_proxy.txt | cut -d ':' -f2)</port>
192       <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
193     </proxy>
194     <proxy>
195       <id>optional</id>
196       <active>true</active>
197       <protocol>https</protocol>
198       <username>proxyuser</username>
199       <password>proxypass</password>
200       <host>$(cat /opt/config/https_proxy.txt | cut -d ':' -f1)</host>
201       <port>$(cat /opt/config/https_proxy.txt | cut -d ':' -f2)</port>
202       <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
203     </proxy>
204   </proxies>
205
206
207   <!-- servers
208    | This is a list of authentication profiles, keyed by the server-id used within the system.
209    | Authentication profiles can be used whenever maven must make a connection to a remote server.
210    |-->
211   <servers>
212     <!-- server
213      | Specifies the authentication information to use when connecting to a particular server, identified by
214      | a unique name within the system (referred to by the 'id' attribute below).
215      |
216      | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
217      |       used together.
218      |
219     <server>
220       <id>deploymentRepo</id>
221       <username>repouser</username>
222       <password>repopwd</password>
223     </server>
224     -->
225
226     <!-- Another sample, using keys to authenticate.
227     <server>
228       <id>siteServer</id>
229       <privateKey>/path/to/private/key</privateKey>
230       <passphrase>optional; leave empty if not used.</passphrase>
231     </server>
232     -->
233   </servers>
234
235   <!-- mirrors
236    | This is a list of mirrors to be used in downloading artifacts from remote repositories.
237    |
238    | It works like this: a POM may declare a repository to use in resolving certain artifacts.
239    | However, this repository may have problems with heavy traffic at times, so people have mirrored
240    | it to several places.
241    |
242    | That repository definition will have a unique id, so we can create a mirror reference for that
243    | repository, to be used as an alternate download site. The mirror site will be the preferred
244    | server for that repository.
245    |-->
246
247   <!-- profiles
248    | This is a list of profiles which can be activated in a variety of ways, and which can modify
249    | the build process. Profiles provided in the settings.xml are intended to provide local machine-
250    | specific paths and repository locations which allow the build to work in the local environment.
251    |
252    | For example, if you have an integration testing plugin - like cactus - that needs to know where
253    | your Tomcat instance is installed, you can provide a variable here such that the variable is
254    | dereferenced during the build process to configure the cactus plugin.
255    |
256    | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
257    | section of this document (settings.xml) - will be discussed later. Another way essentially
258    | relies on the detection of a system property, either matching a particular value for the property,
259    | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
260    | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
261    | Finally, the list of active profiles can be specified directly from the command line.
262    |
263    | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
264    |       repositories, plugin repositories, and free-form properties to be used as configuration
265    |       variables for plugins in the POM.
266    |
267    |-->
268
269
270
271   
272   
273   <profiles>
274       <profile>
275           
276           <id>10_nexus</id>
277           <!--Enable snapshots for the built in central repo to direct -->
278           <!--all requests to nexus via the mirror -->
279           <repositories>
280               <repository>
281                   <id>10_nexus</id>
282                   <url>http://repo.maven.apache.org/maven2/</url>
283                   <releases><enabled>true</enabled></releases>
284                   <snapshots><enabled>true</enabled></snapshots>
285               </repository>
286           </repositories>
287           
288           <pluginRepositories>
289               <pluginRepository>
290                   <id>10_nexus</id>
291                   <url>http://repo.maven.apache.org/maven2/</url>
292                   <releases><enabled>true</enabled></releases>
293                   <snapshots><enabled>true</enabled></snapshots>
294               </pluginRepository>
295           </pluginRepositories>
296           
297       </profile>
298       <profile>
299           <id>20_openecomp-public</id>
300           <repositories>
301               <repository>
302                   <id>20_openecomp-public</id>
303                   <name>20_openecomp-public</name>
304                   <url>https://nexus.onap.org/content/repositories/public/</url>
305                   <releases>
306                       <enabled>true</enabled>
307                       <updatePolicy>daily</updatePolicy>
308                   </releases>
309                   <snapshots>
310                       <enabled>false</enabled>
311                   </snapshots>
312               </repository>
313           </repositories>
314           <pluginRepositories>
315               <pluginRepository>
316                   <id>20_openecomp-public</id>
317                   <name>20_openecomp-public</name>
318                   <url>https://nexus.onap.org/content/repositories/public/</url>
319                   <releases>
320                       <enabled>true</enabled>
321                       <updatePolicy>daily</updatePolicy>
322                   </releases>
323                   <snapshots>
324                       <enabled>false</enabled>
325                   </snapshots>
326               </pluginRepository>
327           </pluginRepositories>
328       </profile>
329       <profile>
330           <id>30_openecomp-staging</id>
331           <repositories>
332               <repository>
333                   <id>30_openecomp-staging</id>
334                   <name>30_openecomp-staging</name>
335                   <url>https://nexus.onap.org/content/repositories/staging/</url>
336                   <releases>
337                       <enabled>true</enabled>
338                       <updatePolicy>daily</updatePolicy>
339                   </releases>
340                   <snapshots>
341                       <enabled>false</enabled>
342                   </snapshots>
343               </repository>
344           </repositories>
345           <pluginRepositories>
346               <pluginRepository>
347                   <id>30_openecomp-staging</id>
348                   <name>30_openecomp-staging</name>
349                   <url>https://nexus.onap.org/content/repositories/staging/</url>
350                   <releases>
351                       <enabled>true</enabled>
352                       <updatePolicy>daily</updatePolicy>
353                   </releases>
354                   <snapshots>
355                       <enabled>false</enabled>
356                   </snapshots>
357               </pluginRepository>
358           </pluginRepositories>
359       </profile>
360       <profile>
361           <id>40_openecomp-release</id>
362           <repositories>
363               <repository>
364                   <id>40_openecomp-release</id>
365                   <name>40_openecomp-release</name>
366                   <url>https://nexus.onap.org/content/repositories/releases/</url>
367                   <releases>
368                       <enabled>true</enabled>
369                       <updatePolicy>daily</updatePolicy>
370                   </releases>
371                   <snapshots>
372                       <enabled>false</enabled>
373                   </snapshots>
374               </repository>
375           </repositories>
376           <pluginRepositories>
377               <pluginRepository>
378                   <id>40_openecomp-release</id>
379                   <name>40_openecomp-release</name>
380                   <url>https://nexus.onap.org/content/repositories/releases/</url>
381                   <releases>
382                       <enabled>true</enabled>
383                       <updatePolicy>daily</updatePolicy>
384                   </releases>
385                   <snapshots>
386                       <enabled>false</enabled>
387                   </snapshots>
388               </pluginRepository>
389           </pluginRepositories>
390       </profile>
391       
392       <profile>
393           <id>50_openecomp-snapshots</id>
394           <repositories>
395               <repository>
396                   <id>50_openecomp-snapshot</id>
397                   <name>50_openecomp-snapshot</name>
398                   <url>https://nexus.onap.org/content/repositories/snapshots/</url>
399                   <releases>
400                       <enabled>false</enabled>
401                   </releases>
402                   <snapshots>
403                       <enabled>true</enabled>
404                   </snapshots>
405               </repository>
406           </repositories>
407           <pluginRepositories>
408               <pluginRepository>
409                   <id>50_openecomp-snapshot</id>
410                   <name>50_openecomp-snapshot</name>
411                   <url>https://nexus.onap.org/content/repositories/snapshots/</url>
412                   <releases>
413                       <enabled>false</enabled>
414                   </releases>
415                   <snapshots>
416                       <enabled>true</enabled>
417                   </snapshots>
418               </pluginRepository>
419           </pluginRepositories>
420       </profile>
421       <profile>
422           <id>60_opendaylight-release</id>
423           <repositories>
424               <repository>
425                   <id>60_opendaylight-mirror</id>
426                   <name>60_opendaylight-mirror</name>
427                   <url>https://nexus.opendaylight.org/content/repositories/public/</url>
428                   <releases>
429                       <enabled>true</enabled>
430                       <updatePolicy>daily</updatePolicy>
431                   </releases>
432                   <snapshots>
433                       <enabled>false</enabled>
434                   </snapshots>
435               </repository>
436           </repositories>
437           <pluginRepositories>
438               <pluginRepository>
439                   <id>60_opendaylight-mirror</id>
440                   <name>60_opendaylight-mirror</name>
441                   <url>https://nexus.opendaylight.org/content/repositories/public/</url>
442                   <releases>
443                       <enabled>true</enabled>
444                       <updatePolicy>daily</updatePolicy>
445                   </releases>
446                   <snapshots>
447                       <enabled>false</enabled>
448                   </snapshots>
449               </pluginRepository>
450           </pluginRepositories>
451       </profile>
452       
453       <profile>
454           <id>70_opendaylight-snapshots</id>
455           <repositories>
456               <repository>
457                   <id>70_opendaylight-snapshot</id>
458                   <name>70_opendaylight-snapshot</name>
459                   <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
460                   <releases>
461                       <enabled>false</enabled>
462                   </releases>
463                   <snapshots>
464                       <enabled>true</enabled>
465                   </snapshots>
466               </repository>
467           </repositories>
468           <pluginRepositories>
469               <pluginRepository>
470                   <id>70_opendaylight-snapshot</id>
471                   <name>70_opendaylight-snapshot</name>
472                   <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
473                   <releases>
474                       <enabled>false</enabled>
475                   </releases>
476                   <snapshots>
477                       <enabled>true</enabled>
478                   </snapshots>
479               </pluginRepository>
480           </pluginRepositories>
481       </profile>
482   </profiles>
483   
484   <activeProfiles>
485       <activeProfile>10_nexus</activeProfile>
486       <activeProfile>20_openecomp-public</activeProfile>
487       <activeProfile>30_openecomp-staging</activeProfile>
488       <activeProfile>40_openecomp-release</activeProfile>
489       <activeProfile>50_openecomp-snapshots</activeProfile>
490       <activeProfile>60_opendaylight-release</activeProfile>
491       <activeProfile>70_opendaylight-snapshots</activeProfile>
492
493   </activeProfiles>
494   
495 </settings>
496 EOF
497
498 cd /opt/authz
499 mvn install -Dmaven.test.skip=true
500
501 cd /opt
502 ./aaf_vm_init.sh